如何在不使用表单的情况下将PHP页面中的变量传递到另一个页面? [英] How to pass variables in PHP page to another page without using form?
问题描述
我使用的项目与Facebook有关.当用户登录$user
时,将在该页面中知道该变量,但对于其他页面则不知道.所以我想知道如何通过不带形式的PHP传递变量?我已经在尝试声明会话了,但是由于处于if条件下,所以不可能
My project using related to Facebook. When user login $user
will variable that in this page is know this variable but for other page is no. So I want to know how to pass variables by using PHP without form? I am trying with declare session already but it is not possible because it's in if condition
<?php
if ($user):
echo 'Name:'. $user_profile['id']."<br />";
echo 'Name:'. $user_profile['name']."<br />";
else:
?>
$user_profile['id']
是我要传递到另一页的内容.
$user_profile['id']
is what I want to pass to the other page.
推荐答案
您可以在会话中完成
session_start();
$_SESSION['user_profile'] = $user_profile['id'];
并在每个要存储变量的页面上使用会话变量
and use session variable every page you want the stored variables
在其他所有页面上,您都可以像这样检索变量值
on every other pages you can retrieve the variable value like that
session_start();
$user_profile['id'] = $_SESSION['user_profile'];
这篇关于如何在不使用表单的情况下将PHP页面中的变量传递到另一个页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!