Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 会话未反映在页面中_Php_Session - Fatal编程技术网

Php 会话未反映在页面中

Php 会话未反映在页面中,php,session,Php,Session,我已经创建了会话名称($_session['valid']=“yes””)以反映在所有页面中,它在一些页面中有效,但在一些页面中无效,特别是在(pwdchange.php)中,我不知道为什么。有人能看到我的代码并告诉我错误在哪里吗。引导我走过。而且会话文件也没有在/tmp目录中创建 我的代码 第一页ifstatment.php <html> <body> <h1>Welcome To Internet HotSpot</h1> <form

我已经创建了会话名称($_session['valid']=“yes””)以反映在所有页面中,它在一些页面中有效,但在一些页面中无效,特别是在(pwdchange.php)中,我不知道为什么。有人能看到我的代码并告诉我错误在哪里吗。引导我走过。而且会话文件也没有在/tmp目录中创建

我的代码

第一页ifstatment.php

<html>
<body>
<h1>Welcome To Internet HotSpot</h1>

<form action="auth.php" method="post">
Username: <br><input type="text" name="username"></br>
Password: <br><input type="password" name="password"></br>


<div id="main">
<div class="floatdiv">

<input type="submit" name = 'submit' value= 'Login'>
</form>
</div>

<div class="floatdiv">

<form method="POST" action="adminlogin1.php">
<button type="submit">admin login</button>
</form>
</div>
</div>


 <style type="text/css">
 #main
 {
 position:relative;
    width:200px;
 }
.floatdiv
 {
 float:left;
    width=80px
  }
</style>

</body>
</html>

欢迎来到互联网热点
用户名:

密码:

管理员登录 #主要 { 位置:相对位置; 宽度:200px; } .floatdiv { 浮动:左; 宽度=80px }
第二页

Auth.php

<? ob_start(); ?>
<?php

session_start();

//connecting to database

$db = mysql_connect("localhost","sqldata","sqldata") or die(mysql_error());

//selecting our database

$db_select = mysql_select_db("accounts", $db) or die(mysql_error());

ini_set('session.bug_compat_42',0);
ini_set('session.bug_compat_warn',0);

//Retrieving data from html form

if(empty($_POST["username"]))
{

echo "Error you must enter username and password</br>";

}

$username = $_POST['username'];

$password = $_POST['password'];


$_SESSION['username']= $_POST['username'];
//for mysql injection (security reasons)

$username = mysql_real_escape_string($username);

$password = mysql_real_escape_string($password);



//checking if such data exist in our database and display result

$result= mysql_query("select * from uptable where username = '$username' ");

$row = mysql_fetch_array( $result );

$storedPassword = $row['password'];


$hash= crypt($password,$storedPassword)===$storedPassword;

if ($hash)
{

$_SESSION['valid'] = "yes";

$_SESSION['logged_in'] = true;

header("Location: check.php");

$ip = $_SERVER['REMOTE_ADDR'];

exec("/usr/bin/sudo -u apache sudo  /sbin/iptables  -I INPUT -s $ip -j ACCEPT");

exit;
}


else
{
if ($_SESSION['valid'] != "yes")

{

$ip = $_SERVER['REMOTE_ADDR'];

exec("/usr/bin/sudo -u apache sudo  /sbin/iptables  -D INPUT -s $ip -j ACCEPT");

session_destroy();

session_unset();

header("location:ifstatment.php");

exit();
}
}

?>
<? ob_flush(); ?>

会话\u start()
必须在任何输出之前执行:

<? ob_start(); ?>

<html>
<body>
<?php

error_reporting(E_ALL);


session_start();


(您应该考虑使用A),

会话在您提到的页面中工作,但不在PddCux.PHP页面中。请在您的问题中不显示它,请再次在其上看到pWdCux.PHP页面。请执行<代码> PrimtTyr($AY会话);<在
session_start()之后的文件中的code>。你看到什么了吗?如果没有,请确保文件顶部没有任何意外的空白;它在第3行的/var/www/html/phptest/pwdchange.php中显示Notice:Undefined index:valid。没有空格,我查过了。
<?php

session_start();

print_r($valid= $_SESSION['valid']);
print_r($hadi=$_SESSION["valid"]);
print_r($logged_in= $_SESSION["logged_in"]);

?>
<? ob_start(); ?>

<html>
<body>
<?php

error_reporting(E_ALL);


session_start();
<? 
ob_start(); 
session_start();
error_reporting(E_ALL); // This should be up here, too
?>

<html>
<body>