php5 中的无 cookie 身份验证
在我的 PHP 应用程序中,我使用了 UserName & pwd并检查数据库中的用户表,检查用户的有效性。登录成功后,我将凭据存储在服务器会话中,如下所示:
$_SESSION['username'] = $username;
$_SESSION['pwd'] = $pwd;
我检查了会话以确保用户已经登录。您可以看到下面的代码:
if (empty($_SESSION['userId']))
header("Location: login.php");
问题是如果我在浏览器中禁用了 cookie ,即使登录成功也无法进入其他页面。我发现,PHP 会话使用 cookie 在浏览器中存储一些值。无论如何,在 PHP5 中可以使用 cookieless 会话吗?
In my PHP application, I used UserName & Pwd and check the user table in the database to check the validity of users. After the login is successful, I stored the credentials in the Server Session as below:
$_SESSION['username'] = $username;
$_SESSION['pwd'] = $pwd;
And I checked the session to ensure that the user has already logged in. You can see the code below:
if (empty($_SESSION['userId']))
header("Location: login.php");
The problem is if I disabled the cookie in the browser, I could not go into another page even though the log in is successful. I found out that, the PHP session uses the cookie to store some values in the browser. Is there anyway to use cookieless session in PHP5?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

发布评论
评论(4)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
是的,但您需要将
sessid
或sid
附加到每个链接。这里有详细描述:
http://myles.eftos .id.au/blog/2005/11/26/cookie-less-sessions-in-php/
您还需要更改
php.ini
,如下所示:php_value session .use_trans_sid = 1
。Yes, but you need to append the
sessid
orsid
to every link.It's described in detail here:
http://myles.eftos.id.au/blog/2005/11/26/cookie-less-sessions-in-php/
You also need to change
php.ini
like so:php_value session.use_trans_sid = 1
.