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

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

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

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

If I can just chime in here....

Might just want to add a space after Location:

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]"

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.