2013-10-16 37 views
1

即時嘗試重定向嘗試頁如果用戶填寫不正確的信息... 另一方面,如果嘗試頁得到刷新,希望它被重定向登錄頁... 即時通訊使用會話爲...重定向如果會話不存在

if (isset($c)) 
{ 
    $q = mysql_query("select * from registeration where email='$a' and password='$b'"); 
    $r = mysql_num_rows($q); 

    if($r) 
    { 
     $_SESSION["Authenticated"] = 1; 
     $_SESSION['id'] = $a; 
    } 
    else 
    { 
     $_SESSION["Authenticated"] = 0; 
     $_SESSION["att"] = 1; 
    } 

    if(isset($_SESSION["att"])) 
    { 
     header("location:attempt1.php"); 
    } 
    else 
    { 
     session_write_close(); 
     header('location:profile.php'); 
    } 
} 

上述代碼被重定向上attempt1.php 但代碼上attempt1.php回重定向到index.php

session_start(); 
if (!isset($_SESSION["att"])) 
{ 
    echo "<meta http-equiv=\"refresh\" content=\"0; url=index.php\">"; 
} 

我想attempt1.php代碼重定向在用戶o上ň的index.php如果會議沒有設置.. 並刷新或直接頁面加載... 所以破壞會議 請朋友們有所幫助索引頁直接訪問這個頁面的結果重定向..

ANSWERANSWERANSWER 所有我問我做出愚蠢的錯誤問題... 在這裏這個問題,我還沒有開始會話欺騙存儲會話變量.... 添加下面的代碼在第一行的登錄腳本

session_start(); 

回答

1

我覺得你問如果會話不存在重定向,因爲會話需要一個ID,你應該能夠檢查針對:

if(!(session_id()) header("Location: /mypage.php"); 
+0

嘿馬修,我真的需要一個session_id當我有會話名稱... – user2881430

+0

會話ID是自動創建的,它是將用戶與服務器上存儲的內容綁定在一起的ID。無論是在cookie中還是通過URL。 –

+0

hmmm ohk,thanx爲rply ... – user2881430

6
//try this code 
<?php 
session_start(); 
    if (!isset($_SESSION["att"])) 
    { 
     header("location: index.php"); 
    } 
?> 
+0

已經試過...同樣的問題 – user2881430

1

試試這個:

if(empty($_SESSION)) 
{ 
    header("Location: /mypage.php"); 
} 
else 
{ 
    // do something .... 
} 

- 感謝