Solved

$_SESSION in PHP5.9 ...

Posted on 2015-01-16
7
106 Views
Last Modified: 2015-01-17
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
Comment
Question by:Hans Inge Hagen
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 200 total points
ID: 40553310
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
 
LVL 8

Assisted Solution

by:Ahmed Merghani
Ahmed Merghani earned 200 total points
ID: 40553312
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
 

Author Comment

by:Hans Inge Hagen
ID: 40553337
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 4

Assisted Solution

by:Jim Riddles
Jim Riddles earned 100 total points
ID: 40553789
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
 
LVL 8

Assisted Solution

by:Ahmed Merghani
Ahmed Merghani earned 200 total points
ID: 40553947
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
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 200 total points
ID: 40554634
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
 

Author Comment

by:Hans Inge Hagen
ID: 40554939
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now