我想通过一个变量从(register.php)到(submit.php),最后到(yes.php) - 请注意,我已经包括'session_start ();”在每个页面中作为主要PHP页面上的“包含”。PHP会话没有传递到不同的页面(基本)
register.php - 1
<div id = "content">
<form action="submit.php" method="post">
<ul>
<li>
Username*:<br>
<input type="text" name="username">
</li>
<br>
<li>
Email Address*:<br>
<input type="text" name="email">
</li>
<br>
<li>
Telephone Number*:<br>
<input type="text" name="telephone">
</li>
<br>
<li>
Telephone Again*: <br>
<input type="text" name="telephoneagain">
<br>
</li>
<li>
<input type="submit" name="submit">
</li>
</ul>
</form>
</header>
这是一个非常基本的登记表。 然后它被发送到
submit.php - 2
<?php
<div id = "content">
<div id = "feature">
Your username is: <?php echo $_POST['username']; ?> <br>
Your email address is: <?php echo $_POST['email']; ?> <br>
Your telephone number is: <?php echo $_POST['telephone']; ?> <br>
Just to confirm your telephone number: <?php echo $_POST['telephoneagain']; ?>
<br>
<br>
</div>
<div id = "validation">
Is this correct? <br>
<li> <a href="yes.php"> Yes </a> </li>
<li> <a href="register.php"> No </a> </li>
<?php
$_SESSION['username'] = $username;
$_SESSION['email'] = $email;
$_SESSION['telephone'] = $telephone;
$_SESSION['telephoneagain'] = $telephoneagain;
?>
</div>
</header>
同样相当基础,忽视缺乏验证。所以在这里,我可以通过register.php输入用户名。然后,我点击“是”表示信息是正确的。
yes.php - 3
<?php
$_POST['username'];
?>
<?php
if(isset($_SESSION['username']))
echo $_SESSION['username'];
?>
<?php
$sql = "INSERT INTO users (username, email, telephone, telephoneagain)
VALUES ('$username', '$email', '$telephone', '$telephoneagain')";
?>
这里的问题是,变量没有从以前的页面传递,因此该页面无法找到他们。
人都在问我有没有在session_start()的最后一页上,这里是完整的代码
这是yes.php - 3
<?php
include 'includes/yes/yeshead.php';
include 'includes/yes/yesheader.php';
include 'includes/yes/yescontent.php';
include 'includes/yes/yesnav.php';
include 'includes/yes/yesfooter.php';
include 'core/init.php'; ?>
的init.php包含在session_start( );
<?php
session_start();
error_reporting(-1);
require 'core/database/connect.php';
require 'core/users.php';
$current_file = explode('/', $_SERVER['SCRIPT_NAME']);
$current_file = end($current_file);
$errors = array();
?>
你确定包含'session_start()'的文件?如果启动会话的文件需要其余的功能,则应该考虑使用require()而不是include()。 – Abuh 2015-02-11 13:09:17
写入'$ _SESSION'之后,尝试调用'session_write_close()'... – 2015-02-11 13:11:24
您是否启用了cookie?没有Cookie =没有会话 - 除非您手动传递会话ID。 – udondan 2015-02-11 13:15:08