我正在尝试创建在线注册系统。目的是使用户可以创建一个事件,然后成员可以注册它们。我已经使用了我正在使用的登录系统,但是当尝试登录用户时,它并没有结束在所有页面上存储用户名的会话。在创建注册表时,会生成一个新页面,即使我使用其他用户登录或注销,该页面上的会话也会停滞不前并且不会发生变化。我还是相当新的PHP,但除了会话之外一切正常。任何帮助将不胜感激。对不起,请写文章。 这是创建注册表的页面
<?php
session_start();
$sitename = $_POST['eName'];
$title = $_POST['eName'];
$sDate = $_POST['sDate'];
$enDate = $_POST['enDate'];
$exDate = $_POST['exDate'];
$desc = $_POST['desc'];
$pName = $_POST['eName'];
$user = $_POST['user'];
$date = date('Y-m-d');
if($exDate >= $date && $sDate <= $enDate && $sDate > $exDate && !empty($title)) {
$con=mysqli_connect("localhost","emuas","flgdls","EMUAS_signUp");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql="INSERT INTO TEST (EventName, StartDate, EndDate, ExpiryDate, Description, User)
VALUES
('$_POST[eName]','$_POST[sDate]','$_POST[enDate]','$_POST[exDate]','$_POST[desc]','$_POST[user]')";
if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
$eventId = mysqli_insert_id($con);
$file = ' <?php
include ("sign_up.php");
?> ';
$fp = fopen("sign_up_sheets/$sitename.php", "w");
fputs($fp, $file);
fclose($fp);
$styleStPHP = '<?php
session_start();
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="table.css" />
<LINK REL="icon" HREF="http://www.emuas.co.uk/colours.ico" TYPE="image/x-icon">
<LINK REL="SHORTCUT ICON" HREF="http://www.emuas.co.uk/colours.ico" TYPE="image/ico">
</head>
<body bgcolor="#eff0f3">
<center>
<table style=" margin-top:0px" border="0" cellpadding="0" cellspacing="0" width="980" align="center" >
<tr>
<td bgcolor="#313e5b"><div class="div6"><img src="images/title.png" alt="EMUAS ONLINE"></div>
</td>
</tr>
<tr>
<td bgcolor="#646e7d"><div align="right"><img src="images/banner.png" alt=""></div></td>
</tr>
</table>
<table style="margin:0px" border="0" cellpadding="0" cellspacing="0" width="980" align="center">
<tr>
<td style="vertical-align:top" width="200" bgcolor="#ffffff" ><div style="margin-top:30px; margin-right:10px; margin-left:10px; vertical-align:top;">
<?php
include("vlinks.php");
?>
</div></td>
<td colspan="2" bgcolor="#ffffff" valign="top">
<div style="margin-top:0px; margin-bottom:10px;">
<?php
switch($link){
case(\'\'):
include("';
$styleEnPHP = '.php");
break;
default:
include("$link");
break;
}
?>
</div></td>
</tr>
</table>
<table style="margin:0px" border="0" cellpadding="0" cellspacing="0" width="980" align="center">
</tr>
<tr>
<td colspan="2" bgcolor="#ffffff" id="main2" align="center"><div align="center" style="margin:3px"><font size="1" color="black"><br>
Copyright 2008</font></div> </td>
</tr>
<tr>
<td colspan="2" bgcolor="#ffffff" class="div1"><img src="images/spacer.gif" width="1" height="20" alt=" "></td>
</tr>
<tr>
<td colspan="2" bgcolor="#646e7d"><img src="images/spacer.gif" width="1" height="8" alt=" "></td>
</tr>
<tr>
<td width="50%" valign="top"><div align="left" style="margin-top:10px;"><img src="images/logo_ft.png" alt="Royal Air Force"></div></td>
<td width="50%"><div align="right" style="margin-top:4px"><img src="images/crest_ft.png" alt="crest"></div></td>
</tr>
</table>
</center>
</body>
</html>';
$fps = fopen("sign_up_sheets/$eventId.php", "w");
fputs($fps, $styleStPHP);
fputs($fps, $sitename);
fputs($fps, $styleEnPHP);
fclose($fps);
mysqli_close($con);
$_SESSION['create'] = TRUE;
header ("Location: sign_up.php");
} else{
$_SESSION['error'] = TRUE;
header ('Location: sign_up_createS.php');
}
?>
这是新页面中包含的内容。 (sign_up.php)
<?php
var_dump($_SESSION);
if (isset($_SESSION["username"])){
$url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$parts = explode("/",$url);
$name = explode(".",$parts[5]);
$eventId = $name[0];
$con=mysqli_connect("localhost","emuas","*****","EMUAS_signUp");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
echo "<table class='styleTitle'>
<tr>
<th></br></th>
</tr>";
$event = mysqli_query($con,"SELECT * FROM TEST WHERE EventID='$eventId' LIMIT 1");
while($event_row = mysqli_fetch_array($event))
{
echo "<tr>";
echo "<th>" . $event_row['EventName'] . "</th>";
echo "</tr>
<tr>
<td><br /></td>
</tr>
<tr>
<th> Created By:</th>
</tr>
<tr>";
echo "<td>" . $event_row['User'] . "</td>";
echo "</tr>
<tr>
<td><br /></td>
</tr>
<tr>
<th> Start Date: </th>
<th> End Date: </th>
<th> Expiry Date: </th>
</tr>
<tr>";
echo "<td>" . $event_row['StartDate'] . "</td>";
echo "<td>" . $event_row['EndDate'] . "</td>";
echo "<td>" . $event_row['ExpiryDate'] . "</td>";
echo "</tr>
<tr>
<td><br /></td>
</tr>
</table>
<table class='styleTitle'>
<tr>
<th>Description</th>
</tr>
<tr>";
echo "<td>" . $event_row['Description'] . "</td>";
}
echo "<tr>
<td></br></td>
</tr>
</table>";
echo "<table class='style'>
<tr>
<th>Name</th>
<th>Comments</th>
</tr>";
$sign = mysqli_query($con,"SELECT * FROM SIGN_UP_TEST WHERE EventID='$eventId' ORDER BY User");
while($row = mysqli_fetch_array($sign))
{
echo "<tr>";
echo "<td>" . $row['User'] . "</td>";
echo "<td>" . $row['Comments'] . "</td>";
echo "</tr>";
}
echo "</table>
<p> </p>";
mysqli_close($con);
}
else {
header ('Location: http://www.emuas.co.uk/members/sign_up.php');
}
?>
<form action="sign_user.php" method="post">
<input type="hidden" name="id" value="<?php echo ($eventId) ?>" /><table>
<td> Comments: <br /> <input type="text" name="comments"/>
<input type="submit" value="Sign Up"/> </td>
</tr>
</table>
</form>
从var_dump($_SESSION)
返回的值为array(1) { ["username"]=> string(5) "Admin" }
即使我退出或以其他人身份登录,它仍然是