我继承了一个小型办公室游泳池网站。最近我的主机升级了我的服务器,PHP脚本停止工作。我现在能够解决一些错误并抑制其他错误,但登录后不会保留$ user_id。登录后,我可以看到"玩家"链接。选择其中一个链接会显示页面,但无法访问用户。请求的任何新页面都表现得好像没有登录。我确定代码已经很老了。我只需要重新开始并完成赛季。我不知道该怎么做。希望可以阅读。
<?
session_start();
include "functions.php";
include "uiFunctions.php";
// session_register("user_id");
$_session['userid']= $user_id;
// session_register("groupID");
$_session['groupID']= "groupID";
// log in/out sequence
if ($logout) $user_id = 0;
if ($login_step)
{
$check = dbFetch("SELECT id FROM users WHERE user='".$userName."' AND
pass=PASSWORD('".$userPass."') AND ((activated>0 AND
banned=0) OR is_admin=1)");
if ($check[0])
{
$user_id = $check[0];
$page = "";
dbQuery("UPDATE users SET last_login=NOW() WHERE
id='".$user_id."'");
}
}
$user_info = dbFetch("SELECT full_name, is_admin FROM users WHERE
id='".$user_id."'");
$user_name = $user_info[0];
$user_admin = $user_info[1];
$page_path = $_SERVER['PHP_SELF'];
// -----------------------------------------------------------------
$m_curSystemTimeStamp = dbFetch("SELECT DATE_ADD(NOW(), INTERVAL 1 HOUR)");
$m_curSystemTimeStamp = dbFetch("SELECT
DATE_FORMAT('".$m_curSystemTimeStamp[0]."', '%Y-%m-%d'), ".
"DATE_FORMAT('".$m_curSystemTimeStamp[0]."', '%H:%i:%s')");
$m_CURDATE = $m_curSystemTimeStamp[0];
$m_CURTIME = $m_curSystemTimeStamp[1];
?><html>
<head>
<title>Pick'em</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel='stylesheet' href='base.css' type='text/css'>
</head>
<script language=javaScript>
<!--
function finishedLoading()
{
<? if (!empty($user_admin)) echo "return;"; ?>
for(x=0;x<document.all.length;x++)
{
me = document.all[x];
tg=me.tagName;
if (tg=='DIV' || tg=='IMG' || tg=='TD' || tg=='SPAN' || tg=='B' ||
tg=='BODY' || tg=='FONT' || tg=='NOBR')
{
me.unselectable='on';
me.style.cursor='default';
}
}
}
-->
</script>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"
style="background: #3A4774 url(img/page_bg.gif) repeat-x"
onLoad="finishedLoading()">
<table align=center border=0 cellspacing=0 cellpadding=0>
<tr><td rowspan=3 width =1><img src="img/spacer.gif" height=123 width=1>
</td>
<td height=1><img src="img/spacer.gif" width =770 height=1></td>
</tr>
<tr><td class="logo_text" height=55>Pick'em</td></tr>
<tr><td class="logo_text" height=48><img src="img/spacer.gif" width =770
height=1></td></tr>
<tr><td colspan=2>
<table border=0 cellspacing=0 cellpadding=0>
<tr><td valign=top width=140><img src='img/spacer.gif' width=140 height=1>
</td>
<td valign=top width=640><img src='img/spacer.gif' width=460 height=1>
</td>
</tr><tr><td valign=top>
<?
// ---------------------------------------------------------------------
// the left panels
uiStartPannel("Site map", 135);
uiLink("Home" , $page_path);
uiLink("Race results", $page_path."?page=race_rez");
uiLink("Standings" , $page_path."?page=standings");
uiLink("Rules" , $page_path."?page=rules");
uiEndPannel();
uiPannelDelimiter();
uiStartPannel("Players area", 135);
if (empty($user_id))
{
// uiLink("Log in here" , $page_path."?page=closed");
uiLink("Log in here" , $page_path."?page=login");
uiLink("Register now" , $page_path."?page=new_user");
// uiLink("Register now" , $page_path."?page=closed");
} else {
if (empty($user_admin))
{
uiLink("Make your picks", $page_path."?page=make_picks");
uiLink("Everyone's pick", $page_path."?page=everyone_pick");
uiLink("Player info..." , $page_path."?page=view_player");
uiLink("Driver info..." , $page_path."?page=view_driver");
} else {
uiLink("Everyone's pick" , $page_path."?
page=everyone_pick");
uiLink("Edit players" , $page_path."?page=adm_users");
uiLink("Edit player picks", $page_path."?page=adm_picks");
uiLink("Edit races" , $page_path."?page=adm_races");
uiLink("Edit race results", $page_path."?page=adm_results");
uiLink("Edit drivers" , $page_path."?page=adm_drivers");
}
uiLink("Prize Table", $page_path."?page=prizes");
uiLink("Change password", $page_path."?page=change_pw");
uiLink("Log out" , $page_path."?logout=1");
}
uiEndPannel();
$serverDate = dbFetch("SELECT DATE_FORMAT('".$m_CURDATE."', '%D %b
%Y')");
echo "<div class=pannel_text><br>Server time: <br>".
"<div align=left>".substr($m_CURTIME, 0, 5)." ".$serverDate[0]."
</div></div><br><br><br>\n";
// ------------------------------------------------------------
echo "</td><td valign=top align=center>";
// the middle area
if (empty($page)) $page = "home";
include $page.".php";
?></td></tr>
<tr><td colspan=2><? PushCopyrightNote(); ?></td></tr>
</table>
</td></tr></table>
</body></html>
答案 0 :(得分:0)
据我了解代码:登录后,user_id不会保存在Session中。此行$_session['userid']= $user_id;
始终将用户ID设置为不存在的变量。
也许这有效:
<?
session_start();
include "functions.php";
include "uiFunctions.php";
// log in/out sequence
if ($logout) $user_id = 0;
if ($login_step)
{
$check = dbFetch("SELECT id FROM users WHERE user='".$userName."' AND
pass=PASSWORD('".$userPass."') AND ((activated>0 AND
banned=0) OR is_admin=1)");
if ($check[0])
{
$user_id = $check[0];
$page = "";
dbQuery("UPDATE users SET last_login=NOW() WHERE
id='".$user_id."'");
$_SESSION['userid']= $user_id; // Write in session
}
}
// Read from session
$user_id = $_SESSION['userid'];
$user_info = dbFetch("SELECT full_name, is_admin FROM users WHERE
id='".$user_id."'");
$user_name = $user_info[0];
$user_admin = $user_info[1];
$page_path = $_SERVER['PHP_SELF'];