只能通过另一个php页面访问php页面

只能通过另一个php页面访问php页面,php,security,Php,Security,我期待着开发一个包含阶段的网站。例如,我只想在点击第1阶段页面中的finish按钮时通过第2阶段,这样只有当用户通过另一个页面时,第2阶段页面才能通过其url或其他方式访问 有没有办法做到这一点???我是安全方面的初学者,请尝试帮助我,提前感谢编码人员利用开发此模型 index.php <?php @extract($_POST); if(isset($sub)) { session_start(); $_SESSION['authenticate']=true; header("

我期待着开发一个包含阶段的网站。例如,我只想在点击第1阶段页面中的finish按钮时通过第2阶段,这样只有当用户通过另一个页面时,第2阶段页面才能通过其url或其他方式访问

有没有办法做到这一点???我是安全方面的初学者,请尝试帮助我,提前感谢编码人员利用开发此模型

index.php

<?php
@extract($_POST);
if(isset($sub))
{
session_start();
$_SESSION['authenticate']=true;
    header("location:test1.php");
    exit;
}
?>
<form action='' method="post">

    <input type="SUBMIT" name="sub" value="Finish" />

</form>
<?php
session_start();
if(!isset($_SESSION['authenticate']))
{
    echo "You are not allowed to access";
}
else { echo "You came from index.php ! so you are a valid user"; }
session_destroy(); //<-- I added this so you can test your example multiple times.
我想,这场演出很成功:)

使用可以直接将用户从index.php重定向到open.php

header('Location : open.php');
或者, 在open.php中,将

if($_SERVER['HTTP_REFERER'] == 'index.php page's full link') {
  //Do or Show whatever you want to show here
} else {
  // Tell the user that you are not authorized
}
如果这不起作用,请echo$\u服务器['HTTP\u REFERER'],并查看它提供给您的链接。并将链接放在上面指定的位置

酷?:)

编辑(根据评论)--

假设在stage1.php中有一个表单

<form method="post" action="">
<span class="error"><?php echo $error; ?></span>
Name: <input type="text" name="name"><br/>
Email: <input type="text" name="email"><br/>
<input type="submit" name="submit" value="Submit">
</form>
if (isset($_POST['name'])||isset($_POST['email'])) {
    if (!empty($_POST["name"])||!empty($_POST["email"])) {
        $error = "Please fill in all the fields correctly";
    }
    else {
        $name = $_POST['name'];
        $email = $_POST['email'];
        //You can also save the above Variables Globally by $GLOBALS['name'] = $_POST['name'];
        //So that you can use the details when you reach the final stage
        header('Location : stage2 page's link');
    }   
}
?>
在第2页中,假设您有另一个表单,然后还有检查

<?php
if(!empty($name)||!empty($email)) { 
//the above is check for global variables email and name are not empty - means stage 2 was filled properly

//Do things for the second page's form like you did for stage 1
} else {
header('Location : stage1 page's link');
//redirect back to stage 1. 
}
?>

查找“PHP令牌”,这可能会对您有所帮助。我输入了它给我的open.PHP的url,您来自index.PHP。。。如果我点击index.php中的一个按钮,它会让我进入open.php,否则没有办法吗?抱歉,如果我打扰了您,但我确实需要这方面的帮助如果您直接输入
open.php
,您将收到消息
您不允许访问
。您可能会在之前意外访问
index.php
。进入未设置身份验证的循环时应调用Exit,它将阻止脚本处理超出范围的任何内容,甚至调用位置标头强制重定向回所需页面我是否将操作保留为空?此方法有点不可靠,因为HTTP引用可能会被欺骗。我正在制作一个包含阶段的网站,因此我希望用户在单击在第1阶段的页面中单击“完成”,这就是我想要的。。你能帮我吗?对于点击事件,你需要使用javascript。在您的按钮中添加属性
onclick=“javascript:rtostage2();”
,然后在页面头部制作一个脚本标记,并在其中放置
函数rtostage2(){window.location=“Link to stage 2的页面”;}
Done:)黑客是否有办法进行黑客攻击并进入第2阶段?或者它的安全性为90%?请参阅,为了获得更好的安全性,请验证表单中的所有字段,并检查它们是否为空和是否已设置。你想让我在上面的答案中写下密码吗P