我有登录表单(HTML ),我通常使用PHP创建登录表单,并使用会话变量,但是现在我必须只在clien端使用HTML,而PHP只能在服务器端使用。现在,我很困惑如何读取会话变量在HTML中的第二或登陆表单后登录。这是我的密码
index.html
<script>
$(document)
.ready(function() {
$("#SAVE").on('click', function(){
var EMAIL = $("#EMAIL").val();
var PASS = $("#PASS").val();
//alert(EMAIL);
//alert(PASS);
$.post("index-action.php", {email: EMAIL, pass: PASS}, function(datane) {
//$( ".result" ).html( datane );
if(datane == "sukses"){
alert('Login berhasil ');
location.href = '/buku/utama.html';
}
else{
alert('Input Gagal');
}///end if
});//end post
});//end save
})
;
</script>
<body>
<div class="ui middle aligned center aligned grid">
<div class="column">
<h2 class="ui teal image header">
<img src="./login_files/logo.png" class="image">
<div class="content">
Log-in Crud Master
</div>
</h2>
<form class="ui large form" id="LOGIN">
<div class="ui stacked segment">
<div class="field">
<div class="ui left icon input">
<i class="user icon"></i>
<input type="text" name="email" id="EMAIL" placeholder="E-mail address">
</div>
</div>
<div class="field">
<div class="ui left icon input">
<i class="lock icon"></i>
<input type="password" name="password" id="PASS" placeholder="Password">
</div>
</div>
<div class="ui fluid large teal submit button" type="submit" id="SAVE">Login</div>
</div>
<div class="ui error message"></div>
</form>
<div class="ui message">
New to us? <a href="https://semantic-ui.com/examples/login.html#">Sign Up</a>
</div>
</div>
</div>
</body>以及在操作表单/服务器端的index-action.php
<?php
session_start();
include "koneksi.php";
$email = $_POST['email'];
$pass = $_POST['pass'];
$sql = "SELECT * FROM user where email = '$email' and pass = '$pass'";
$hasil = mysqli_query($mysqli, $sql);
$data = mysqli_fetch_assoc($hasil);
if($data['ID']){
$_SESSION['user'] = $data['user'];
$_SESSION['hak'] = $data['hak'];
}
if ($hasil) {
echo "sukses";
} else {
echo "input gagalx";
}
?>好的,代码工作得很好,登录后我可以去utama.html,但我的问题是,如何获得
$_SESSION‘’user‘;
$_
在utama.html文件中。我知道我不能在HTML中使用PHP?
有人能帮我解决这个问题吗?
我非常感谢你的回答。
谢谢
发布于 2019-10-30 04:39:58
要在ja文件中读取任何类型的php变量,您需要以json编码格式发送这些变量。然后,将该值保存在js文件中,并将其分配给cookie。这样您就可以轻松地跟踪登录的用户。注意:您必须在js中设置cookie。
如果您有任何疑问,请告诉我。
发布于 2019-10-30 06:44:51
好的,
我知道另一种选择,我在Javascript中使用了localStorage函数,所以我可以像使用会话一样使用它。
谢谢
https://stackoverflow.com/questions/58618354
复制相似问题