目錄
登录系统
回复讨论(解决方案)
首頁 後端開發 php教程 求大神给指点下这些代码有什么问题啊,为什么session变量不生效啊

求大神给指点下这些代码有什么问题啊,为什么session变量不生效啊

Jun 23, 2016 pm 01:59 PM

<?php require_once('Connections/yiwuyiwu.php'); ?><?phpif (!function_exists("GetSQLValueString")) {function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") {  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);  switch ($theType) {    case "text":      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";      break;        case "long":    case "int":      $theValue = ($theValue != "") ? intval($theValue) : "NULL";      break;    case "double":      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";      break;    case "date":      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";      break;    case "defined":      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;      break;  }  return $theValue;}}mysql_select_db($database_yiwuyiwu, $yiwuyiwu);$query_Recordset1 = "SELECT * FROM `user`";$Recordset1 = mysql_query($query_Recordset1, $yiwuyiwu) or die(mysql_error());$row_Recordset1 = mysql_fetch_assoc($Recordset1);$totalRows_Recordset1 = mysql_num_rows($Recordset1);?><?php// *** Validate request to login to this site.if (!isset($_SESSION)) {  session_start();}// ***session变量开始了$loginFormAction = $_SERVER['PHP_SELF'];if (isset($_GET['accesscheck'])) {  $_SESSION['PrevUrl'] = $_GET['accesscheck'];}if (isset($_POST['Username'])) {  $loginUsername=$_POST['Username'];  $password=(md5($_POST['Password']));  $MM_fldUserAuthorization = "enable";  $MM_redirectLoginSuccess = "index.php";  $MM_redirectLoginFailed = "zhuce.php";  $MM_redirecttoReferrer = false;  //*** 输入账号和密码,判断转向页面。  mysql_select_db($database_yiwuyiwu, $yiwuyiwu);  	  $LoginRS__query=sprintf("SELECT u_id u_name, pass, enable FROM `user` WHERE u_name=%s AND pass=%s",  //*** 启用符号是这个“&middot;”  GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));      $LoginRS = mysql_query($LoginRS__query, $yiwuyiwu) or die(mysql_error());  $row_LoginRS = mysql_fetch_assoc($LoginRS);  $loginFoundUser = mysql_num_rows($LoginRS);      if ($loginFoundUser) {        $loginStrGroup  = mysql_result($LoginRS,0,'enable');        //***   声明三个会话变量并分配值    $_SESSION['MM_Username'] = $loginUsername;    $_SESSION['MM_UserGroup'] = $loginStrGroup;		$_SESSION['u_id']= $row_LoginRS('u_id');         if (isset($_SESSION['PrevUrl']) && false) {      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];	    }    header("Location: " . $MM_redirectLoginSuccess );  }  else {    header("Location: ". $MM_redirectLoginFailed );  }}?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title></title></head><body>  <h3 id="登录系统">登录系统</h3>  <hr /><form ACTION="<?php echo $loginFormAction; ?>" id="form1" name="form1" method="POST">  <table width="250" border="1" align="center" cellpadding="0" cellspacing="0">    <tr>      <td colspan="2" nowrap="nowrap" bgcolor="#3366CC"><div align="center"><font color="#FFFFFF">用户登陆</font></div></td>    </tr>    <tr>      <td width="100" nowrap="nowrap"><div align="right"><font color="#000000">用户名:</font></div></td>      <td width="235">                <div align="left">          <input name="Username" type="text" id="Username" />      </div></td>    </tr>    <tr>      <td width="100" nowrap="nowrap"><div align="right"><font color="#000000">密码:</font></div></td>      <td width="235">                <div align="left">          <input name="Password" type="password" id="Password" value="" />      </div></td>    </tr>    <tr>      <td colspan="2"><div align="right">        <a href="/test/zhuce.php">注册</a>        <input type="submit" name="Submit" value="登陆" />      </div></td>    </tr>  </table></form></body></html><?phpmysql_free_result($Recordset1);?>
登入後複製


回复讨论(解决方案)

你怎么知道没有生效的?

你怎么知道没有生效的?
因为登录以后我计划用session变量做了if语句,结果if语句没生效

你用了哪个session,你可以echo一下看是否有值。

你把相关代码贴出来

本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

AI Hentai Generator

AI Hentai Generator

免費產生 AI 無盡。

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
2 週前 By 尊渡假赌尊渡假赌尊渡假赌
倉庫:如何復興隊友
4 週前 By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒險:如何獲得巨型種子
3 週前 By 尊渡假赌尊渡假赌尊渡假赌

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

11個最佳PHP URL縮短腳本(免費和高級) 11個最佳PHP URL縮短腳本(免費和高級) Mar 03, 2025 am 10:49 AM

11個最佳PHP URL縮短腳本(免費和高級)

Instagram API簡介 Instagram API簡介 Mar 02, 2025 am 09:32 AM

Instagram API簡介

在Laravel中使用Flash會話數據 在Laravel中使用Flash會話數據 Mar 12, 2025 pm 05:08 PM

在Laravel中使用Flash會話數據

構建具有Laravel後端的React應用程序:第2部分,React 構建具有Laravel後端的React應用程序:第2部分,React Mar 04, 2025 am 09:33 AM

構建具有Laravel後端的React應用程序:第2部分,React

簡化的HTTP響應在Laravel測試中模擬了 簡化的HTTP響應在Laravel測試中模擬了 Mar 12, 2025 pm 05:09 PM

簡化的HTTP響應在Laravel測試中模擬了

php中的捲曲:如何在REST API中使用PHP捲曲擴展 php中的捲曲:如何在REST API中使用PHP捲曲擴展 Mar 14, 2025 am 11:42 AM

php中的捲曲:如何在REST API中使用PHP捲曲擴展

在Codecanyon上的12個最佳PHP聊天腳本 在Codecanyon上的12個最佳PHP聊天腳本 Mar 13, 2025 pm 12:08 PM

在Codecanyon上的12個最佳PHP聊天腳本

宣布 2025 年 PHP 形勢調查 宣布 2025 年 PHP 形勢調查 Mar 03, 2025 pm 04:20 PM

宣布 2025 年 PHP 形勢調查

See all articles