在php中,用户在页面刷新时注销
WebPage.php在php中,用户在页面刷新时注销,php,login-script,Php,Login Script,WebPage.php <?php session_start(); include 'functions.php'; ?> <html> <head> <title>Ecommerce</title> <link rel="stylesheet" href="Styling.css"> </head> <body onLoad="CheckLogin()">
<?php
session_start();
include 'functions.php';
?>
<html>
<head>
<title>Ecommerce</title>
<link rel="stylesheet" href="Styling.css">
</head>
<body onLoad="CheckLogin()">
<script>
function CheckLogin(){
var loggedIn = "<?php
if(isset($_SESSION['email'])){
echo 'true';
}else{
echo 'false';
} ?>"
var logout_Form = document.getElementById("logout_Form");
var login_Form = document.getElementById("login_Form");
if(loggedIn == "true"){
login_Form.style.display="none";
logout_Form.style.display = "show";
}else{
logout_Form.style.display="none";
login_Form.style.display = "show";
}
}
function LogOut(){
<?php
session_destroy();
?>
window.open('WebPage.php', '_self');
}
function Login()
{
var modal = document.getElementById('loginModal');
var btn = document.getElementById("login");
var span = document.getElementsByClassName("close")[0];
modal.style.display = "block";
span.onclick = function() {
modal.style.display = "none";
}
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
}
function SignUp()
{
var modal = document.getElementById('signModal');
var btn = document.getElementById("signUp");
var span = document.getElementsByClassName("close2")[0];
modal.style.display = "block";
span.onclick = function() {
modal.style.display = "none";
}
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
}
</script>
<div style = "background:cyan">
<font color="green"><h1><center>WELCOME</center></h1></font>
<div>
<!--Logo and Search Box-->
<form method="GET" action = "results.php">
<a href="WebPage.php"><img src = "ball.png" alt = "Logo of Website" height = "100px" width = "100px"></a>
<input type = "text" name = "user_query" placeholder="Search" size="50px" style="overflow:hidden">
<button type="Submit" name="search">Search</button>
</form>
<!--LOGIN-->
<div id="login_Form">
<button id = "login" onclick="Login()">Login</button>
<button id="signUp" onclick="SignUp()">Sign Up</button>
<div id="loginModal" class="loginModal">
<!-- Modal content -->
<div class="login-content">
<span class="close">×</span>
<p><h2>Login</h2>
<form name="login" method="POST" id="login" action="loginCheckUser.php">
<label><b>E-Mail ID: </b></label>
<input type="email" name="email" required>
<br><br>
<label><b>Password: </b></label>
<input type="password" name="pass" required>
<br><br>
<button type="submit" id="submit" name="submit">Login</button>
<a href="loginCheckSell.php"><input type="button" id="sellerLogin" value="Login as Seller"></a>
<br><br>
<input type="checkbox" checked>Remember Me
</form></p>
</div>
</div>
<div id="signModal" class="signModal">
<!-- Modal content -->
<div class="signUp-content">
<span class="close2">×</span>
<p><h2>Sign Up</h2>
<form name="signup" action="register.php" method="POST" id="signup">
<label><b>Name: </b></label>
<input type="text" name="name" required>
<br><br>
<label><b>E-Mail ID: </b></label>
<input type="email" name="email" required>
<br><br>
<label><b>Password: </b></label>
<input type="password" name="pass" required>
<br><br>
<label><b>Confirm Password: </b></label>
<input type="password" name="con_pass" required>
<br><br>
<label><b>Mobile No: </b></label>
<input type="tel" id="phoneno" name="phone" required>
<br><br>
<button type="submit" id="submit" name="submit">Register</button>
<a href="regSell.php"><button type="submit" id="subSell" name="subSell">Register as Seller</button></a>
</form></p>
</div>
</div>
</div>
<div id="logout_Form">
<div class="dropdown">
<button class="dropbtn"> <?php
echo "Hi ";
if(isset($_SESSION['email'])){
echo getName($_SESSION['email']);
}
?></button>
<div class="dropdown-content">
<a href="myAccount.php?account=a&personal=p">Account</a>
<a href="myAccount.php?orders">Orders</a>
</div>
</div>
<button name="logout" id="logout" onclick="LogOut()">Log Out</button>
</div>
</div>
</div>
<!--Categories-->
<div>
<ul id="searchMenu">
<li>
<a href="#" title="Electronics">Electronics</a></li>
           
<li>
<a href="#" title="Appliances">Appliances</a></li>
           
<li>
<a href="#" title = "Men">Men</a></li>
           
<li>
<a href="#" title="Women">Women</a></li>
</ul>
</div>
<div id="content_area">
<?php cart();?>
<div id="shopping_cart">
<span style = "float: right; font-size: 18px; padding: 5px, line-height:40px;">
Welcome <b style="color:yellow">Shopping Cart: </b>Total Items: <?php total_items();?> - Total Price: <?php total_price();?><a href="cart.php">Go to Cart</a>
</span>
</div>
<?php
$ip = getIp();
?>
<div id="products_box">
<?php
get_pro();
getCatPro();
getBrandPro();
?>
</div>
</div>
<!--Company Info-->
<div>
<ul id="CompInfo" >
<li style="background-color:red"><a href="WebPage.php">Home</a></li>
<li style="background-color:red"><a href="#">About Us</a></li>
<li style="background-color:red"><a href="#">Contact</a></li>
</ul>
</div>
</body>
</html>
电子商务
函数CheckLogin(){
var loggedIn=“”
var logout_Form=document.getElementById(“logout_Form”);
var login_Form=document.getElementById(“login_Form”);
如果(loggedIn==“真”){
登录\ u Form.style.display=“无”;
注销\u Form.style.display=“显示”;
}否则{
注销\u Form.style.display=“无”;
登录\ u Form.style.display=“show”;
}
}
函数注销(){
open('WebPage.php','u self');
}
函数登录()
{
var modal=document.getElementById('loginModal');
var btn=document.getElementById(“登录”);
var span=document.getElementsByClassName(“关闭”)[0];
modal.style.display=“块”;
span.onclick=函数(){
modal.style.display=“无”;
}
window.onclick=函数(事件){
如果(event.target==模态){
modal.style.display=“无”;
}
}
}
函数注册()
{
var modal=document.getElementById('signModal');
var btn=document.getElementById(“注册”);
var span=document.getElementsByClassName(“close2”)[0];
modal.style.display=“块”;
span.onclick=函数(){
modal.style.display=“无”;
}
window.onclick=函数(事件){
如果(event.target==模态){
modal.style.display=“无”;
}
}
}
欢迎
搜寻
登录
注册
&时代;
登录
电子邮件ID:
密码:
登录
记得我吗
&时代;
报名
姓名:
电子邮件ID:
密码:
确认密码:
手机号码:
登记
注销
-
   
-
   
-
   
-
欢迎购物车:共有商品:-总价:
模态内容提供了一个弹出窗口。
我一刷新页面,注销按钮就消失了,还有登录按钮。但我希望该网站的状态与刷新前相同。只有1个可以是登录表单或注销表单
loginCheckUser.php
<?php session_start();?>
<html><head>
</head>
<body>
<script>
var lat =0 ;
var lon =0 ;
function getLocation() {
navigator.geolocation.getCurrentPosition(showPosition);
}
function showPosition(position) {
document.getElementById("lat").value = position.coords.latitude;
document.getElementById("lon").value = position.coords.longitude;
document.getElementById("check").value= "true";
document.getElementById("form").submit();
}
</script>
<form id="form" method="post">
<input type="hidden" id="lat" name="lat">
<input type="hidden" id="lon" name="lon">
<input type="hidden" id="check" value="">
</form>
<?php
include 'functions.php';
$email =$_POST['email'];
$pass =$_POST['pass'];
if($email && $pass){
$connect = mysqli_connect('localhost', 'root', '','test') or die("Couldn't connect to database");
$ip = getIp();
$query = mysqli_query($connect, "SELECT * FROM users WHERE email = '$email'") or die("NO query");
$numrows = mysqli_num_rows($query);
if($numrows >=1){
while($row = mysqli_fetch_assoc($query)){
$dbemail = $row['email'];
$dbpass = $row['pass'];
}
if($email == $dbemail && md5($pass) == $dbpass){
echo '<script>
getLocation();
</script>';
$latitude = $_POST['lat'];
$longitude = $_POST['lon'];
$check =$_POST['check'];
if($check=='true'){
$sql1 = "UPDATE users SET lat = '$latitude', lon = '$longitude' where email = '$email'";
mysqli_query($connect, $sql1);
}
$name="";
$q = mysqli_query($connect, "SELECT name FROM users where email = '$email'") or die("cannot get");
while($row = mysqli_fetch_assoc($q)){
$name = $row['name'];
}
$_SESSION['email'] = $email;
header("location: WebPage.php");
}else{
echo "<script type='text/javascript'>alert('Your password is incorrect');</script>";
header("location: WebPage.php");
}
}
else{
echo "<script type='text/javascript'>alert('The user Doesn't exist');</script>";
header("location: WebPage.php");
}
}
?> </body></html>
var-lat=0;
var-lon=0;
函数getLocation(){
navigator.geolocation.getCurrentPosition(showPosition);
}
功能显示位置(位置){
document.getElementById(“lat”).value=position.coords.latitude;
document.getElementById(“lon”).value=position.coords.longitude;
document.getElementById(“check”).value=“true”;
document.getElementById(“表单”).submit();
}
删除此处的条件:
if (!isset($_SESSION)) {
session_start();
}
拥有会话\u start()
的主要原因是为了设置会话。在此之前,$\u会话
将为空,并且该会话永远不会被设置。并确保,session\u start()
始终位于顶部,因为它类似于header()
函数。删除此处的条件:
if (!isset($_SESSION)) {
session_start();
}
拥有会话\u start()
的主要原因是为了设置会话。在此之前,$\u会话
将为空,并且该会话永远不会被设置。首先,要确保session\u start()
始终位于顶部,因为它类似于header()
函数。您必须在每个页面上启动会话
改变
if (!isset($_SESSION)) {
session_start();
}
到
使会话启动()
是在使用$\u会话的每个页面上调用的第一件事。另外,确保在之前没有空格或制表符,您必须在每个要使用会话的页面开始会话
改变
if (!isset($_SESSION)) {
session_start();
}
到
使会话启动()
是在使用$\u会话的每个页面上调用的第一件事。另外,在输出任何HTML之前,确保在session\u start()前面没有空格或制表符。
应该在最上面。不要把js和php混合得太厉害。您也可以在php中执行登录/注销功能。你的代码太复杂了,读起来很糟糕。@Alex Wiebogen。很抱歉给你添麻烦。但是我不知道如何在html中获得纬度和经度。这就是为什么我需要同时包含js和php的原因。session\u start()
应该在最上面,然后再输出任何HTML。不要把js和php混为一谈。您也可以在php中执行登录/注销功能。你的代码太复杂了,读起来很糟糕。@Alex Wiebogen。很抱歉给你添麻烦。但是我不知道如何在html中获得纬度和经度。这就是为什么我需要同时包含js和php。很抱歉,问题仍然存在。这是fir