我的 PHP 技能有点欠缺,我已经尝试了一段时间的故障排除并寻找没有运气的答案......我相信这很简单。
我在一个域上有一个页面,它正在检查是否存在 cookie,如果不存在,它会将用户发送到一个完全独立的域以输入他们的出生日期。一旦他们输入并超过 21 岁,他们将被重定向回原始域,但由于某种原因,我的脚本仅捕获引用域的子目录,而不是整个内容。
因此,用户通过假设的 URL abc.com 访问以下页面:
<?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 以输入他们的出生日期:
<?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,而不仅仅是子域?