Guest User

probleme_session

a guest
Jan 12th, 2012
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.51 KB | None | 0 0
  1. <?php require_once('Connections/toast_sql.php'); ?>
  2. <?php
  3. //initialize the session
  4. if (!isset($_SESSION)) {
  5.   session_start();
  6. }
  7.  
  8. // ** Logout the current user. **
  9. $logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
  10. if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
  11.   $logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
  12. }
  13.  
  14. if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
  15.   //to fully log out a visitor we need to clear the session varialbles
  16.   $_SESSION['MM_Username'] = NULL;
  17.   $_SESSION['MM_UserGroup'] = NULL;
  18.   $_SESSION['PrevUrl'] = NULL;
  19.   unset($_SESSION['MM_Username']);
  20.   unset($_SESSION['MM_UserGroup']);
  21.   unset($_SESSION['PrevUrl']);
  22.    
  23.   $logoutGoTo = "33.php";
  24.   if ($logoutGoTo) {
  25.     header("Location: $logoutGoTo");
  26.     exit;
  27.   }
  28. }
  29. ?>
  30. <?php
  31. if (!function_exists("GetSQLValueString")) {
  32. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  33. {
  34.   if (PHP_VERSION < 6) {
  35.     $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  36.   }
  37.  
  38.   $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  39.  
  40.   switch ($theType) {
  41.     case "text":
  42.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  43.       break;    
  44.     case "long":
  45.     case "int":
  46.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  47.       break;
  48.     case "double":
  49.       $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  50.       break;
  51.     case "date":
  52.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  53.       break;
  54.     case "defined":
  55.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  56.       break;
  57.   }
  58.   return $theValue;
  59. }
  60. }
  61.  
  62. $colname_test = "-1";
  63. if (isset($_SESSION['MM_username'])) {
  64.   $colname_test = $_SESSION['MM_username'];
  65. }
  66. mysql_select_db($database_toast_sql, $toast_sql);
  67. $query_test = sprintf("SELECT * FROM users WHERE pseudo = %s", GetSQLValueString($colname_test, "text"));
  68. $test = mysql_query($query_test, $toast_sql) or die(mysql_error());
  69. $row_test = mysql_fetch_assoc($test);
  70. $totalRows_test = mysql_num_rows($test);
  71. ?>
  72. <?php
  73. // *** Validate request to login to this site.
  74. if (!isset($_SESSION)) {
  75.   session_start();
  76. }
  77.  
  78. $loginFormAction = $_SERVER['PHP_SELF'];
  79. if (isset($_GET['accesscheck'])) {
  80.   $_SESSION['PrevUrl'] = $_GET['accesscheck'];
  81. }
  82.  
  83. if (isset($_POST['pseudo'])) {
  84.   $loginUsername=$_POST['pseudo'];
  85.   $password=$_POST['pass'];
  86.   $MM_fldUserAuthorization = "";
  87.   $MM_redirectLoginSuccess = "33.php";
  88.   $MM_redirectLoginFailed = "33.php";
  89.   $MM_redirecttoReferrer = false;
  90.   mysql_select_db($database_toast_sql, $toast_sql);
  91.  
  92.   $LoginRS__query=sprintf("SELECT pseudo, pass FROM users WHERE pseudo=%s AND pass=%s",
  93.     GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
  94.    
  95.   $LoginRS = mysql_query($LoginRS__query, $toast_sql) or die(mysql_error());
  96.   $loginFoundUser = mysql_num_rows($LoginRS);
  97.   if ($loginFoundUser) {
  98.      $loginStrGroup = "";
  99.    
  100.     if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
  101.     //declare two session variables and assign them
  102.     $_SESSION['MM_Username'] = $loginUsername;
  103.     $_SESSION['MM_UserGroup'] = $loginStrGroup;      
  104.  
  105.     if (isset($_SESSION['PrevUrl']) && false) {
  106.       $MM_redirectLoginSuccess = $_SESSION['PrevUrl']; 
  107.     }
  108.     header("Location: " . $MM_redirectLoginSuccess );
  109.   }
  110.   else {
  111.     header("Location: ". $MM_redirectLoginFailed );
  112.   }
  113. }
  114. ?>
  115. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  116. <html xmlns="http://www.w3.org/1999/xhtml">
  117. <head>
  118. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  119. <title>Document sans titre</title>
  120. </head>
  121.  
  122. <body>
  123. <?php
  124. if (empty($_SESSION['connected'])) {
  125. ?>
  126. <form id="form1" method="POST" action="<?php echo $loginFormAction; $_SESSION['connected'] = true;?>">
  127.   <p>
  128.     <label for="pse"></label>
  129.     <input type="text" name="pseudo" id="pseudo" />
  130.   </p>
  131.   <p>
  132.     <label for="pass"></label>
  133.     <input type="text" name="pass" id="pass" />
  134.   </p>
  135.   <p>
  136.     <input type="submit" name="ok" id="ok" value="Envoyer" />
  137.   </p>
  138. </form>
  139. <p>
  140.   <?php
  141. } else {
  142. ?>
  143. <a href="<?php echo $logoutAction ?>">Déconnecter</a>
  144. <p><?php echo $row_test['pseudo']; ?>
  145. <p><?php echo $row_test['pass']; ?>
  146. <p>
  147.   <?php
  148. }
  149. ?>
  150. </body>
  151. </html>
  152. <?php
  153. mysql_free_result($test);
  154. ?>
Advertisement
Add Comment
Please, Sign In to add comment