how to create back/next link

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
adsegzy
Forum Contributor
Posts: 184
Joined: Tue Jul 28, 2009 9:26 am

how to create back/next link

Post by adsegzy »

Hello there,

I want to create back link and next link on my pages so that visitors can go back to the previously visited pages, how do i get the URL of these previous pages, or how do i go about it.

regards
websitesca
Forum Newbie
Posts: 16
Joined: Fri Jul 09, 2010 2:47 pm

Re: how to create back/next link

Post by websitesca »

There are a number of ways to go about this. It really depends on your website design of course.

URL PASSING METHOD:

This is probably the best method. When a user clicks a link to go FORWARD, you could pass some info about where they are coming from in the url. So you would make a link like:

Code: Select all

$link = "<a href='page.php?previous=page57'>Next Page</a>";
COOKIES/SESSION METHOD:

This requires use of the $_SESSION variable. When on any particular page, simply do this:

Code: Select all

$_SESSION["previous_page"] = $_SERVER["REQUEST_URI"];
Now you can use that session variable anywhere.

JAVASCRIPT METHOD:

This doesn't really involve PHP, but it still can work. This works on the client side, so the BROWSER knows where you've been last:

You can put this in a link, or in a form, but basically the code is history.back();

Code: Select all

<FORM> 
<INPUT type="button" value="Click here to go back" onClick="history.back()"> 
</FORM>
I hope that helps you with your website!
Georges,
http://www.websites.ca
Post Reply