简体   繁体   English

我的会话不会奏效

[英]My SESSION won't work

Register Page: 注册页面:

$_SESSION['namex']=$_POST['username'];
$_SESSION['passx']=$_POST['pass'];
$_SESSION['confirmpassx']=$_POST['confirmpass'];
$_SESSION['emailx']=$_POST['email'];
$_SESSION['confirmemailx']=$_POST['email2'];
$_SESSION['keyx']=$_POST['byond'];

Index Page 索引页面

$namex=$_POST['username'];
$passx=$_POST['pass'];
$pass2x=$_POST['confirmpass'];
$emailx=$_POST['email'];
$email2x=$_POST['email2'];
$ByondKeyx=$_POST['byond'];
str_replace($namex,$_SESSION['namex'],$namex);
str_replace($passx,$_SESSION['passx'],$passx);
str_replace($pass2x,$_SESSION['confirmpassx'],$pass2x);
str_replace($emailx,$_SESSION['emailx'],$emailx);
str_replace($email2x,$_SESSION['confirmemailx'],$email2x);
str_replace($keyx,$_SESSION['keyx'],$keyx);

Alright, so what these codes are supposed to do is the Register Page is doing it's thing (I think) and the Index page is a page that if something is wrong like used Username or password or the Username is invaild then the index page comes in and makes another form with the same data as the Register page. 好吧,所以这些代码应该做的是Register Page正在做的事情(我认为),而Index页面是一个页面,如果出现错误,如使用用户名或密码或用户名是invaild那么索引页面进来并使用与“注册”页面相同的数据创建另一个表单。 sorry if it's hard to read/understand. 对不起,如果难以阅读/理解。 If you wanted to see my website and see what I mean then here's the link: http://snyp.freeoda.com Thanks for reading and please help. 如果你想看到我的网站,看看我的意思,那么这里是链接: http://snyp.freeoda.comhttp://snyp.freeoda.com感谢阅读,请帮助。

Add session_start() to the top of each file And add $_SESSION['varname'] in front of each str_replace call. session_start()添加到每个文件的顶部并在每个str_replace调用前添加$_SESSION['varname'] (or whatever you're trying to assign to, can't quite tell) (或者你要分配的任何东西,都不能说清楚)

Do you have the session_start(); 你有session_start(); function call at the very beginning of your code? 函数调用在代码的最开头?
Note: No newlines, whitespaces are allowed before it. 注意:在它之前不允许有换行符,空格。

First off, this answer assumes you have session_start() at the top of both scripts and that no errors / warnings are visible when the page is shown (using error_reporting(-1) and ini_set('display_errors', 'On') . 首先,这个答案假设你在两个脚本的顶部都有session_start() ,并且在显示页面时没有可见的错误/警告(使用error_reporting(-1)ini_set('display_errors', 'On')

Your register page stores the posted fields inside the session: 您的注册页面将已发布的字段存储在会话中:

$_SESSION['namex']=$_POST['username'];

That's all fine; 那一切都很好; let's assume that you redirect back to the index page. 我们假设您重定向回索引页面。 The index page can then take the values from the session directly: 然后,索引页面可以直接从会话中获取值:

$namex = $_SESSION['namex'];

Assuming the form on the index page uses $namex to build the form. 假设索引页面上的表单使用$namex来构建表单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM