PHP Sessions - globals off

This is a discussion on PHP Sessions - globals off within the alt.comp.lang.php forums, part of the PHP Programming Forums category; I am trying to get a login script working with globals turned off... Page 1 (login.php): Page one has ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 06-08-2004
aaron
 
Posts: n/a
Default PHP Sessions - globals off

I am trying to get a login script working with globals turned off...

Page 1 (login.php): Page one has a username and password field, once
submitted it goes to page 2.

Page 2 (login_script.php):
// If $username and $password are set, match data against users table
$query=mysql_query("SELECT * FROM users WHERE username =
'$_POST[username]' AND password = '$_POST[password]'")
or die ("For some reason the script wasn't able to check the
username/password.<br> ".mysql_error());

// If num_rows from users table = 1, set session variables
if (mysql_num_rows($query) == "1") {

if(!session_id()){
session_start();
}
// i want to "register" these thing to display the info later
$_SESSION['valid_user'] = $_POST['username'];
$_SESSION['ip_address'] = $_SERVER['REMOTE_ADDR'];
$_SESSION['seclevel'] = $data->seclevel;
$rowid = $data->id;

header("Location: ./index.php?$id");
}

Page 3 (index.php):
I'm trying to call the variables (session variables) here:
Username: <? print "{$_SESSION['valid_user']}"; ?><br />
Security Level: <? print "{$_SESSION['seclevel']}"; ?>

The script works with globals on, but I want to turn that off in the
php.ini on my server.

What am I doing wrong with the $_SESSION side of things?

thanks
Reply With Quote
  #2 (permalink)  
Old 06-08-2004
Alvaro G Vicario
 
Posts: n/a
Default Re: PHP Sessions - globals off

*** aaron wrote/escribió (8 Jun 2004 06:04:51 -0700):
> Page 3 (index.php):
> I'm trying to call the variables (session variables) here:
> Username: <? print "{$_SESSION['valid_user']}"; ?><br />
> Security Level: <? print "{$_SESSION['seclevel']}"; ?>


Do you load session data with session_start() ?

--
--
-- Álvaro G. Vicario - Burgos, Spain
--
Reply With Quote
  #3 (permalink)  
Old 06-09-2004
aaron
 
Posts: n/a
Default Re: PHP Sessions - globals off

Alvaro G Vicario <alvaro_QUITAR_REMOVE@telecomputeronline.com> wrote in message news:<gpu1r8udpx6j$.ctv7tgsna9ry.dlg@40tude.net>.. .
> *** aaron wrote/escribió (8 Jun 2004 06:04:51 -0700):
> > Page 3 (index.php):
> > I'm trying to call the variables (session variables) here:
> > Username: <? print "{$_SESSION['valid_user']}"; ?><br />
> > Security Level: <? print "{$_SESSION['seclevel']}"; ?>

>
> Do you load session data with session_start() ?
>
> --



Yes, I am doing a session_start();
Reply With Quote
  #4 (permalink)  
Old 06-11-2004
Rook
 
Posts: n/a
Default Re: PHP Sessions - globals off

I think you need to get rid of the if statement... you can check to see if
you are hitting the session_start function like this:
<?
if (!session_id()) {
session_start();
exit('session started');
}
exit('session NOT started');
?>

I don't think you need the session_id function at all.... I'd change it to
this:
<?
session_start();
?>

OR if you want to give it a specific session id... do this:
<?
session_id('MY_SESS_ID');
session_start();
?>


"aaron" <redhatlinux@msn.com> wrote in message
news:dd6e9aa5.0406080504.3eb4c2c3@posting.google.c om...
> I am trying to get a login script working with globals turned off...
>
> Page 1 (login.php): Page one has a username and password field, once
> submitted it goes to page 2.
>
> Page 2 (login_script.php):
> // If $username and $password are set, match data against users table
> $query=mysql_query("SELECT * FROM users WHERE username =
> '$_POST[username]' AND password = '$_POST[password]'")
> or die ("For some reason the script wasn't able to check the
> username/password.<br> ".mysql_error());
>
> // If num_rows from users table = 1, set session variables
> if (mysql_num_rows($query) == "1") {
>
> if(!session_id()){
> session_start();
> }
> // i want to "register" these thing to display the info later
> $_SESSION['valid_user'] = $_POST['username'];
> $_SESSION['ip_address'] = $_SERVER['REMOTE_ADDR'];
> $_SESSION['seclevel'] = $data->seclevel;
> $rowid = $data->id;
>
> header("Location: ./index.php?$id");
> }
>
> Page 3 (index.php):
> I'm trying to call the variables (session variables) here:
> Username: <? print "{$_SESSION['valid_user']}"; ?><br />
> Security Level: <? print "{$_SESSION['seclevel']}"; ?>
>
> The script works with globals on, but I want to turn that off in the
> php.ini on my server.
>
> What am I doing wrong with the $_SESSION side of things?
>
> thanks



Reply With Quote
  #5 (permalink)  
Old 06-16-2004
aaron
 
Posts: n/a
Default Re: PHP Sessions - globals off

Thanks...I'll try it. I've just had issues with sessions since
globals off is the default.

thanks

"Rook" <rook@wasabi-is-good.com> wrote in message news:<2d9yc.11118$H65.4905@nwrddc02.gnilink.net>.. .
> I think you need to get rid of the if statement... you can check to see if
> you are hitting the session_start function like this:
> <?
> if (!session_id()) {
> session_start();
> exit('session started');
> }
> exit('session NOT started');
> ?>
>
> I don't think you need the session_id function at all.... I'd change it to
> this:
> <?
> session_start();
> ?>
>
> OR if you want to give it a specific session id... do this:
> <?
> session_id('MY_SESS_ID');
> session_start();
> ?>
>
>
> "aaron" <redhatlinux@msn.com> wrote in message
> news:dd6e9aa5.0406080504.3eb4c2c3@posting.google.c om...
> > I am trying to get a login script working with globals turned off...
> >
> > Page 1 (login.php): Page one has a username and password field, once
> > submitted it goes to page 2.
> >
> > Page 2 (login_script.php):
> > // If $username and $password are set, match data against users table
> > $query=mysql_query("SELECT * FROM users WHERE username =
> > '$_POST[username]' AND password = '$_POST[password]'")
> > or die ("For some reason the script wasn't able to check the
> > username/password.<br> ".mysql_error());
> >
> > // If num_rows from users table = 1, set session variables
> > if (mysql_num_rows($query) == "1") {
> >
> > if(!session_id()){
> > session_start();
> > }
> > // i want to "register" these thing to display the info later
> > $_SESSION['valid_user'] = $_POST['username'];
> > $_SESSION['ip_address'] = $_SERVER['REMOTE_ADDR'];
> > $_SESSION['seclevel'] = $data->seclevel;
> > $rowid = $data->id;
> >
> > header("Location: ./index.php?$id");
> > }
> >
> > Page 3 (index.php):
> > I'm trying to call the variables (session variables) here:
> > Username: <? print "{$_SESSION['valid_user']}"; ?><br />
> > Security Level: <? print "{$_SESSION['seclevel']}"; ?>
> >
> > The script works with globals on, but I want to turn that off in the
> > php.ini on my server.
> >
> > What am I doing wrong with the $_SESSION side of things?
> >
> > thanks

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 05:38 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0