By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,948 Members | 1,929 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,948 IT Pros & Developers. It's quick & easy.

Help , i cann't Read session value in another page

abdoelmasry
100+
P: 104
Hi Friends
i need help in sessions
im passing variables between pages using sessions
this is the main page thats mean the home page
the main page have table to show messages for users , it have also the site style


<?
session_start();
echo
<html>
<title>WWW.EGYHK.COM</title>
<body>
<center>
<table wisth='100%' height='500' border='1' cellpadding='0' callspacing='0'>
<tr><td>$maintopic</td></tr>
</table></center>
</body>
</html>
";
?>

and i have another page named functions.php that setting the session, it have this code

<?
function showmsg($msg){
session_start();
session_register("maintopic");
$maintopic=$msg;
header("location:main.php");
}
?>

the third page is login.php , this code

<?
switch($do){
case "login":
if((!$username)||(!$password)){
showmessage("Error<br>Supply Empty Fields");
}

if(($username!='abdoelmasry')||($password!='$amiab do95245ra!@')){
showmessage("Not Valid Login Info");
}}

echo "
<html>
<body>
<form name='login' action='login.php?do=login' method='post'>
<input type='textbox' name='username' value='username'><br>
<input type='password' name='password'><br>
<input type='submit' value=' login '></form>
</body>
</html>
";
?>

if the username or password empty it will send the message (Error<br>Supply Empty Fields)

to function showmsg() to set the session variable the send header to main page
that will write the session value

but i cannot read session from another page
it can be readed in functions.php

i think the function showmsg() not setting global session

i need help to set session from showmsg function , then read session in another page

i hope i could explain

Please read the Posting Guidelines before you post in this forum! Especially the part about enclosing your code with tags

moderator.
Jan 21 '07 #1
Share this Question
Share on Google+
3 Replies


P: 33
Hi,


I think you need to use $_SESSION['variable_name'] in your code. And you need to give the command session_start on each of the page, where you needed the session variable

Please refer http://in2.php.net/session_start

Subash :)
Jan 21 '07 #2

abdoelmasry
100+
P: 104
Thank you Much subash

but what is the changes between

session_register("variable");
and
$_session["variable"];

???

could You Help ?
Jan 22 '07 #3

abdoelmasry
100+
P: 104
Sorry moderator
Will Not Repead Again

Abdo Elmasry
Feb 10 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.