php - Redirect to the last page requested after login -
i need regarding login system. in project when user logs in go account. if browsing pages , asked login should redirect page after login , not profile page.
here code trying user redirected student_account.php , not requested page.
$fetch = mysql_fetch_assoc($exec); $_session['login'] = $fetch[uniq]; $_session['emailid'] = $fetch['email']; $emailid = $_session['emailid']; $_session['type'] = 'student'; if(isset($_session['url'])) $url = $_session['url']; // holds url last page visited. else $url = "student_account.php"; // default page header("location:$url");
i think should try http_referer here redirect on last visited page. set hidden field in login form.
html :-
<input type="hidden" name="redirurl" value="<? echo $_server['http_referer']; ?>" />
and redirurl
value in form post.
php :-
if(isset($_request['redirurl'])) $url = $_request['redirurl']; // holds url last page visited. else $url = "student_account.php"; // default page header("location:$url");
or if using session please ensure start session session_start() on page. otherwise session break , couldn't save desired url.
Comments
Post a Comment