PHP文件无法跨页面恢复会话变量 [英] PHP File cannot recover session variable across pages

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

问题描述

Okai,所以我尝试将其发布得更早一些,尽管我的问题有所改变. 我已经确定问题出在我的login.php(我分配了$ _SESSION值)和members.php页面(我试图再次选择$ _SESSION变量,但无法恢复它)之间.我发现此问题的方法是在members.php文件中的会话上运行一个var dump,这给了我0.在将login.php中的值赋值并得到赋值后,我也这样做了. 如果您帮助我,我将非常感激!

Okai, so I attempted to post this a bit earlier, although my question has changed slightly. I have identified the problem to be in between my login.php (where I assign the $_SESSION value) and my members.php page (where I try to pick up the $_SESSION variable again, but fail to recover it). The way I identified this problem was by running a var dump on session in my members.php file which gave me 0. I also did this after I asign the value in login.php and I got the asigned value as an outcome. If you help me out I will really appreciate it!

这是我的login.php页面:

This is my login.php page:

<?php
session_start();
require('connect.php');

$username = $_POST['username'];
$password = $_POST['password'];

if (isset($username) && isset($password))
{
    $query = mysql_query("SELECT * FROM login WHERE username='$username' AND password='$password'");
    $result = mysql_num_rows($query);

    if($result > 0)
    {
        echo "You have been logged in. <a href='members.php'>Go to the members page</a>";
        $username = $_SESSION['login'];
    }
    else
    {
        echo "Password is incorrect. Try again.";
    }
}
else
{
    echo "You have to enter your username and password. Try again";
}
?>

这是我的member.php页面:

This is my members.php page:

<?php
session_start();

if (isset($_SESSION['login']))
{
    echo "Welcome " .  $login . " | <a href='logout.php'>Logout</a>";
}
else
{
    header('Location: index.php');
}

?>

推荐答案

解决了聊天问题:

  1. 结果是var_dump(is_writable(session_save_path()));返回了bool(false).

session_save_path()/var/php_sessions/.

realpath(dirname(__FILE__));/hermes/bosoraweb124/b185/dom.gjertgjersundcom/public_html.

我尝试移动会话保存路径-但是由于某些原因,无法写入public_html中的文件夹,与读取相同(无法读取).无论如何,将sessions放在公共文件夹中以供所有人查看仍然是一个坏主意.

I tried moving the session save path -- however for some reason the folder within public_html couldn't be written, same with read (couldn't read). In any case, it's a bad idea to have sessions in the public folder for everyone to see anyway.

我建议OP联系其主机提供商以运行chmod 766 -R /var/php_sessions/的命令.

I recommended the OP contact their host provider to run the command of chmod 766 -R /var/php_sessions/.

已解决:他的虚拟主机上的工作人员已应用权限,现在可以正常工作了.

Solved: The staff at his webhost applied the permissions and it works fine now.

这篇关于PHP文件无法跨页面恢复会话变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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