다른 HTML 페이지에 로그인 세션 정보를 전달할 수 없습니다. 아래는 내 로그인 PHP 코드입니다. 성공적으로 로그인 할 수 있지만 HTML 홈 페이지와 같은 다른 페이지로 정보를 전달할 수는 없지만 동일한 페이지에 로그인하지 않아도 열립니다. 같은 코드를 시도했습니다PHP에서 페이지간에 로그인 세션을 사용할 수 없습니다
<?php
require_once("config.php");
$email=$_POST['email'];
$password=$_POST['password'];
$email = stripslashes($email);
$password = stripslashes($password);
$email = mysql_real_escape_string(strip_tags($email));
$password = mysql_real_escape_string(strip_tags($password));
// Check occurence of email password combination
$sql="SELECT * FROM register WHERE email='$email'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $email, table row must be 1 row
if($count==1)
{
$row = mysql_fetch_array($result);
if($password == $row['password'])
{
session_start();
$_SESSION['login'] = "1";
header("location:home.html");
exit;
}
else
{
echo "Please enter correct Password";
header("location:login.html");
session_start();
$_SESSION['login'] = ''
exit();
}
}
else
{
header("Location:register.html");
exit();
}
?>
Below is the php snippet that I use at the top of my HTML page:
<?php
require_once("config.php");
session_start();
if (!(isset($_SESSION['login']) && $_SESSION['login'] != '')) {
header ("Location: login.html");
exit;
}
?>
적합합니다. 이러한 빠른 대응에 대해 Niels에게 감사드립니다. 그리고 완벽하게 작동했습니다. – user2267055