我的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,而不仅仅是子域?
答案 0 :(得分:0)
所以,忽略我认为的相同来源注释,只是看到会话开始代码让我觉得你试图跨域共享会话。
您只是在询问$_SERVER variables我看到了什么。
'REQUEST_URI' - 为了访问此页面而给出的URI;例如,'/ index.html'。
尝试使用HTTP_HOST
之类的内容。