Session not working

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
winsonlee
Forum Commoner
Posts: 76
Joined: Thu Dec 11, 2003 8:49 pm

Session not working

Post by winsonlee »

I tried implementing session using the following code but it doesnt seems to be working. some one can advise me what went wrong ??

Login.php

Code: Select all

session_start();
$_SESSION['userid'] = $_REQUEST['username'];

HOME.php

Code: Select all

if(isset($_SESSION['userid'])){

echo "<tr><td align=center'><strong><font color='#FFFFFF'>Welcome $_SESSION[userid]</font></strong></td></tr>";
}
mickd
Forum Contributor
Posts: 397
Joined: Tue Jun 21, 2005 9:05 am
Location: Australia

Post by mickd »

it could be setting but because that html you wrote in home has a few mistakes in it it doent show. btw better to use " for html instead of '. also keep the userid in '.

Code: Select all

echo '<tr><td align="center"><strong><font color="#FFFFFF">Welcome ' . $_SESSION['userid'] . '</font></strong></td></tr>';

edit: also the font tag is being depracated, better to use styles instead.
winsonlee
Forum Commoner
Posts: 76
Joined: Thu Dec 11, 2003 8:49 pm

Post by winsonlee »

hmm ..
my session still doesnt seems to be working..
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

change your error reporting up to E_ALL. I'm going to bet you have output before the session_start() call. In which case, viewtopic.php?t=1157
41
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

i don't see you putting session_start() on the home.php page. if you are going to use a session on any page no matter what you have to put session_start() at the top of it
winsonlee
Forum Commoner
Posts: 76
Joined: Thu Dec 11, 2003 8:49 pm

Post by winsonlee »

thanks .. that is helpful.
manage to solve the problem
Post Reply