Supply extra command along with PHP header("Location&qu

 
Post new topic   Reply to topic    Aprelium Forum Index -> PHP
View previous topic :: View next topic  
Author Message
alphaque
-


Joined: 26 May 2006
Posts: 1

PostPosted: Fri May 26, 2006 7:54 am    Post subject: Supply extra command along with PHP header("Location&qu Reply with quote

Hi
I have an index.php file that use the PHP header(location) command to redirect to an external web site when user submit the "p" value as "123" in their source URL (i.e : www.xyz.com/index.php?p=123). Below is the example when user supply p=123, it will be redirected to www.abc.com :

//source PHP file - index.php
<?php
$a = $_REQUEST["p"];
switch ($a) {
case '123': header( "Location: http://www.abc.com"); exit; break;
}
?>

My problem is besides redirect the user to the destination URL (http://www.abc.com), i also want to pass along a line of java script to the destination URL which is like below :

<script>document.write('You are coming from www.xyz.com')</script>

The above script need to be executed at the detination web site (www.abc.com)before the HTML code of the www.abc.com is read. This means i want to pass the above script command to the destination URL and it is executed before the destination URL <HTML> tag,basically i want the destination web site source code to look something like below :

<script>document.write('You are coming from www.xyz.co')</script> //this script command is passed from the source PHP file

<html>
<head>abcde </head>
<body>scnsdjcsc</body?
</html>

Can anyone share with me how do i pass that script command in my PHP header (location) command in my source PHP file ?

thanks in advance..
Back to top View user's profile Send private message
AbyssUnderground
-


Joined: 31 Dec 2004
Posts: 3855

PostPosted: Fri May 26, 2006 9:52 am    Post subject: Reply with quote

You cannot pass the javascript but you can pass a PHP variable that will be read by the next page.
_________________
Andy (AbyssUnderground) (previously The Inquisitor)
www.abyssunderground.co.uk
Back to top View user's profile Send private message Visit poster's website
aprelium
-


Joined: 22 Mar 2002
Posts: 6800

PostPosted: Fri May 26, 2006 10:34 am    Post subject: Re: Supply extra command along with PHP header("Locatio Reply with quote

alphaque,

When you send a Location header, the browser will ignore the body of the response and will redirect to the value of the Location header. Under some circumstances, it is even the server itself which optimizes this and does an internal redirection.

So to have the body of the response processed by the browser, you'll have to not use Location and rather send a normal HTML page with a META REFRESH tag in its HEAD section. This way, you force the browser to process the page and the Javascript it may contain and then to redirect to another page.
_________________
Support Team
Aprelium - http://www.aprelium.com
Back to top View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> PHP All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group