Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/72.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和html——按下一个按钮,如何重定向到另一个页面,同时触发一个php文件_Php_Html - Fatal编程技术网

php和html——按下一个按钮,如何重定向到另一个页面,同时触发一个php文件

php和html——按下一个按钮,如何重定向到另一个页面,同时触发一个php文件,php,html,Php,Html,我有一个php页面,其中有一个按钮(index.php),这个php页面包含变量,我想在另一个文件的另一个php脚本(script.php)中使用它们,但同时,我希望用户被重定向到一个html页面(success.html) 我该怎么做?这很简单。有几种方法可以做到这一点,您可以使用会话或设置表单来发布结果。因此,在index.php上,您可以这样做 <?php session_start() $_SESSION['foo'] = 'bar'; header("location:s

我有一个php页面,其中有一个按钮(index.php),这个php页面包含变量,我想在另一个文件的另一个php脚本(script.php)中使用它们,但同时,我希望用户被重定向到一个html页面(success.html)
我该怎么做?

这很简单。有几种方法可以做到这一点,您可以使用会话或设置表单来发布结果。因此,在index.php上,您可以这样做

<?php

 session_start()
 $_SESSION['foo'] = 'bar';
 header("location:success.html");

?>

您现在可以全局访问$_会话['foo']

<?php 
   echo $_SESSION['foo']; // will output bar
在index.php中设置
,并将这行代码放在script.php中脚本的末尾:

header('location: 'success.html']);
如何将变量传递到script.php

如果将此脚本放在script.php中:

foreach ($_POST as $key => $value){
          $$key=$value;
        }
然后,它将使用
name=”“
atribute为所有表单元素创建变量,并为它们分配各自的值

例如:

将创建变量


$firstname='John'

什么是Sessionoon foo??对不起,我只知道php的基本知识:sNo问题。Foo只标识会话变量。你可以用任何你喜欢的东西$_会话['anything']。美好的很好的解释:)谢谢