Navruk Navruk - 1 year ago 152
PHP Question

How to redirect to the same page after login

I have a cart products page, if a person clicks on a product add to cart button they will be redirected to the login page.

After a successful login, I need to send the user back to same products page.

Answer Source

A simple solution would be to store the "return" URL in a session variable before you kick to the login page. The login page would check for the presence of the session variable and then unset it prior to using a header location re-direct to return the user to the URL in question.

For example on the login page you'd use:

// Successfully logged in...
$destURL = $_SESSION['kickurl'] ? $_SESSION['kickurl'] : '/index.php';
header('Location: ' . $destURL);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download