•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 426,018 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,709 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 630 | Replies: 11
![]() |
•
•
Join Date: Feb 2007
Posts: 56
Reputation:
Rep Power: 2
Solved Threads: 0
Hello, I want to be able to echo a redirect url, based on a few variables. The content type of this php script is set as Header("content-type: application/x-javascript"); here is my code:
Right now the url just outputs the url as text, but it doesn't go there. I am calling this script from a form, it is called when the user posts the submit button.
$row = mysql_fetch_row($result); echo "window.location = \"http://myurl.com/test/".$row[0]."/index.php?name=".$row[0]."\";";
Right now the url just outputs the url as text, but it doesn't go there. I am calling this script from a form, it is called when the user posts the submit button.
Last edited by adaykin : Jul 16th, 2008 at 4:50 pm.
My Website <-- check out my site!
•
•
Join Date: Feb 2007
Posts: 56
Reputation:
Rep Power: 2
Solved Threads: 0
Yeah I have to first get the url from database, which is based on the current page.
My Website <-- check out my site!
Try echoing a meta refresh:
php Syntax (Toggle Plain Text)
$row = mysql_fetch_row($result); echo'<meta http-equiv="refresh" content="0;url=http://myurl.com/test/'.$row[0].'/index.php?name='.$row[0].'">';
Lost time is never found again.
- Benjamin Franklin
- Benjamin Franklin
OR
php Syntax (Toggle Plain Text)
$row = mysql_fetch_row($result); echo'<script type="text/javascript">'; echo "window.location = 'http://myurl.com/test/".$row[0]."/index.php?name=".$row[0]."/';"; echo'</script>';
Lost time is never found again.
- Benjamin Franklin
- Benjamin Franklin
•
•
Join Date: Feb 2008
Location: Gurgaon India
Posts: 181
Reputation:
Rep Power: 1
Solved Threads: 14
hi,
warning : if u use this:
use this in head tag
bye
1.
$row = mysql_fetch_row($result);
2.
echo'<meta http-equiv="refresh" content="0;url=http://myurl.com/test/'.$row[0].'/index.php?name='.$row[0].'">';warning : if u use this:
use this in head tag
bye
•
•
Join Date: Feb 2007
Posts: 56
Reputation:
Rep Power: 2
Solved Threads: 0
•
•
•
•
Hi,
Buddy is right,
You should always remember to
enclose your javascript code inside <script language=javascript></script>
block, in order to let browser know that this is a javascript code ant a sentence.
No that's incorrect. If you look at the original post, my header is:
Header("content-type: application/x-javascript");
I figured out what I was doing wrong though, my database wasn't being altered correctly when I did my update functions I got it working now though, thanks guys!
My Website <-- check out my site!
•
•
•
•
No that's incorrect. If you look at the original post, my header is:
Header("content-type: application/x-javascript");
I figured out what I was doing wrong though, my database wasn't being altered correctly when I did my update functions I got it working now though, thanks guys!
JavaScript isn't executed if you just download the file. That is, if you add the Mime-Type that tells the browser is javascript, and send it the content, it will not execute it.
It is only executed inside HTML, that is, when the browser finds an embedded script in HTML, it will assume it must be executed.
So you need a HTML file, with embedded <script> tag.

You can also just use the PHP header() function as mentioned.
$row = mysql_fetch_row($result);
header("http://myurl.com/test/".$row[0]."/index.php?name=".$row[0]."/"; www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
•
•
Join Date: Feb 2007
Posts: 56
Reputation:
Rep Power: 2
Solved Threads: 0
Javascript will execute the code. Just try putting an alert, where the header type is
Header("content-type: application/x-javascript"); you will see :-)
Like I said before a header WOULD NOT WORK since I have to pull information from a database first. You MUST put a header at the top of the page.
Header("content-type: application/x-javascript"); you will see :-)
Like I said before a header WOULD NOT WORK since I have to pull information from a database first. You MUST put a header at the top of the page.
My Website <-- check out my site!
![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Previous Thread: inbox
- Next Thread: link protector help


Linear Mode