[英]How to pass variables from one php page to another without form?
I want to know how to pass a variable from one page to another in PHP without any form. 我想知道如何在没有任何形式的PHP中将变量从一个页面传递到另一个页面。
What I want to achieve is this: 我想要实现的是:
use the get method in the url. 在url中使用get方法。 If you want to pass over a variable called 'phone' as 0001112222: 如果要将名为“phone”的变量作为0001112222传递:
<a href='whatever.php?phone=0001112222'>click</a>
then on the next page (whatever.php) you can access this var via: 然后在下一页(whatever.php)上,您可以通过以下方式访问此var:
$_GET['phone']
You can pass via GET. 你可以通过GET传递。 So if you want to pass the value foobar
from PageA.php
to PageB.php
, call it as PageB.php?value=foobar
. 因此,如果您想将PageA.php
的值foobar
PageA.php
给PageB.php
,请将其称为PageB.php?value=foobar
。
In PageB.php, you can access it this way: 在PageB.php中,您可以通过以下方式访问它:
$value = $_GET['value'];
check to make sure the variable is set. 检查以确保设置变量。 Then clean it before using it: 然后在使用前清洁它:
isset($_GET['var'])?$var=mysql_escape_string($_GET['var']):$var='SomeDefaualtValue';
Otherwise, assign it a default value ( $var=''
is fine) to avoid the error you mentioned. 否则,为其指定一个默认值( $var=''
很好)以避免您提到的错误。
You can use Ajax calls or $_GET["String"]; 您可以使用Ajax调用或$ _GET [“String”]; Method 方法
If you are trying to access the variable from another PHP file directly, you can include that file with include()
or include_once()
, giving you access to that variable. 如果您尝试直接从另一个PHP文件访问该变量,则可以使用include()
或include_once()
包含该文件,从而可以访问该变量。 Note that this will include the entire first file in the second file. 请注意,这将包括第二个文件中的整个第一个文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.