944,054 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 46598
  • PHP RSS
Oct 22nd, 2004
0

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

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 1
Newbie Poster
Decency is offline Offline
22 posts
since Aug 2004
Oct 23rd, 2004
0

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

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.
Reputation Points: 12
Solved Threads: 5
Junior Poster
ReDuX is offline Offline
127 posts
since Sep 2004
Oct 24th, 2004
0

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

Wouldnt you be able to simply use a include function or some sort, or can you not. I know phpBB does it.
Reputation Points: 12
Solved Threads: 0
Posting Pro in Training
Young Teck 06 is offline Offline
440 posts
since Sep 2004
Oct 24th, 2004
0

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

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<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>";
}

?>
Reputation Points: 10
Solved Threads: 1
Newbie Poster
fpepito is offline Offline
14 posts
since Oct 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Php portal install help!!
Next Thread in PHP Forum Timeline: PHP Include ... Quote quirk





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC