我的PHP技能缺乏一点,我尝试了一段时间来解决这个问题并寻找一个没有运气的答案......并且我确信它很简单。对多个域名之间的PHP URL重定向问题
我在一个域上有一个页面,用于检查cookie是否存在,如果不存在,它会将用户发送到一个完全独立的域以输入其出生日期。一旦他们进入并超过21岁,他们将被重定向回原始域,但由于某种原因,我的脚本只捕获引用域的子目录,而不是整个事情。
<?php
function over21(){
session_start();
$redirect_url='http://xyz.com';
$validated=false;
if(!empty($_COOKIE["over21"])) { $validated=true; }
if(!$validated && isset($_SESSION['over21'])) { $validated=true; }
if($validated) { return; }
else {
$redirect_url=$redirect_url."?return=".$_SERVER['REQUEST_URI'];
header('location: '.$redirect_url);
exit(0);
}
}
over21();
?>
<html>
<head>
<title>abc.com page</title>
</head>
<body>
Before you are able to read this content, you will be redirected to xyz.com to validate your age
</body>
</html>
到目前为止好,他们现在发送到xyz.com在他们的出生日期输入:
所以,用户在一个假设的URL,abc.com访问以下网页
<?php
session_start();
if(isset($_POST['submit']))
{
$month = $_POST['month'];
$day = $_POST['day'];
$year = $_POST['year'];
$birthday = mktime(0,0,0,$month,$day,$year);
$difference = time() - $birthday;
$age = floor($difference - 662256000);
if($age >= 21)
{
setcookie("over21",$value, time()+3600*24);
$_SESSION['over21'] = 1;
$redirect=isset($_GET['return'])?urldecode($_GET['return']):'./';
header("location: ".$redirect);
exit;
}
else
{
$_SESSION['under21'] = 0;
header("location: http://google.com");
exit;
}
}
?>
<html>
<head>
<title>this is xyz.com</title>
</head>
<body>
<form>
There is a form in here with input's and such to gather day, month and year of birth.
</form>
</body>
</html>
如果我将年龄验证部分和引用页面保留在同一个域中,该脚本工作得非常好。但是,我该如何修改它,以便年龄验证页面捕获引用域的完整URL,而不仅仅是子域?
做两个网站共用一个域名?您是否熟悉[同源策略](http://en.wikipedia.org/wiki/Same_origin_policy)? – ficuscr 2013-03-26 19:10:22