标题位置重定向不起作用

时间:2014-05-26 18:51:09

标签: php redirect

我有一个登录页面,登录成功后我会重定向到用户来自的页面或index.php。这很好用,直到我实现ajax登录。问题是成功登录后页面重定向到同一页面而不是索引。它只是重定向到那里并显示login.php

中的index.php页面

网址看起来像localhost/login.php?/index.php

JS

$('.login').on('click', function() { 
var user = $('.username').val();
var pass = $('.password').val();
ref;//redirect url
$.ajax({
type: "GET",
url: "process.php",
data: {req: 'req', user: user, pass:pass, ref:ref},
cache: false,
success: function(response)
{  
}
});

});

process.php我从js获取每个值,但重定向不起作用。有什么想法吗?

if(isset(_GET['req'])){ 
if(empty($_GET['user'])){
echo "uname empty";
}
else if(empty($_GET['pass'])){
echo "pass empty";
}
else{
if(...){
//some validations
}
else{
//everything good...redirect to index.php or user's page
 $page = $_GET['ref'];
if(!empty($page)){     
//Redirect to the page where user came from
header("location: ".$page);
}
else{header("location:index.php");}
}
}
}

1 个答案:

答案 0 :(得分:0)

喜欢这个

$page = $_GET['ref'];
if(!empty($page)){     
//Redirect to the page where user came from
echo $page;
}
else{echo 'index.php';}
}

和ajax回复

success: function(response)
{  
  location.href='/'+response;
}