Page 1 of 1

creating a dynamic link from a specific url

Posted: Fri Jun 24, 2005 1:04 pm
by soianyc
Im not quite sure how to word this question but here goes. Im making a catalog and what i want to do is make a link that goes back to a certain page. I want to grab the url from the previous page and put it up as link on another page.

Is there an $HTTP_GET variable for something like this?? Ive googled this as well as tried forums but i feel i may be asking my question incorrectly.

Again what im looking to do is grab a url and place it as a hyperlink.

Any thoughts are greatly appreciated

Regards
-soia

Posted: Fri Jun 24, 2005 1:10 pm
by Burrito
you can use HTTP_REFERER although it's not 100% reliable.

what you could also do is use the javascript history function.

Posted: Fri Jun 24, 2005 1:12 pm
by dethron
FIRST
i am sure we can help you, just state your question well.

SECOND (if i get it right)
add a referrer data (the address of the current page) to all links in current page. so that when user selects a link and open another page, that page knows exactly who is the referrer.

Posted: Fri Jun 24, 2005 1:12 pm
by soianyc
Ive stayed javascript free for the site. Id rather not add any now unless its the only reliable way to do it. Besides HTTP_REFERER is there another way to grab a url??

Posted: Fri Jun 24, 2005 1:13 pm
by Burrito
you could store the previous page in a $_SESSION var and then output that on subsequent pages, then reset it for every page hit...

Posted: Fri Jun 24, 2005 1:16 pm
by soianyc
sessions huh. Well i was about to implement sessions on the page, if it will help me do this i think ill give it a go. Have any good tutorial recomandations for sessions.

Posted: Fri Jun 24, 2005 1:16 pm
by dethron
dont use session like that, because session uses your server's memory. if the number of the users who use your page increase, your server will have a problem ;)

Posted: Fri Jun 24, 2005 1:19 pm
by Burrito
dethron wrote:dont use session like that, because session uses your server's memory. if the number of the users who use your page increase, your server will have a problem ;)
not likey going to be a problem as it's only one variable in the $_SESSIONs array...would take a helluva lotta people to notice any problems.

take a look at sessions there then post questions if you have them.

Posted: Fri Jun 24, 2005 1:20 pm
by dethron

Code: Select all

//================ head.php================

<?php
    echo "this is a page named as head.php";
    echo "<a href=\"toss.php?referrer=head.php\">second page</a>";

?>


//================ toss.php ================

<?php
   echo "this is toss.php";
   echo "<a href=\"".$_GET['referrer']."\">the referrer</a>";
?>

Posted: Fri Jun 24, 2005 1:27 pm
by Burrito
if you're going to do something like that, you might consider using $_SERVER["PHP_SELF"] so you don't have to hard code every page in the url string.

Posted: Fri Jun 24, 2005 1:28 pm
by dethron
of course we need using such a thing, the heart of using this is posting the variable is better than using session in memory matter. and using session is better in CPU matter ;)