请教:php中验证用户名和密码正确后,如何实现跳转?

js代码:

 function signin() {
    var name = $('#name').val();
    var password = $('#password').val();
    dataVal = {
        username: name,
        userpassword: password
    };
    $.ajax({
        url: 'verifyOld.php',
        type: 'GET',
        data: dataVal,
        success: function(msg) {
            alert(msg);
        }
    });
}

PHP代码:

 <?php
$username = $_GET['username'];
$userpassword = $_GET['userpassword'];
$link = mysqli_connect("localhost","root","1009976636",'blog');
if(!$link)
{
    $output = 'Unable to connect to the database server.';
    echo $output;
    exit();
}
if(!mysqli_set_charset($link,'utf8'))
{
    $output = 'Unable to set database connection encoding.';
    echo $output;
    exit();
}
$sql = ("select password from user where username = '$username'");
$result = mysqli_query($link, $sql);
if (mysqli_num_rows($result) > 0) {
    if($userpassword == mysqli_fetch_assoc($result)["password"])
    {
//    $url = 'homepage.html';
//      header("Location: $url");
//      echo "login successuflly";
//      if(isset($url)) 
//      { 
//          header('Location:'.$url); 
//          exit();
//      } 
//      $url = "homepage.html"; 
//      echo "<script language='javascript' type='text/javascript'>"; 
//      echo "window.location.href='$url'"; 
//      echo "</script>"; 
    }
    else
        echo "The username and/or password you specified are not correct.";
}

else {
    echo "The username does not exist!";
}

?>

还望大神不吝赐教。

跳转需要在javascript里做

 <?php
$username = $_GET['username'];
$userpassword = $_GET['userpassword'];

header('Content-Type: application/json');

$link = mysqli_connect("localhost","root","1009976636",'blog');
if(!$link)
{

     $output = 'Unable to connect to the database server.';
   echo json_encode(array('status' => 'error','message'=> $output);
    exit();
}
if(!mysqli_set_charset($link,'utf8'))
{
    $output = 'Unable to set database connection encoding.';
        echo json_encode(array('status' => 'error','message'=> $output);
    exit();
}
$sql = ("select password from user where username = '$username'");
$result = mysqli_query($link, $sql);
if (mysqli_num_rows($result) > 0) {
    if($userpassword == mysqli_fetch_assoc($result)["password"])
    {
     $url = '/homepage.html';
         echo json_encode(array('status' => 'ok','message'=> $url);
    }
    else
        echo json_encode(array('status' => 'error','message'=>  'The username and/or password you specified are not correct.';
}

else {
    echo json_encode(array('status' => 'error','message'=> 'The username does not exist!');
}

?> 
function signin() {
    var name = $('#name').val();
    var password = $('#password').val();
    dataVal = {
        username: name,
        userpassword: password
    };
    $.ajax({
        url: 'verifyOld.php',
        type: 'GET',
        data: dataVal,
        success: function(msg) {
                    if(msg.status == 'ok') {
                          window.location = msg.message
                        }else{
              alert(msg.message);
                        }
        }
    });
} 

http://blog.csdn.net/sysprogram/article/details/21107041

成功后后台给个返回码,根据状态来跳转