creating a dynamic link from a specific url

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
soianyc
Forum Commoner
Posts: 61
Joined: Wed Mar 30, 2005 2:48 pm
Location: NY

creating a dynamic link from a specific url

Post 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
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

you can use HTTP_REFERER although it's not 100% reliable.

what you could also do is use the javascript history function.
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Post 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.
Last edited by dethron on Fri Jun 24, 2005 1:14 pm, edited 1 time in total.
User avatar
soianyc
Forum Commoner
Posts: 61
Joined: Wed Mar 30, 2005 2:48 pm
Location: NY

Post 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??
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post 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...
User avatar
soianyc
Forum Commoner
Posts: 61
Joined: Wed Mar 30, 2005 2:48 pm
Location: NY

Post 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.
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Post 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 ;)
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post 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.
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Post 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>";
?>
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post 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.
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Post 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 ;)
Post Reply