Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

$_SESSION in PHP5.9 ...

Posted on 2015-01-16
7
Medium Priority
?
133 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 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 800 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 800 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
Technology Partners: 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!

 
LVL 9

Assisted Solution

by:Jim Riddles
Jim Riddles earned 400 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 800 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 111

Accepted Solution

by:
Ray Paseur earned 800 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
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…
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 create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

916 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