Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如果不满足条件,则停止用户查看页面_Php - Fatal编程技术网

Php 如果不满足条件,则停止用户查看页面

Php 如果不满足条件,则停止用户查看页面,php,Php,Hi appologies,如果已回答此问题,但我无法为我的问题找到明确答案 假设我有两个页面,分别是fruit.php和sala.php 当用户在fruit.php的字段中输入数据时,他将被引导到sala.php,但是没有任何东西阻止用户在浏览器中键入sala.php,这将打开第二页并给出错误的结果,因为他的第1页fruit.php中的数据尚未输入 知道我如何在fruit.php完成之前阻止用户访问salard.php吗?假设fruit.php在get中发送数据,如下所示 salad.php&

Hi appologies,如果已回答此问题,但我无法为我的问题找到明确答案

假设我有两个页面,分别是
fruit.php
sala.php

当用户在
fruit.php
的字段中输入数据时,他将被引导到sala.php,但是没有任何东西阻止用户在浏览器中键入
sala.php
,这将打开第二页并给出错误的结果,因为他的第1页
fruit.php
中的数据尚未输入


知道我如何在fruit.php完成之前阻止用户访问
salard.php
吗?

假设fruit.php在
get
中发送数据,如下所示

salad.php&donut=yummy
您需要的是,在加载sala.php时,验证是否已发送甜甜圈。为此,您需要使用
isset()
。(请注意,这也适用于
$\u POST
,但为了示例起见,我将继续使用
$\u GET

首先,这应该可以解决问题,然后我建议查看
$\u POST
,而不是
$\u GET
,然后检查
$\u session

这就是了。

您应该以这样的方式编写salard.php,即它只接受POST请求,如果是GET请求,则将其重定向到salard.php顶部的fruit.php

if(($_SESSION['HTTP_REFERER'] !="http://domain.ext/dir/fruit.php") || (!isset($_POST['essentialFormVar1From_fruit.php'])) || ...){
  header('location: http://domain.ext/dir/fruit.php');
};
else{
  ...
  //render page
  ...
}

如果通过POST传递值,可以在“sala.php”页面中进行如下验证:

if(!isset($_POST['myVariable'])) {
    header('Location: fruit.php');
    exit;
}

... continue my salad page ...

如果您正在使用GET,只需将$\u POST更改为$\u GET。

在这种情况下,您可以执行以下操作: 由于用户希望在第1页中输入一些值,因此(表单)将显示在那里,我们假设这一页:

fruit.php

<form name="fruit" id="fruit" action="salad.php" method="POST">
First component: <input type="text" name="component1">
Second component: <input type="text" name="component2">
<input type="submit" value="check">
</form>

第一部分:
第二部分:
现在进入第二页:

salar.php

<?php
//first thing first, we're going to check whether the user
//is being redirected by the form by doing something like
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
//do something
} else {
//this thing will redirect the user to the former page in case no form was applied
header('Location: fruit.php') or die('Unexpected error');
}
?>

您可以在sala.php中添加一个检查,检查是否发送了来自请求的正确数据:

if($_POST['fieldname'] == ''){
  echo 'you enterd the page wrong. Please go back to the <a href="...">Form</a> and enter the data needed';
}else{
  // normal page content here.
}
if($\u POST['fieldname']=''){
echo“您输入的页面错误。请返回并输入所需的数据”;
}否则{
//正常的页面内容在这里。
}

因此,当浏览者提交试衣请求时,他将只获得页面。

显示您的尝试。。请发布您的表单。@NarendraSisodia我只是在寻找开始解决此问题的逻辑,而不是code@Marilee您可以使用
$\u会话
手册:
if($_POST['fieldname'] == ''){
  echo 'you enterd the page wrong. Please go back to the <a href="...">Form</a> and enter the data needed';
}else{
  // normal page content here.
}