0
具有在本地主機會議的問題,我的問題是,當它重定向到新的崗位頁面會話實際上並不工作,它的反應是,你應該先登錄會議不能正常工作
登錄代碼
<?php
include '../Class/db.class.php';
include '../Class/validation.class.php';
@session_start();
if(!$_SESSION['user']){
$link=$_GET['dir'];
if($link){
echo <<<EOF
<html> <head><title>ورود</title></head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<form method='post' action='index.php?dir=$link'>
Username: <input type='text' name='user'><br />
password<input type='password' name='pass'><br />
<input type='hidden' name='hidd' value=1>
<input type='submit' value='login'><br />
</form>
EOF;
}
else {
echo <<<EOF
<html> <head><title>login</title></head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<form method='post' action='index.php'>
username: <input type='text' name='user'><br />
password: <input type='password' name='pass'><br />
<input type='hidden' name='hidd' value=1>
<input type='submit' value='login'><br />
</form>
EOF;
}
}
$db=new db("localhost", "root", "", "blog");
$con=$db->connect();
$logout=$_GET['logout'];
$user=$_POST['user'];
$pass=$_POST['pass'];
$hidden=$_POST['hidd'];
if($hidden){
if(!$user){
echo "username field can't left blank";
}
elseif (!$pass) {
echo 'password field can't left blank!';
}
else{
$userres=$db->usersearch($user, $pass);
if($userres==FALSE){
echo 'username or password is wrong';
}
else {
$_SESSION['user']=$user;
}
}
}
if($_SESSION['user']){
$link=$_GET['dir'];
echo "you logged in ".$_SESSION['user'];
if($link=="new")
echo '<meta http-equiv="REFRESH" content="0;url=../admin/post/new.php">';
}
if($logout)
session_destroy();
if($_SESSION['user'])
echo '<br /><a href="?logout=1">logout</a>';
?>
新的職位代碼
<?php
@session_start();
if($_SESSION['user']=="admin"){
include '../../Class/db.class.php';
echo <<<EOF
<form method=post action="new.php">
<br /> subject:
<br />
<input type="text" name="title"><br />
post:<br />
<textarea cols=50 rows=10 name="post"></textarea><br />
<input type="submit" value="send">
EOF;
$title=$_POST['title'];
$post=$_POST['post'];
$db=new db("localhost", "root", "", "blog");
$db->connect();
if($title && $post){
$d=$db->post_insert($title, $title, 1);
if($d==TRUE)
echo "post created";
else
echo "an error occurred while sending the post";
}
$dd=$db->read(0, 20);
for($i=0;$i<20;$i++){
echo $dd['content'][$i]."<br />";
}
}
else
{
echo "you should login first";
echo $_SESSION['user'];
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
?>
請幫幫我!
首先你能告訴我你爲什麼使用@session_start(); @將壓制任何警告等等所以我要做的第一件事就是調用@session_start(); as session_start(); – 2012-02-25 06:30:21
問題解決了謝謝 – hatef 2012-02-25 06:41:37