บทความ > PHP

PHP Redirect back to previous page after login Turn Back

เมื่อ 2016-09-09 11:15:25

php redirect back to previous page after authentication successful
 
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)
<?php
 
if ( $user_authen != TRUE ) {
  header("Location:login.php?location=" . urlencode($_SERVER['REQUEST_URI']));
  exit;
}
 
?>
 
login.php
 
<?php
 
if( trim($_POST['location']) != '' )
{
      $redirect_url = trim($_POST['location']);
}
 
// Authentication methods
if (Authen == TRUE)
{
      // Something
 
      if($redirect != '')
      {
                  header('Location: '.$redirect_url);
      }
      else
      {
                  header('Location: default_page.php');
      }
}
 
?>
 
Hope you enjoy
 
Turn Back

Automotive ดูทั้งหมด

IT Update ดูทั้งหมด