Page 1 of 1
Redirect To Previous Page
Posted: Sat May 01, 2010 11:26 am
by nitediver
Im going to make page that redirect to the previous page after login, anyone can help me?
After doing some search I found about using "$_SERVER['HTTP_REFERER']".
Any advice please, I really appreciate, thanks.
Re: Redirect To Previous Page
Posted: Sat May 01, 2010 11:42 am
by social_experiment
nitediver wrote:Im going to make page that redirect to the previous page after login, anyone can help me?
Do you mean to an index page? Either way, tryin using 'header()'.
Code: Select all
<?php header('location: page.php'); exit(); ?>
There shouldn't be any other headers sent to the browser prior to this or you will receive an error, you could probably check for that with 'headers_sent()'.
Re: Redirect To Previous Page
Posted: Sun May 02, 2010 3:38 am
by hypedupdawg
The easiest way to do this is actually not using php but javascript - all you need to do is insert this section of code in the head:
Code: Select all
<script type="text/javascript">function goBack(){window.history.go(-1);}</script>
The -1 needs to be replaced with the number of steps you want to jump backwards. So if your login is integrated into all pages, leave it as -1 (like on the
Steam Forums). If it is on a separate page, as on this website, insert -2, to go back two steps, and so on and so on.
You can then call this function multiple times, eg. in a javascript block, or as a backup link:
Code: Select all
<a href="javascript :goBack()">Click here to be Redirected</a>
Re: Redirect To Previous Page
Posted: Sun May 02, 2010 8:54 am
by nitediver
Sorry that's not what I mean.
Im building shopping cart website, I want to use redirect for this situation,
After choosing a product user must login first, after login I want to redirect the page to previous product already chosen by user, instead of index or other page.