Solved

$_SESSION in PHP5.9 ...

Posted on 2015-01-16
7
112 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 109

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
ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 
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 109

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

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.  …
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 dynamically set the form action using jQuery.

825 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