亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

會話不重定向

會話不重定向

PHP
神不在的星期二 2021-11-19 16:11:44
我有一個登錄頁面,當檢查數據庫是否存在用戶時,不會重定向到面板問題出在會話中,因為沒有它它可以正常工作if($sql->RowCount()>0){    $entrou = $_SESSION['entrou'];    header('location: painel.php');在這里我們檢查一下,如果沒有創建會話,則自動因為沒有登錄,如果沒有會話,則重定向到登錄    if (!isset($_SESSION['entrou']) == true ) {  unset($_SESSION['entrou']);  header('location: index.php');}
查看完整描述

3 回答

?
慕無忌1623718

TA貢獻1744條經驗 獲得超4個贊

如前所述,您必須在要使用會話的每個文件的開頭啟動會話。


如果要設置會話,請使用以下命令:


session_start();

$_SESSION[NAME] = VALUE;

并在檢查會話是否設置后重定向,您可以這樣做:


session_start();

if (isset($_SESSION[NAME]){

   header(‘Location: index.php‘;

}


查看完整回答
反對 回復 2021-11-19
?
小唯快跑啊

TA貢獻1863條經驗 獲得超2個贊

試一試。


// ensure to add session_start at the beginning of 

// all scripts that require use of $_SESSION[]

session_start();


if($sql->rowCount()){

    $entrou = $_SESSION['entrou'];

    header('location: panel.php');

}


if(isset($_SESSION['entrou'])){

    unset($_SESSION['entrou']);

    header('location: index.php');

}


查看完整回答
反對 回復 2021-11-19
?
一只斗牛犬

TA貢獻1784條經驗 獲得超2個贊

在這里試試這個



<?php


session_start();


...


if($sql->RowCount()>0){


   $_SESSION['entrou'] = true;

   header('location: panel.php');

}

else {

    header('location: index.php'); // "no user in the db!"

}


...


if (!isset($_SESSION['entrou']) {

    header('location: index.php');

}


?>

但當然,如果你想檢查用戶是否存在于數據庫中,你應該做這樣的事情


<?php


$data = $sql->query('SELECT * WHERE username=$_SESSION["username"]') // where "username" is the username column


if ($data == "") {

    header('location: index.php'); // user is non-existent

}

else {

    header('location: panel.php'); // the user is in the database

}

// note this only applies if you're using SQLite


查看完整回答
反對 回復 2021-11-19
  • 3 回答
  • 0 關注
  • 206 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號