请帮我解决这个问题。我只想在会话被激活时访问页面的内容,否则重定向用户首先激活会话。但是,当我将用户重定向到会话页面时,它会卡住,无法返回到内容页面。我是新来的,所以请帮我解决这个问题。访问页面的内容,如果会话被激活,否则激活会话第一
<?php
session_start();
if(!isset($_SESSION['username'])){
\t \t echo "cookie is not activated" ;
\t \t header('Location: http://localhost/CC/Loginsession.php');
\t \t die;
}
else {
?>
<!doctype html>
<html>
<head>
<title>Update in PHP</title>
</head>
<body>
<?php
\t \t $servername="localhost";
\t \t $username="root";
\t \t $password="";
\t \t $conn=mysql_connect($servername,$username,$password);
\t
\t if(!$conn) {
\t \t die('Could not connect: ' . mysql_error());
\t }
\t \t $sq1 = 'select * from biodata';
\t \t mysql_select_db('firstdb');
\t \t $display=mysql_query($sq1,$conn);
\t if(!$display) {
\t
\t \t \t \t die('Could not get data: ' . mysql_error());
\t \t \t \t exit;
\t }
\t if (mysql_num_rows($display) == 0) {
\t \t \t \t echo "No rows found, nothing to print so am exiting";
\t \t \t \t exit;
\t }
?>
<table border="2" style= "background-color: #84ed86; color: #761a9b; margin: 0 auto;" >
<thead>
<tr>
<th>ID</th>
<th>Fname</th>
<th>Lname</th>
<th>Email</th>
<th>Phone</th>
<th>Message</th>
\t \t <th>Update</th>
</tr>
</thead>
<tbody>
<?php
while($row = mysql_fetch_assoc($display)){
echo
"<form method= 'post' />
\t \t \t \t <tr>
\t \t \t \t \t <td ><input name='UID' value='{$row['ID']}' readonly/></td>
\t \t \t \t \t <td ><input name='upfname' value='{$row['fname']}' /></td>
\t \t \t \t \t <td ><input name='uplname' value='{$row['lname']}' /></td>
\t \t \t \t \t <td ><input name='upemail' value='{$row['email']}' /></td>
\t \t \t \t \t <td ><input name='upphone' value='{$row['phone']}' /></td>
\t \t \t \t \t <td ><input name='upmessage' value='{$row['message']}' /></td>
\t \t \t \t \t <td><input type='Submit' name='update' value='Update' id='".$row["ID"]."' </td>
\t \t \t \t </tr>
\t \t \t </form>";
\t }
?>
</tbody>
</table>
<?php
\t \t if(isset($_REQUEST['update']))
\t \t {
\t \t \t
\t \t \t $id = $_REQUEST['UID'];
\t \t \t $upfn = $_REQUEST['upfname'];
\t \t \t $upln = $_REQUEST['uplname'];
\t \t $upem = $_REQUEST['upemail'];
\t \t \t $upph = $_REQUEST['upphone'];
\t \t \t $upms = $_REQUEST['upmessage'];
\t \t \t
\t \t \t $up="UPDATE biodata
\t \t \t SET
\t \t \t fname='$upfn',
\t \t \t lname='$upln',
\t \t \t email='$upem',
\t \t \t phone='$upph',
\t \t \t message='$upms'
\t \t \t WHERE ID = $id";
\t \t \t $updbb=mysql_query($up,$conn);
\t \t \t
\t \t \t if($updbb){
\t \t header('Location: http://localhost/Prac/updateinsamepage.php');
}
\t
\t \t }
}
?>
\t \t \t
</body>
</html>>
和我的会话登录表单代码是在这里
<?php
session_start();
if(isset($_SESSION['username'])){
\t echo "Already registered as $_SESSION[username]" ;
}
else if($_SERVER['REQUEST_METHOD'] == 'POST'){
\t
\t $uname=htmlentities($_POST['username']);
\t $pass=htmlentities($_POST['password']);
\t
\t \t if(!empty($uname) && !empty($pass)) {
\t \t \t $_SESSION['username']=$uname;
\t \t \t echo "Thanks<br />" . "UserName: $uname " . "Password: $pass";
\t \t \t
\t \t \t
\t \t }
\t
\t \t else{
\t \t echo "Please fill out the both fields";
\t \t }
}
else {
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Loginsession</title>
</head>
<body>
<form method="post">
Username:<input type="text" id="username" name="username" /> <br /><br />
Password:<input type="password" id="password" name="password"/><br /><br />
<input type="hidden" name="hiddenvalue" value="<?php http://localhost/CC/Loginsession.php?username=overwritten ?>"/>
<input type="Submit" value="Login" name="Submit" id="submit" />
</form>
<?php }?>
<?php
session_unset();
session_destroy();
?>
</body>
</html>
检查您的PHP日志。您的会话登录页面至少有一个明显的语法错误。你有一个随机的URL输入服务器端代码,在'input'元素中。 – David
@David(程式):5 Uncaught TypeError:无法读取属性'removeAttribute'的nullprotectStyleSheet @ include.preload.js:393 先生是什么意思? –
如果你已经发送了内容(例如'echo'),你就不能使用'header' – apokryfos