Solved

$_SESSION in PHP5.9 ...

Posted on 2015-01-16
7
108 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
wamp versus xampp 4 43
How to use md5 hashing 3 25
Load google maps api into wordpress 5 35
mysqli 3 18
Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

930 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

12 Experts available now in Live!

Get 1:1 Help Now