[英]how to save in a session variable an array extracted from a database to send it to other web pages in php
[英]How to save generated numbers of array in session for the other php file?
这是第一个 php 文件的代码:
<html>
<body>
<form name="form" method="post">
Size of array: <input type="number" name="size">
<input type="submit" name="Send" button style="width:700px;height:250px" value="Show array"></span></p>
</form>
</body>
</html>
<?php
session_start();
if(isset($_POST['Send']))
{
for ($i = 0; $i < $_POST['size']; $i ++)
{
$random[] = rand(0, 10);
}
$_SESSION['random'] = $random;
var_dump($_SESSION['random']);
//sort($random);
echo "<br>";
echo "<br>";
echo "Amount of array's elements: ";
echo '<strong>'.count($random).'</strong>';
header('Location: 2nd_form.php');
exit();
}
?>
这是第二个文件的代码:
<?php
// Start the session
session_start();
//session_start();
var_dump($_SESSION['random']);
?>
那么,如何保存第一种形式的数组并且代码必须将其保存为第二个文件? 请帮助:-(
这将与您合作
<?php
session_start();
if(isset($_POST['Send']))
{
for ($i = 0; $i < $_POST['size']; $i ++)
{
$random[] = rand(0, 10);
}
$_SESSION['random'] = $random;
//var_dump($_SESSION['random']);
//use die to stop script and do var_dump
//die();
//
//dont print anything before header
//
header('Location: 2nd_form.php');
exit();
}else{
?>
<html>
<body>
<form name="form" method="post">
Size of array: <input type="number" name="size">
<input type="submit" name="Send" button style="width:700px;height:250px" value="Show array"></span></p>
</form>
</body>
</html>
<?PHP
}
?>
2nd_form.php:
<?php
// Start the session
session_start();
//session_start();
var_dump($_SESSION['random']);
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.