954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How Can I Pass A PHP Variable From One .php page to another

hey, i've been in a middle of a problem about passing a php variable from one .php page to another?
for example:
if im in a middle of sign.php which has a variable called $username:
this user name is to be known through all the rest .php pages in my project
as long as the cookies for this user name are set.
thank you.

Decency
Newbie Poster
22 posts since Aug 2004
Reputation Points: 10
Solved Threads: 1
 

If you are already setting the username in a cookie
e.g.
[PHP]setcookie("your_cookie", $username, time()+99999999, "/", ".domain.name.com", 0);[/PHP]

Then you can just check it's set:
[PHP]$_COOKIE['your_cookie'][/PHP]

on top of that you can check the username variable, along with passwords, and compare them to the contents of a database for example.

ReDuX
Junior Poster
127 posts since Sep 2004
Reputation Points: 12
Solved Threads: 5
 

Wouldnt you be able to simply use a include function or some sort, or can you not. I know phpBB does it.

Young Teck 06
Posting Pro in Training
440 posts since Sep 2004
Reputation Points: 12
Solved Threads: 0
 

A little example: (try it in http://fpepito.dyndns.org/test.php )

I hope that help you,

pepito

-----------------

<?

$myname = $PHP_SELF;
session_register ("session");

if (isset ($session[lang])) {
// if user choice another language, update the session[lang]
if (isset ($lg)) { $session[lang] = $lg;}

echo "Session existe, you have enter: $session[count] times
";
echo "Your actual language is: $session[lang]
";

setlocale ("LC_TIME", $session[lang]);
echo strftime ("%c")."
";

// You need locale file corresponding with the next language
echo "Utiliser le français
";
echo "Use english langage
";
echo "Utilizar o portugues
";
// update counter
$session[count] = $session[count] + 1;
} else {
echo "It's the first time that you coming. We will create session:
";
$session[lang] = $HTTP_ACCEPT_LANGUAGE;
$session[count] = 1;
echo "reload";
}

?>

fpepito
Newbie Poster
14 posts since Oct 2004
Reputation Points: 10
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You