开发者

I want to store a php $_SESSION variable and retrieve it on another page

开发者 https://www.devze.com 2023-01-03 10:42 出处:网络
<?php session_start(); // store session data $_SESSION[\'count\']=0; ?> <html><head></head>
<?php 
session_start();
// store session data
$_SESSION['count']=0; ?>

<html><head></head>
<body>
<?php include ("getElement.php");
echo getLinkButton("myscript.php", "myscript.php"); 
echo $_SESSION['count']++; ?>

</body> 
</html>

The code above works, but when I click the link to navigate to myscript.php:

<?php
echo $_SESSION['count'];
?>

I get this error: Undefined variable: _SESSION in /home/ubuntu/public_开发者_运维问答html/myscript.php on line 2


Use session_start() in the second page too, before accessing the $_SESSION superglobal array.


myscript.php:

<?php
session_start();

echo $_SESSION['count'];
?>

You must include session_start at the top of all pages you wish to use the session in.


you have to do session_start(); on every page you want to use the session-vars and also be sure you have cookies enabled or send the session-id with every link and form.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号