会话问题 [英] Session Problem

查看:65
本文介绍了会话问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用会话来允许人们登录我的网站。问题

有时它会起作用,有时它不会!据我所知,我的

脚本很好(因此有时为什么会这样)我有人告诉我

它也很好。基本上,当用户输入他们的用户名和密码时,它会对我的mysql数据库进行检查,如果正确则创建会话,并且
将其用户名存储在名为uname的变量中。然后,当他们

访问该网站的另一个区域时,它会检查它是否设置了uname,如果它是b $ b那么它允许他们访问该区域,如果它不是要求他们再次登录

。会话ID保留,所以我知道会话在那里,但它没有
总是注册变量uname。我认为php版本是4.1.2(它是在sourceforge上托管的
)。


有人可以帮忙吗?

Darrell

I''m trying to use sessions to allow people to log into my site. The problem
is that sometimes it works and sometimes it doesn''t! As far as I''m aware my
script is fine (hence why it works sometimes) and I''ve had people tell me
it''s fine too. Basically, when a user enters their username and password it
checks that against my mysql database and if correct creates a session and
stores their username in it in a variable called uname. Then, when they
access another area of the site it checks to see it uname is set and if it
is then it lets them access that area and if it isn''t asks them to log in
again. The session id is kept so I know the session is there but it doesn''t
always register the variable uname. I think the php version is 4.1.2 (it''s
hosted on sourceforge).

Can anyone help?

Darrell

推荐答案

Darrell,


你能发布一些你的代码?否则我们只能猜测为什么

它不起作用,甚至那可能是一个很长的镜头。


Marcus

Darrell,

Can you post some of your code? Otherwise we can only guess as to why
it isn''t working, and even that would probably be a long shot.

Marcus


好的。我在下面列出了三个文件。 admin.php是用户输入

用户名和密码的地方。 admin2.php是检查用户名和

密码并显示管理部分和addnews.php允许您向网站添加

新闻的地方。当我尝试添加有时有效的新闻时,

有时候不会。当我点击添加新闻的一半时间它会显示添加

新闻部分,而有一半时间它没有。这是因为uname不应该设置为
(并且是一半的时间)。如果你想看到网站

转到 http:/ /linrar.sourceforge.net/index2.php (我会将它重命名为index.php

一旦网站正常工作)。


admin。 php


<?php

session_start();

session_unset();

session_destroy ();

?>

< html>

< head>

< link rel = QUOT;样式表"类型= QUOT;文本/ CSS" href =" style.css">

< title> LinRAR主页< / title>

< / head>

< ; body>

< table border =" 0" CELLPADDING = QUOT; 0" cellspacing =" 0">

< tr>

< td>

< table border =" 0" CELLPADDING = QUOT; 10" cellspacing =" 0">

< tr>

< td width =" 122" valign =" top">

< table width =" 122"边界=" 0" CELLPADDING = QUOT; 2英寸cellspacing =" 0"

bgcolor ="#000000">

< tr>

< td>

< table width =" 120"边界=" 0" CELLPADDING = QUOT; 5英寸cellspacing =" 0"

bgcolor =" #ffffff">

< tr>

< td>

< a href = index.php>新闻< / a>< br>

< a href = about.php>关于< / a>< br>

< a href = download.php>下载< / a>< br>

< a href = support.php>支持< / a>< br> ;

< a href =" http://sourceforge.net/projects/linrar"> Sourceforge< / a>< br>

< a href =" admin.php"> Admin< / a>< br>

< / td>

< / tr>

< / table>

< / td>

< / tr>

< / table>

< / td>

< td valign =" top">

< h1> LinRAR - 管理员< / h1>

< br>

要登录管理部分,请在下方输入您的用户名和密码,然后点击输入:< br>< br>

< form action = admin2.php见过hod = post>

< table>

< tr>< td>

UserName< / td>< td>< ; input type =" text" name =" lruname">< / td>< / tr>

< tr>< td>

密码< / td>< td> ;< input type =" password" name =" lrpass">< / td>< / tr>

< / table>

< br>

< input type =" submit"值= QUOT的Enter键; class =" flatbutton">

< / form>

< / td>

< / tr>

< / table>

< / td>

< / tr>

< / table>

< / body>

< / html>


admin2.php


<?php

session_start();

?>

< html>

< ; head>

< link rel =" stylesheet"类型= QUOT;文本/ CSS" href =" style.css">

< title> LinRAR主页< / title>

< / head>

< ; body>

<?php
Ok. I''ve listed three files below. admin.php is where the user enters their
username and password. admin2.php is where it checks the username and
password and displays the admin section and addnews.php allows you to add
news to the site. It''s when I try to add news when it sometimes works and
sometimes doesn''t. When I click add news half of the time it shows the add
news section and half of the time it doesn''t. This is because uname isn''t
set when it should be (and is half of the time). If you want to see the site
go to http://linrar.sourceforge.net/index2.php (I will rename it index.php
once the site works).

admin.php

<?php
session_start();
session_unset();
session_destroy();
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<title>LinRAR Homepage</title>
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<table border="0" cellpadding="10" cellspacing="0">
<tr>
<td width="122" valign="top">
<table width="122" border="0" cellpadding="2" cellspacing="0"
bgcolor="#000000">
<tr>
<td>
<table width="120" border="0" cellpadding="5" cellspacing="0"
bgcolor="#ffffff">
<tr>
<td>
<a href=index.php>News</a><br>
<a href=about.php>About</a><br>
<a href=download.php>Download</a><br>
<a href=support.php>Support</a><br>
<a href="http://sourceforge.net/projects/linrar">Sourceforge</a><br>
<a href="admin.php">Admin</a><br>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
<td valign="top">
<h1>LinRAR - Admin</h1>
<br>
To log in to the admin section type in your username and password below and
click enter:<br><br>
<form action=admin2.php method=post>
<table>
<tr><td>
UserName</td><td><input type="text" name="lruname"></td></tr>
<tr><td>
Password</td><td><input type="password" name="lrpass"></td></tr>
</table>
<br>
<input type="submit" value="Enter" class="flatbutton">
</form>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>

admin2.php

<?php
session_start();
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<title>LinRAR Homepage</title>
</head>
<body>
<?php


notfounduser = 0;
notfounduser = 0;


这篇关于会话问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆