I want to set session on clicking of link so after login user will redirect to last visited page.
for example:
Step1 : user opened home page.(seesion url set to home page
$_SESSION['url'] = $_SERVER['REQUEST_URI'])
step2 : Next in new tab user will open contact page (again session variable reset)
step3: user will come to home page and click to login link.(session not set because no reload of page)
step4: after login user will redirect to contact page.
but here i want user to be redirect where user clicked the link for login.
i tried with following code but it not working for me.
PHP code:
session_start();
$_SESSION['url'] = $_SERVER['REQUEST_URI'];
$url=$_SESSION['url'];
HTML code
<div class="gallery_div">
<p>
Please Click <strong><a href="login.php?link=<?php echo $url; ?>" style="color:#993b05"> here </a></strong>to login
</p></div>
In login page
session_start();
if(isset($_GET['link']))
{
$_SESSION['url'] = $_GET['link'];
}
when redirect this page it coming with parameter and so page not found is coming. because only login.php is there.
can any one help me on this.
session_startbefore write to session.$urldefined?$_GET['link']and the$_SESSION['url']. If you have it right you may need to redirect withheader('Location:'.$_SESSION['url']);. Otherwise check if you reset or destroy your session on wrong positions.