LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 05-26-2006, 01:52 AM   #1
alphaque
LQ Newbie
 
Registered: Nov 2004
Posts: 9

Rep: Reputation: 0
How to supply extra commands along with PHP header("Location: http://www.abc.com")?


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..
 
Old 05-26-2006, 04:06 AM   #2
zeitounator
Member
 
Registered: Aug 2003
Location: Montpellier, France, Europe, World, Solar System
Distribution: Debian Sarge, Fedora core 5 (i386 and x86_64)
Posts: 262

Rep: Reputation: 30
2 quick n' dirty solutions.

Solution 1: pass a parameter in the url.
Code:
#Index.php on xyz.com
<?php
$a = $_REQUEST["p"];
switch ($a) {
case '123': header( "Location: http://www.abc.com?fromsite=www.xyz.com"); exit; break;
}
?>

#Index.php on abc.com
<?php
#some blabla for the head
$onload = '';
if (!empty($_GET['fromsite'])) {
    $onload = " onload=\"document.write('You are coming from " . $_GET['fromsite'] . "')\"";
}
echo '<body' . $onload . '>';
# remaining code for the page....
?>
Solution 2: use the http referer (I let you figure out how to retreive the hostname only from that string if your really need to).
Code:
#index.php on abc.com
<?php
#some blabla for the head
$onload = '';
if (!empty($_SERVER['HTTP_REFERER'])) {
   $onload = " onload=\"document.write('You were redirected from " . $_SERVER['HTTP_REFERER'] . "')\"";
}
echo '<body' . $onload . '>';
# remaining code for the page....
?>
 
Old 05-26-2006, 04:14 AM   #3
alphaque
LQ Newbie
 
Registered: Nov 2004
Posts: 9

Original Poster
Rep: Reputation: 0
Hi zeitounator
Thanks, your solution works if i own the destination web site, the problem is i don't own the destination web site so i can't modify the code there, anymore help ? :-)

thanks ~~
 
Old 05-26-2006, 04:28 AM   #4
spooon
Senior Member
 
Registered: Aug 2005
Posts: 1,755

Rep: Reputation: 48
Quote:
Originally Posted by alphaque
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>
You can't do that (for obvious security reasons). Why do you need to do this? Why not instead do something like 1) use frames to display a message in one frame and the site in the other, or 2) print the content of the other site with your script?

Last edited by spooon; 05-26-2006 at 04:33 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to write a bash script to replace all "KH" to "K" in file ABC??? cqmyg5 Slackware 4 07-24-2007 09:00 AM
PHP header("Location: xxx.php") not working? baddah Programming 7 05-10-2006 09:00 AM
Location of the directory of "C" header files RoMan65 Linux - Software 8 01-19-2006 04:59 PM
Where is the Embedded Linux "HOWTO" at http://www.tldp.org ? t3gah General 14 06-06-2005 06:35 AM
PHP header("Location") Gerardoj Programming 1 05-11-2004 04:29 PM


All times are GMT -5. The time now is 06:47 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration