2013-03-10 164 views
0

我是一名PHP初學者。我設法創建了一個用戶註冊/註冊系統,該系統導致儀表盤面板。但我無法使URL看起來像http://example.com/dashboard?username=xyz如何讓用戶使用網址儀表板登錄?username = xyz

這是我的checklogin代碼。請幫助我。

<?php 
include "config.php"; 
session_start(); 

if(!empty($_SESSION['LoggedIn']) && !empty($_SESSION['Username'])) 
{ 


echo "<script>location.href='logindo.php?success=yes'</script>"; 


} 
elseif(!empty($_POST['username']) && !empty($_POST['password'])) 
{ 
$username = mysql_real_escape_string($_POST['username']); 
$password = md5(mysql_real_escape_string($_POST['password'])); 

$checklogin = mysql_query("SELECT * FROM users WHERE Username = '".$username."' AND password = '".$password."'"); 

if(mysql_num_rows($checklogin) == 1) 
{ 
    $row = mysql_fetch_array($checklogin); 
    $email = $row['EmailAddress']; 

    $_SESSION['Username'] = $username; 
    $_SESSION['EmailAddress'] = $email; 
    $_SESSION['LoggedIn'] = 1; 

    echo "<h1>Success</h1>"; 
    echo "<p>We are now redirecting you to the member area.</p>"; 
    echo "<script>location.href='logindo.php?success=yes'</script>"; 
    } 



     else 
     { 

      echo "<script>location.href='logindo.php?error=yes'</script>"; 
     } 
    } 


    else 
    { 
} 
    ?> 
    <?php if($_GET['error'] == 'yes') 
     { 
     echo "<h1>Error</h1>"; 
    echo "<p>Sorry, your account could not be found. Please <a href=\"user_login.php\">click here to try again</a>.</p>"; 
     } 
     ?> 

     <?php if($_GET['success'] == 'yes') 
     { 


    header('Location: /im/dashboard/'); 
     } 
     ?> 


<?php if($_GET['error1'] == 'yes') 
     { 
     echo "<h1>Error</h1>"; 
    echo "<p>Sorry, one ore more required fields were left empty. Please <a href=\"user_login.php\">click here to try again</a>.</p>"; 
     } 
     ?> 
+1

請注意,不建議使用mysql_ *'函數(請參閱[紅盒子](http://php.net/mysql_query))。 – 2013-03-10 18:50:07

+2

散列之前的SQL轉義數據** ** **。 – ThiefMaster 2013-03-10 18:50:38

+0

你能否給我提供正確的方法?或任何教程正確方法的教程鏈接? thnx – 2013-03-10 18:51:58

回答

-1

爲了使用「儀表板?......」作爲您的網址,你需要使用一個名爲友好的URL方法。這很簡單,但你需要訪問你的apache設置。看看這個答案mod_rewrite幫助:apache-mod-rewrite-friendly-urls-with-corresponding-301-redirects

這將讓你知道這是如何工作的。我也發現有些時候,你也必須在apache中使用ForceType聲明。快速谷歌搜索將有助於這一點,誰知道,你可能不需要它!先刷上mod_rewrite,看看會發生什麼! HTH!

+0

重寫網址對於接受簡單的GET參數不是必需的。 – Repox 2013-03-10 19:38:54

相關問題