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.
Redirect To Previous Page
Moderator: General Moderators
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: Redirect To Previous Page
Do you mean to an index page? Either way, tryin using 'header()'.nitediver wrote:Im going to make page that redirect to the previous page after login, anyone can help me?
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()'.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
- hypedupdawg
- Forum Commoner
- Posts: 74
- Joined: Sat Apr 10, 2010 5:21 am
Re: Redirect To Previous Page
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:
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
<script type="text/javascript">function goBack(){window.history.go(-1);}</script>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
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.
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.