2017-02-25 28 views
0

如何讓用戶註冊後重定向到不同的頁面。我用盡大部分的東西,是它註冊不錯,但我只是用這一個位d掙扎:正在註冊的用戶重定向到不同的頁面PHP

regsister.inc.php

<?php 
//Start session: 
session_start(); 

//Include db settings and create a connection: 
include("config.inc.php"); 

//Create variable for username input and prevent sql injections: 
$username = mysql_real_escape_string($_POST['usern2']); 
//Create variable for password input, prevent sql injections and hash it with md5: 
$password = mysql_real_escape_string(md5($_POST['pass2'])); 

//Select matching username and password from admin table based on input: 
$sql = "INSERT INTO admin VALUES('$username', md5('$password'))"; 
//$sql = "SELECT * FROM admin WHERE username = '$username' AND password = '$password'"; 
//Execute query to db: 
$execute = mysql_query($sql); 

if (mysql_num_rows($execute) == 1) { 
    $_SESSION['user'] = $username; 
    echo "<p>Register Successful</p>"; 

} 

register.php

<?php 
include ("includes/register.inc.php"); 
    ?> 
<!DOCTYPE html> 

<html> 
    <head> 
     <meta charset="utf-8"> 
     <link href="https://fonts.googleapis.com/css?family=Ubuntu" rel="stylesheet"> 
     <meta name="viewport" content="width=device-width, initial-scale=1.0"> 

     <link href="css/style.css" rel="stylesheet"> 
    </head> 
    <body> 

     <div id="container"> 

      <?php echo $errormsg; ?> 

      <h2>Register</h2> 

      <form method="post" action="register.php"> 
       <label>Username: </label> 
       <input type="text" size="25" name="usern2" value=""><br> 
       <label>Password: </label> 
       <input type="password" size="25" name="pass2" value=""><br> 
       <input type="submit" value="Register!"> 
      </form> 

     </div> 

    </body> 
</html> 

太大的幫助會讚賞,不要烤我即時新的PHP D:

+1

的可能的複製[如何使PHP中的重定向?](http://stackoverflow.com/questions/768431/how-to-make-a-redirect-in-php) –

+0

但IDK的地方把它放在代碼 – n0b0y

+0

如果條件如果(mysql_num_rows($ execute)== 1){// here} –

回答

0

header()用於發送原始的HTTP/1.1規範特定的標頭。必須在發送任何實際輸出之前調用header()

if (mysql_num_rows($execute) == 1) { 
    $_SESSION['user'] = $username; 

    /* Redirect browser */ 
    header("Location: http://example.com/myOtherPage.php"); 

    /* Make sure that code below does not get executed when we redirect. */ 
    die(); 
} 
+0

仍然沒有工作:/ – n0b0y

+0

你可以給我發送代碼嗎? –

+0

什麼代碼?還有Skype? – n0b0y

相關問題