简体   繁体   中英

PHP Session not working and immidietly expires

I'm new to PHP and I learn sessions right now, so I tried to to create two files, one that creates the session var and one who prints it.. here's the code: session1.php

<?php session_start(); $_SESSION['a'] = 1;  echo 'The session right now is: ' . $_SESSION['a']; ?>

session2.php

<?php
session_start();
if(isset($_SESSION['a']))
{
    echo $_SESSION['a'];
}
else
{
echo 'but the output here is false';
}
?>

First I enter to session1.php to create the session, then I go to session2.php and the output is false.. This only happens when this files are uploaded to the web hosting, you are welcome to try it yourself in this url: wwww.pzwhatsup.com/session1.php and wwww.pzwhatsup.com/session2.php. When trying this in my computer with wamp, it works perfectly..

Does your hosting company allow Sessions, and did they give a valid path with the proper rights for storing the sessions?

It happens.

Else, do you request the two files right after each other (include or somthing), or is there a page switch in between?

Cause when you set a Session value and request it right after (miliseconds) your value isn't always set properly.

有些网络主机不会创建会话的剧目,所以请尝试阅读您的webhoster的使用条款,也许您会发现有关创建自己的会话库的信息。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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