Php会话不存储在webhost上

问题描述 投票:-1回答:1

我做了一个简单的会话,并在我的localhost(xampp)上完美地工作

第一页是这样的

<?php 
     if(!session_start()):
        session_start();
     endif;
?>

<?php
$_SESSION['user'] = "grace1004";
echo '<a href = "2ndpage.php">Please Click</a>';
?>

第2页

<?php
     if(!session_start()):
        session_start();
     endif;
     ?>
     <?php
if($_SESSION['user']) {
echo $_SESSION['user'];
}
else {
    echo ' hahahaha'; //i made this to check if the session is being stored
}

?>

即时通讯使用000webhostapp,错误说未定义索引:用户

php
1个回答
0
投票

<?php
session_start();
    
    
if(!empty($_SESSION['user'])) {
echo $_SESSION['user'];
}
else {
    echo ' hahahaha'; //i made this to check if the session is being stored
}

?>
you shoud use session_start(); at the beginning of each php file you need to use a session try this !
© www.soinside.com 2019 - 2024. All rights reserved.