0

Hi,

I have this vision:

Someone clicks on a link that goes to my website. When they get my website, my website picks up the url that they just came from. With my code I have gotten that far. But what I want is for the page's url that they just came from to be in my page's url. Got it?

Ok, so example. They come from this page:

http://example.com/

and when they get to my page, my page's url looks like this:

http://mypage.com/index.php?url=http://example.com/

So here is my code:

<?php
$url = $_SERVER['HTTP_REFERER'];
$_GET["$url"];

?>

But it is not working. So how would I accomplish this?

Thanks

4
Contributors
6
Replies
10
Views
6 Years
Discussion Span
Last Post by twiss
0

http_referer is not a dependable resource, its is not sent by all browsers
$_GET is an array not a command, it is populated from the referring page

before any other code redirects MUST be before any output

<?php if(!isset($_GET['url'])) {
   if(isset($_SERVER['HTTP_REFERER'])) {
     header("Location: $_SERVER['php_self']?url=$_GET['url']");} }

checks that 'url' is not set, checks if the referere is set, then redirects to the appropriate url form $_server['php_self'] can be the filename, eg index.php, I dont know what the filename is, this a a very generic redirect

Edited by almostbob: n/a

0

http_referer is not a dependable resource, its is not sent by all browsers
$_GET is an array not a command, it is populated from the referring page

before any other code redirects MUST be before any output

<?php if(!isset($_GET['url'])) {
   if(isset($_SERVER['HTTP_REFERER'])) {
     header("Location: $_SERVER['php_self']?url=$_GET['url']");} }

checks that 'url' is not set, checks if the referere is set, then redirects to the appropriate url form $_server['php_self'] can be the filename, eg index.php, I dont know what the filename is, this a a very generic redirect

Hey, thanks. It didn't quite work on my server at first, but i made some changes to get it working. Do you think it will change anything?

<?php if(!isset($_GET['ref'])) {
   if(isset($_SERVER['HTTP_REFERER'])) {
   header("Location:".$_SERVER['php_self']."?ref=".$_SERVER['HTTP_REFERER']."");	 
}
}
?>

Thanks

0

the change is cool,
strange though, text and variables inside DQuotes are suppose to parse,
if it continues to work glad to help,
tag the thread solved makes my stats look good :P

Edited by almostbob: n/a

0

If you have strings as keys in an array, don't put quotes around them in a double-quoted string:

"Location: $_SERVER[php_self]?url=$_GET[url]"
0

Also, while the HTTP Referrer is not reliable, it is in fact sent by all browsers (IE5+, Opera4+, etc.)

Also, why do people add ."" on the end so often when concatenating strings? It seems like people think of it as a way you can put variables inside a string.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.