如何在2个PHP文件之间传递变量? [英] How to pass variables between 2 PHP files?
本文介绍了如何在2个PHP文件之间传递变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个名为one.php的文件中的以下代码
<?php
session_start() ;
$ _SESSION ['one'] =ONE;
$ _SESSION ['two'] =TWO;
?>
< html>
< body>
< a href =two.php>点击此处查看1.< / a>
< a href =two.php>点击此处查看2.< / a>
< / body>
< / html>
现在,当我点击其中一个锚标签链接,它需要我到two.php。 / p>
这里我想输出为
一个被点击。 c $ c> OR
两个被点击。
如何使用PHP在two.php中进行上述输出
解决方案
最简单的解决方案是将一个参数附加到url
< a href =two.php?clicked = 1>点击此处查看1.< / a>
< a href =two.php?clicked = 2>点击此处进行2.< / a>
然后在PHP
if(isset($ _ GET ['clicked'])){
$ clicked =(int)$ _ GET ['clicked'];
} else {
$ clicked = 0;
}
I have the following code in a file called one.php
<?php
session_start();
$_SESSION['one'] = "ONE";
$_SESSION['two'] = "TWO";
?>
<html>
<body>
<a href="two.php">Click here for 1.</a>
<a href="two.php">Click here for 2.</a>
</body>
</html>
Now when I click on one of the anchor tag links, it takes me to two.php.
Here I want the output to be,
One was clicked.
OR Two was clicked.
How do I make the above output in two.php using PHP?
解决方案
The simplest solution is to append a paramter to the url
<a href="two.php?clicked=1">Click here for 1.</a>
<a href="two.php?clicked=2">Click here for 2.</a>
then in PHP
if (isset($_GET['clicked'])) {
$clicked = (int)$_GET['clicked'];
} else {
$clicked = 0;
}
这篇关于如何在2个PHP文件之间传递变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文