经过大量搜索以及反复试验,我难住了。重定向不允许我访问实际站点的代码有什么问题?我无法获取年龄输入以将我引导至主站点或 index.php。如果答案错误,无论输入的日期如何,都会重定向到用户会去的地方——在这种情况下是 youtube。
这是我在本地工作的 index.php 中的内容:
<?php
@session_start();
$url = 'http://localhost/J2.5/index.php';
if (!isset($_COOKIE['Visited'])) {
$_COOKIE['Visited'] = 1;
$url = 'http://localhost/J2.5/ageverificationone.php';
}
header("Location: {$url}");
?>
该部分非常适合弹出年龄验证脚本所在的实际页面-ageverificationone.php(可以是任何名称..尝试了很多变体):
<?php
session_start();
if($_SERVER['REQUEST_METHOD']=='POST')
{
if(isset($_POST['YES']))
{
$redirect=isset($_GET['return'])?urldecode($_GET['return']):'./';
$expire=isset($_GET['x']) && is_numeric($_GET['x'])?intval($_GET['x']):-1;
if($expire==-1)
{
$_SESSION['verified']="yes";
header("location: ".$redirect);
exit(0);
}
if($expire==0)
{
setcookie("verified", "yes",mktime(0,0,0,01,01,date("Y")+30));
$_SESSION['verified']="yes";
header("location: ".$redirect);
exit(0);
}
setcookie("verified", "yes",(time()+$expire));
$_SESSION['verified']="yes";
header("location: http://www.superiorvaping.com/");
exit(0);
}else{
header("location: http://www.youtube.com/watch?v=gppbrYIcR80");
exit(0);
}
}
?>
<html>
<head>
<title>Age Verification</title>
<script language=Javascript>
<!--
function isNumberKey(evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode != 46 && charCode > 31 && (charCode < 48 || charCode > 57))
return false;
return true;
}
//-->
</script>
<script type="text/javascript">
function jumpField(elmnt,content)
{
if (content.length==elmnt.maxLength)
{
next=elmnt.tabIndex
if (next<document.forms[0].elements.length)
{
document.forms[0].elements[next].focus()
}
}
}
</script>
<script src="http://cdn.jquerytools.org/1.2.5/full/jquery.tools.min.js"></script>
<script src="js/fade.js" type="text/javascript"></script>
<link href="js/ageverify.css" type="text/css" rel="stylesheet" />
</head>
<body id="body" OnLoad="document.ageVerifyForm.month.focus();">
<img src="images/logoVerify.png" alt="Superior Vaping" id="logoVerify" /><br />
<p id="welcome">Welcome! Please enter your date of birth.</p>
<form id="ageVerifyForm" name="ageVerifyForm" action="" method="POST" onsubmit="return formCheck(this);">
<input type="text" tabindex="1" onkeypress="return isNumberKey(event)" onkeyup="jumpField(this,this.value)" id="month" name="month" maxlength="2" size="2" required="required" value="MM" onfocus="value=''" />
<input type="text" tabindex="2" onkeypress="return isNumberKey(event)" onkeyup="jumpField(this,this.value)" id="day" name="day" maxlength="2" size="2" required="required" value="DD" onfocus="value=''" />
<input type="text" tabindex="3" onkeypress="return isNumberKey(event)" onkeyup="jumpField(this,this.value)" id="year" name="year" maxlength="4" size="4" required="required" value="YYYY" onfocus="value=''" />
<br />
<input type="submit" value="Enter Superior Vaping" id="submit" name="submit" />
</form>
<script language="JavaScript">
<!--
function formCheck(formobj){
// Enter name of mandatory fields
var fieldRequired = Array("month", "day", "year");
// Enter field description to appear in the dialog box
var fieldDescription = Array("month", "day", "year");
// dialog message
var alertMsg = "Please complete the following fields:\n";
var l_Msg = alertMsg.length;
for (var i = 0; i < fieldRequired.length; i++){
var obj = formobj.elements[fieldRequired[i]];
if (obj){
switch(obj.type){
case "select-one":
if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
alertMsg += " - " + fieldDescription[i] + "\n";
}
break;
case "select-multiple":
if (obj.selectedIndex == -1){
alertMsg += " - " + fieldDescription[i] + "\n";
}
break;
case "text":
case "textarea":
if (obj.value == "" || obj.value == null){
alertMsg += " - " + fieldDescription[i] + "\n";
}
break;
default:
}
if (obj.type == undefined){
var blnchecked = false;
for (var j = 0; j < obj.length; j++){
if (obj[j].checked){
blnchecked = true;
}
}
}
}
}
if (alertMsg.length == l_Msg){
return true;
}else{
document.getElementById("error").innerHTML="All Fields Must be Filled out";
return false;
}
}
// -->
</script>
</body>
</html>
我在 Joomla 基础中使用它。这是几个脚本拼凑在一起,至少可以发挥它的作用。如前所述,缺少最后一步 - 使用 cookie 获得正确的重定向,因此用户只能获得一次年龄验证,并且无论进入页面如何,它都会出现。这是针对电子烟网站的,他们要求进行年龄验证。
我正在使用 WAMP 作为开发基础在本地执行此操作。
谢谢托马斯