Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 141
  • Last Modified:

$_SESSION in PHP5.9 ...

I am trying to update a session scritpt to my members pages. (from PHP 5.x to PHP 5.9) ...
My login sets the:
$_SESSION['username']
$_SESSION['pw']

if correct it will go to the main member page ...
I have a script checking the Session:


<?php
session_start();
if (! isset($_SESSION['username'] )) Header('Location: logout.php'); {
}
?>

.. my problem is that it will send me to "logout.php" all the time.

How do I update my script to PHP 5.9?

Anyone?
0
Hans Inge Hagen
Asked:
Hans Inge Hagen
  • 2
  • 2
  • 2
  • +1
5 Solutions
 
Ray PaseurCommented:
Current levels of PHP are documented on the home page: http://php.net/  There is no PHP 5.9 yet, and may well never be!

I think you may want the check to redirect to the log-IN page, not to the log-OUT page.  A sample design for PHP client authentication is given in this article.  It's old, but the principles still apply.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_2391-PHP-login-logout-and-easy-access-control.html
0
 
Ahmed MerghaniCommented:
Can you post the login page or the part of code you set $_SESSION['username'] ?
Are you sure there is no anywhere "session_destroy()"?
BTW, if you use $_SESSION['pw'] for storing password, then, this is very DANGEROUS practice!
0
 
Hans Inge HagenOwner and programmerAuthor Commented:
hi, sorry ... PHP 5.5.9 .. and sorry again I do not sesson the password ...


My login session start:

session_start();

$_SESSION['username'] = $username;
$_SESSION['aid'] = $aid;

If correct it will send the user to the main member page (main.php) where I have a script (include userpass.php) checking the session by the username:

<?php
session_start();
if (! isset($_SESSION['username'])) Header('Location: logout.php'); {
}
?>
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Jim RiddlesPrepress/OMS SpecialistCommented:
It looks like there is a typo in your code.
Current code
<?php
session_start();
if (! isset($_SESSION['username'])) Header('Location: logout.php'); {
}
?>

Open in new window

Changed lines
if (! isset($_SESSION['username']))  {
  Header('Location: logout.php');
}

Open in new window

0
 
Ahmed MerghaniCommented:
From where did the $username  value come? Insure that this value is set and not contains null!
Try to hard coded the value or set it manually at login like this:
//$_SESSION['username'] = $username;
$_SESSION['username'] = "test";

Open in new window

Regarding Jim Riddles comment, you just can remove "{}".
0
 
Ray PaseurCommented:
If you're new to PHP and want some learning examples and guidance, this article can help.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11769-And-by-the-way-I-am-new-to-PHP.html
0
 
Hans Inge HagenOwner and programmerAuthor Commented:
Hi,

it will not keep the $_SESSION even when hard coding ... there might be a problem with the servers. I have to talk to the administrators .... hmmm.

Thanks all for you answers!
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now