를 작동하지 않는 문제는 새 게시물 페이지로 리디렉션 할 때 세션이 먼저 로그인해야대로 응답입니다 실제로 작동하지 않는 것입니다세션이 제대로
로그인 코드
<?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(); –
문제 해결 – hatef