Advertisement
Guest User

Login PHP

a guest
May 21st, 2013
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.86 KB | None | 0 0
  1. <?php
  2. session_start();
  3. error_reporting(E_ALL^ E_NOTICE);
  4. //include the connection and variable defination page
  5. include("include/server.php");
  6. include("include/function.php");
  7. //checking the form has been submit by user or not
  8. if(isset($_POST['cmdSubmit']) and $_POST['cmdSubmit']="Login")
  9. {  
  10. //$refLink  = $_SERVER['HTTP_REFERER'];
  11. $refLink    = "index.php?err_msg=1";
  12. $user = addslashes($_POST['username']);
  13. $pass = addslashes($_POST['password']);
  14. $remember = $_POST['remember'];
  15.  
  16. $strErrorMessage = "";
  17. if($user==""){
  18.     $strErrorMessage = "User Name can not be blank";
  19. }
  20. if($pass==""){
  21.     $strErrorMessage = "Password can not be blank";
  22. }
  23. if($user=="" and $pass==""){
  24.     $strErrorMessage = "User Name and Password can not be blank";
  25. }
  26.  
  27. if($strErrorMessage=="")
  28. {
  29.  
  30.     if(isset($_POST['remember'])){
  31.         //removing all the cookie at set the user name password in cookies
  32.         unset($_COOKIE[session_name()]);        
  33.         setcookie("usernamex", $_POST['username'], time()+60*60*24*100);
  34.         setcookie("userpassx", $_POST['password'], time()+60*60*24*100);
  35.         setcookie("rememberx", $_POST['remember'], time()+60*60*24*100);
  36.     }else{
  37.         if(isset($_COOKIE['rememberx']) && isset($_COOKIE['usernamex']) && isset($_COOKIE['userpassx']))
  38.         {
  39.             unset($_COOKIE[session_name()]);        
  40.             setcookie("usernamex", $_POST['username'], time());
  41.             setcookie("userpassx", $_POST['password'], time());
  42.             setcookie("rememberx", $_POST['remember'], time());
  43.         }
  44.     }
  45.  
  46.     $sqlLogin   = "select * from member_mast where username = '".$user."' and password = '".$pass."' and is_deleted_flg=0 and is_profile=0";        
  47.     $queryLogin = mysql_query($sqlLogin) or die(mysql_error()." Please check the Query");
  48.     $totLogin   = mysql_num_rows($queryLogin);      
  49.  
  50.     //here checking the user is authorized or not
  51.     if($totLogin>0)
  52.     {
  53.         $rsLogin                = mysql_fetch_array($queryLogin);  
  54.         $_SESSION['uid']        = trim($rsLogin['username']);
  55.         $_SESSION['memberid']       = trim($rsLogin['user_id']);
  56.         $_SESSION['userType'] = trim($rsLogin['member_role']);
  57.  
  58.         if(isset($_POST["page"]) and trim($_POST["page"])!="")
  59.         {
  60.             $pageName       = trim($_POST["page"]);
  61.             $pagepassId     = trim($_POST["pageid"]);
  62.             $redirect_url   = "http://www.fakesite.com/fspv2/welcome.php?page=".$pageName."&pageid=".$pagepassId;
  63.         }
  64.         else
  65.         {
  66.             //$redirect_url = "http://www.fakesite.com/fspv2/welcome.php";
  67.             //$redirect_url = "welcome.php";
  68.             $redirect_url   = "welcome.php";
  69.         }
  70. //header("Location: ".$redirect_url);
  71. ?>
  72.         <script>window.location.href="<?php echo $redirect_url; ?>";</script>
  73.       <!--  <meta http-equiv="refresh" content="0;url=<?php echo $redirect_url; ?>">    -->
  74. <?php
  75. }
  76. else
  77. {      
  78.         $displayMessage = "Login failed. If you are authorized, try again";
  79.         session_destroy();
  80.         $state = "inv";
  81.         $_SESSION['username'] = $_POST['username'];
  82.         $_SESSION['password'] = $_POST['pass'];        
  83.         $username = $_SESSION['username'];
  84.         $password = $_SESSION['password'];  
  85.     ?>
  86.         <script>window.location.href="<?php echo $refLink; ?>";</script>
  87.     <?php      
  88.     }
  89. }
  90. else
  91. {  
  92.     $state = "inv";
  93.     $_SESSION['username'] = $_POST['userid'];
  94.     $_SESSION['password'] = $_POST['pass'];
  95.     $username = $_SESSION['username'];
  96.     $password = $_SESSION['password'];
  97.     $displayMessage = $strErrorMessage;
  98. ?>
  99.     <script>window.location.href="<?php echo $refLink; ?>";</script>
  100. <?php      
  101. }  
  102. }
  103.  //header("Location: ".$refLink);
  104. ?>
  105. <!--<script>window.location.href="<?php echo $refLink; ?>";</script>--> <!-- <meta http-equiv="refresh" content="0;url=<?php echo $refLink; ?>">  -->
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement