Connecting Tech Pros Worldwide Forums | Help | Site Map

How to pass a same variable across mutiple pages using sessions

Member
 
Join Date: Aug 2006
Posts: 34
#1: Jan 23 '07
hi
i cant pass a same variable to multiplepages...
while passing variables in sessions
it shows warning and it doesn't pass to multiple pages
here the coding which i hve used
Registration.php
<?
session_start();
session_register("username");
$username=$_POST['t3'];
?>
Registration1.php
<?
session_start();
echo "".$username;
?>
update.php
<?
session_start();
echo "".$username;
$q1="UPDATE `realtour` SET list='$protype' where uname='$username'";
?>

in the above....
i cant get the value of username where used in Registration1.php
can anyone suggest me

ronverdonk's Avatar
Moderator
 
Join Date: Jul 2006
Location: The Netherlands
Posts: 4,139
#2: Jan 23 '07

re: How to pass a same variable across mutiple pages using sessions


Passing variables can best be done via the $_SESSION array.
Quote:

Originally Posted by php doc

If your script uses session_register(), it will not work in environments where the PHP directive register_globals is disabled.

So in your case it is best to code as follows:
[php]Registration.php:
------------------
<?php
session_start();
$username=$_POST['t3'];
$_SESSION['username'] = $username;

Registration1.php:
------------------
<?php
session_start();
echo $_SESSION['username'];

update.php:
-----------
<?php
session_start();
$username = $_SESSION['username'];
echo $username;
[/php]

Ronald :cool:
Member
 
Join Date: Aug 2006
Posts: 34
#3: Jan 24 '07

re: How to pass a same variable across mutiple pages using sessions


Hi
thanks for ur suggestion
its working well
ronverdonk's Avatar
Moderator
 
Join Date: Jul 2006
Location: The Netherlands
Posts: 4,139
#4: Jan 24 '07

re: How to pass a same variable across mutiple pages using sessions


You are most welcome.

Ronald :cool:
Reply