Page 1 of 1

how to create back/next link

Posted: Mon Jul 12, 2010 10:50 am
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

Re: how to create back/next link

Posted: Mon Jul 12, 2010 3:29 pm
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