這是我的問題,我第一次使用jquery mobile(學生web開發人員)製作一個web應用程序。所以我需要做一個登錄頁面,然後開始一個會話。但我不知道該怎麼做。它只能使用PHP會話(因爲我知道如何使用PHP只能..)?或者我真的需要以另一種方式去做嗎?
這是我做的:在jquery mobile上開始會話,沒有ajax
<?php
include 'fonctions.php';
if (isset($_POST['valider'])){
if ((isset($_POST['ident']) && !empty($_POST['ident']))
&& (isset($_POST['psw']) && !empty($_POST['psw']))) {
// récupération des infos de connex
$identifiant=$_POST['ident'];
$psw=$_POST['psw'];
if(connectionIdent($identifiant,$psw) ===true){
session_start();
$_SESSION['id'] = $identifiant;
$_SESSION['psw'] = hash("sha256",$psw);
header ('Refresh:0; URL= http://localhost/acces.php#radio');
}else{
Echo 'Identifiant ou mot de passe incorrects';
header ('Refresh :3; URL=http://localhost/acces.php#connexion');
}
}
}
?>
我的着陸頁:
<?php
if (isset($_SESSION['id']) && isset($_SESSION['psw'])){
echo 'Votre login est '.$_SESSION['login'].' et votre mot de passe est '.$_SESSION['pwd'].'.';
?>
<div data-role="page" id="radioSansCo">
<div data-role="main" class="ui-content">
<div data-role="panel" class="sidenav" id="mypanel" data-display="overlay" data-position="left" >
<a href="#" class="buttonnav" id="liennav">Forum</a>
<a href="#" class="buttonnav" id="liennav">Bon plans</a>
<a href="#" class="buttonnav" id="liennav">Actualités</a>
<a href="#" class="buttonnav" id="liennav">Deconnexion</a>
</div>
<a href="#mypanel"><span id="sandwich">☰</span> </a>
<img src="images/logo.png" alt="Logo" id="logocentral">
</div>
</div>
<?php
}
?>
在JS中沒有「會話」這樣的事情。但是你可以使用['localStorage'](https://developer.mozilla.org/en/docs/Web/API/Window/localStorage)在客戶端存儲一些數據。 **不要用它來存儲用戶密碼**,因爲這不安全。正如你發佈的那樣,你的PHP方式是正確的。 –