$ _session不使用session_start();叫

时间:2016-12-25 22:39:06

标签: php session

$ _ Session之前曾在我的网站上工作,但现在它无效。 这就是我所说的。

<?php session_start();

echo $_SESSION['a']; 
?>
<!DOCTYPE html>

<html>

<head>

    <title>Ajouter Liste</title>

    <meta charset="utf-8" />
</head>

<body>

这是我设置会话变量的地方,我无法使其工作。

<?php
session_start();
header('Access-Control-Allow-Origin: *');
include 'connect.php';

$pseudo = htmlspecialchars($_POST['pseudo']);
$mail = htmlspecialchars($_POST['mail']);
$password = htmlspecialchars($_POST['password']);
$password = sha1($password);

$pseudo1 = htmlspecialchars($_POST['pseudo1']);
$password1 = htmlspecialchars($_POST['password1']);
$password1 = sha1($password1);
$action = $_POST['action'];

if ($action == "register")
{
$rep = $bdd->prepare('INSERT INTO login (pseudo, mail, password) VALUES(:pseudo, :mail, :password)');
$rep->execute(array(

    'pseudo' => $pseudo,
    'mail' => $mail,
    'password' => $password));
}

if ($action == "login")
{
$rep = $bdd->prepare('SELECT * FROM login WHERE pseudo = :pseudo AND password = :password');
$rep->execute(array(

    'pseudo' => $pseudo1,
    'password' => $password1));
$req = $rep->fetch();
if (isset($req['pseudo']))
{
$arr = array('response' => 'gg');

echo json_encode($arr);

$_SESSION['a'] = "test";

}
else
{
$arr = array('response' => 'fail');

echo json_encode($arr);
}

}
 ?>

上面的代码运行得非常好,但是当我转到第一页时,我可以获得$ _SESSION [&#39; a&#39;]。

phpinfo() 谢谢你的帮助。

0 个答案:

没有答案