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.

12 Years
Discussion Span
Last Post by fpepito

If you are already setting the username in a cookie

setcookie("your_cookie", $username, time()+99999999, "/", ".domain.name.com", 0);

Then you can just check it's set:


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


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


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

I hope that help you,




$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<BR>";
echo "Your actual language is: $session[lang]<BR>";

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

// You need locale file corresponding with the next language
echo "<A HREF=$myname?lg=fr_FR>Utiliser le fran├žais</A><BR>";
echo "<A HREF=$myname?lg=en>Use english langage</A><BR>";
echo "<A HREF=$myname?lg=pt_PT>Utilizar o portugues</A><BR>";
// update counter
$session[count] = $session[count] + 1;
} else {
echo "It's the first time that you coming. We will create session:<BR>";
$session[lang] = $HTTP_ACCEPT_LANGUAGE;
$session[count] = 1;
echo "<A HREF=$myname>reload</A>";


This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.