scs Posted April 3, 2006 Share Posted April 3, 2006 I use dreamweaver so my code is corrent. I'm just not using the right code. I have the session started. When the user logs in I set some session variables. [code] $_SESSION['username'] = "sdgjksndgjsg"; [/code] Now my server uses php4. I'm not sure if that makes a difference. All those session variables are blank when I try to use them. Please respond quickly. I'm in a hurry to finish a project! Quote Link to comment Share on other sites More sharing options...
phpfreak101 Posted April 3, 2006 Share Posted April 3, 2006 I think you have to register the session variable first. Like:[code]session_register('first_name'); $_SESSION['first_name'] = $first_name; [/code] Quote Link to comment Share on other sites More sharing options...
complex05 Posted April 3, 2006 Share Posted April 3, 2006 [!--quoteo(post=361277:date=Apr 3 2006, 01:43 PM:name=phpfreak101)--][div class=\'quotetop\']QUOTE(phpfreak101 @ Apr 3 2006, 01:43 PM) [snapback]361277[/snapback][/div][div class=\'quotemain\'][!--quotec--]I think you have to register the session variable first. Like:[code]session_register('first_name'); $_SESSION['first_name'] = $first_name; [/code][/quote]just make sure you call session_start(); on all the scripts that are using the session variables and it should work. I had a similar problem when I started using sessions. Quote Link to comment Share on other sites More sharing options...
phpfreak101 Posted April 3, 2006 Share Posted April 3, 2006 [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]just make sure you call session_start(); on all the scripts that are using the session variables and it should work. I had a similar problem when I started using sessions.[/quote]Also make sure you put session_start() on your page, before anything else. (HTML etc.) If not, you will get Session errors saying "cannot send header, header already sent" because you sent information to the browser before the session had a chance to start. Quote Link to comment Share on other sites More sharing options...
scs Posted April 3, 2006 Author Share Posted April 3, 2006 I used the session register but it didn't work. Now here is the wierd part. I have a if statement that checks for the session variables. And that works fine. So it acts like the variable are there. But when I go to use then below and I get nothing. Like the variable was created. But not set. It did this also before I used the session register. Quote Link to comment Share on other sites More sharing options...
complex05 Posted April 3, 2006 Share Posted April 3, 2006 don't use session_register. use session_start() at the very beginning of your script. Quote Link to comment Share on other sites More sharing options...
scs Posted April 3, 2006 Author Share Posted April 3, 2006 Oh, sorry, I guess I was unclear. I start the session at the top of every page. When the user is logging in I use the session register. Then they are redirected to the main page where I say 'Welcome $_SESSION['username']'. Quote Link to comment Share on other sites More sharing options...
complex05 Posted April 3, 2006 Share Posted April 3, 2006 [!--quoteo(post=361291:date=Apr 3 2006, 02:14 PM:name=Zach Attack)--][div class=\'quotetop\']QUOTE(Zach Attack @ Apr 3 2006, 02:14 PM) [snapback]361291[/snapback][/div][div class=\'quotemain\'][!--quotec--]Oh, sorry, I guess I was unclear. I start the session at the top of every page. When the user is logging in I use the session register. Then they are redirected to the main page where I say 'Welcome $_SESSION['username']'.[/quote]I normally parse them into variables first$usrname = $_SESSION['username'];echo<<<endhtmlWelcome back, $usrnameendhtml;give it a shot. Quote Link to comment Share on other sites More sharing options...
scs Posted April 3, 2006 Author Share Posted April 3, 2006 Worked, Thanks! Quote Link to comment Share on other sites More sharing options...
drewjoh Posted April 3, 2006 Share Posted April 3, 2006 Also be sure you're not creating what you might think is a local variable with the same name. I just had this problem a few days ago. (If you have register_globals on, which I think is on by default)If you create a variable called $username and change it, this will also change $_SESSION['username'];Also, If you are using $_SESSION (or $HTTP_SESSION_VARS), do not use session_register(), session_is_registered() and session_unregister(). ([a href=\"http://us2.php.net/manual/en/function.session-is-registered.php\" target=\"_blank\"]http://us2.php.net/manual/en/function.sess...-registered.php[/a])Also see: [a href=\"http://us2.php.net/manual/en/security.globals.php\" target=\"_blank\"]http://us2.php.net/manual/en/security.globals.php[/a] Quote Link to comment Share on other sites More sharing options...
txmedic03 Posted April 3, 2006 Share Posted April 3, 2006 [!--quoteo(post=361301:date=Apr 3 2006, 01:46 PM:name=drewjoh)--][div class=\'quotetop\']QUOTE(drewjoh @ Apr 3 2006, 01:46 PM) [snapback]361301[/snapback][/div][div class=\'quotemain\'][!--quotec--]Also be sure you're not creating what you might think is a local variable with the same name. I just had this problem a few days ago. (If you have register_globals on, which I think is on by default)If you create a variable called $username and change it, this will also change $_SESSION['username'];Also, If you are using $_SESSION (or $HTTP_SESSION_VARS), do not use session_register(), session_is_registered() and session_unregister(). ([a href=\"http://us2.php.net/manual/en/function.session-is-registered.php\" target=\"_blank\"]http://us2.php.net/manual/en/function.sess...-registered.php[/a])Also see: [a href=\"http://us2.php.net/manual/en/security.globals.php\" target=\"_blank\"]http://us2.php.net/manual/en/security.globals.php[/a][/quote]Register globals in not default and should DEFINITELY be turned off. It is a security issue. Quote Link to comment Share on other sites More sharing options...
scs Posted April 3, 2006 Author Share Posted April 3, 2006 [!--quoteo(post=361301:date=Apr 3 2006, 11:46 AM:name=drewjoh)--][div class=\'quotetop\']QUOTE(drewjoh @ Apr 3 2006, 11:46 AM) [snapback]361301[/snapback][/div][div class=\'quotemain\'][!--quotec--] Also be sure you're not creating what you might think is a local variable with the same name. I just had this problem a few days ago. (If you have register_globals on, which I think is on by default)If you create a variable called $username and change it, this will also change $_SESSION['username'];Also, If you are using $_SESSION (or $HTTP_SESSION_VARS), do not use session_register(), session_is_registered() and session_unregister(). ([a href=\"http://us2.php.net/manual/en/function.session-is-registered.php\" target=\"_blank\"]http://us2.php.net/manual/en/function.sess...-registered.php[/a])Also see: [a href=\"http://us2.php.net/manual/en/security.globals.php\" target=\"_blank\"]http://us2.php.net/manual/en/security.globals.php[/a] [/quote] Thanks! [!--quoteo(post=361304:date=Apr 3 2006, 11:55 AM:name=txmedic03)--][div class=\'quotetop\']QUOTE(txmedic03 @ Apr 3 2006, 11:55 AM) [snapback]361304[/snapback][/div][div class=\'quotemain\'][!--quotec--] Register globals in not default and should DEFINITELY be turned off. It is a security issue. [/quote] Well this current project I'm working on I'm just testing on a free php server. (My testing server on my computer wasn't working) register_globals IS turn on. So that could be a problem. Now my client who will get the project I'm working on, if he uses some one else as a host and register_globals is turn on. Is there a way he could turn that off? Quote Link to comment Share on other sites More sharing options...
complex05 Posted April 3, 2006 Share Posted April 3, 2006 you can change it using .htaccess... but to be honest I don't know how. look it up on google. or maybe someone else knows? Quote Link to comment Share on other sites More sharing options...
txmedic03 Posted April 4, 2006 Share Posted April 4, 2006 Look at [a href=\"http://www.php.net/manual/en/function.ini-set.php\" target=\"_blank\"]ini_set()[/a] to change your register_globals. The thing is if you use $_GET and $_POST you are compatible with the server whether it uses register globals or not. I strongly urge you to turn it off or request that your server admin does so. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.