我有一个变量声明并在一个php文件中给出一个值,我怎么能将该变量与存储在另一个php文件中的值一起使用?
问题描述:
the website is like a social media.
The first php file does the log in, and it will have a variable $name1 where the username of the logged on user will be stored
I need to that same variable with the username value stored in it in another php file where I create a query containing all the posts from that user.
How can I use that variable in my second php file?
网站就像一个社交媒体。 p>
第一个php文件 登录,它将有一个变量$ name1,其中将存储登录用户的用户名 p>
我需要在另一个php中存储用户名值的同一个变量 file我在哪里创建一个查询,其中包含该用户的所有帖子。 p>
如何在我的第二个php文件中使用该变量? p> div>
答
in login.php
session_start();
$_SESSION['user'] = $name1;
on nextPage.php
session_start();
$username = $_SESSION['user'];
答
Just use the session and store in it username and than you will have access to it in any php file when you start the session.