Jump to content

Please respond to easy question


scs

Recommended Posts

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!
Link to comment
Share on other sites

[!--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.
Link to comment
Share on other sites

[!--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.
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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']'.
Link to comment
Share on other sites

[!--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<<<endhtml
Welcome back, $usrname
endhtml;

give it a shot.
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

[!--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.
Link to comment
Share on other sites

[!--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?
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.