1

如何将变量添加到$_SESSION?

$product = 0;
$_SESSION['product_number'.$product.''] = true;

它不工作。

4

2 回答 2

6

你需要确保你使用了session_start()

page1.php

<?php
session_start();

$product = 0;
$_SESSION['product_number'.$product] = true;

?>

page2.php

<?php
session_start();
$product = 0;
if ($_SESSION['product_number'.$product]) echo 'Session variable was set!';
else echo 'It was not!';
?>
于 2012-11-02T21:38:41.690 回答
5

这可能对您有用:

<?
session_start();
$product = 0;
$_SESSION['product_number'] = $product;
?>
于 2012-11-02T21:42:38.760 回答