PHP Redirect back to previous page after login Turn Back
2016-09-09 11:15:25
The PHP script including condition terms before loaded content.
If the condition is false
The script will redirecting back to the login page with location parameters.
Main page (index.php)
<?phpif ( $user_authen != TRUE ) {header("Location:login.php?location=" . urlencode($_SERVER['REQUEST_URI']));exit;}?>
login.php
<?phpif( trim($_POST['location']) != '' ){$redirect_url = trim($_POST['location']);}// Authentication methodsif (Authen == TRUE){// Somethingif($redirect != ''){header('Location: '.$redirect_url);}else{header('Location: default_page.php');}}?>
Hope you enjoy