|
-
September 8th, 2010, 01:37 PM
#1
best authentication method PHP5
Earlier i would take username and password, match with db and on success redirect
Code:
session_register("myusername");
On every page that is viewed i would include a file that checks if the session is registered or not.
Now that session_register is deprecated, i did try to google alot to see what would be the best way to authenticate. With the above method i always noticed lots of hacking, session hijacking happening.
WHAT IS THE BEST AND MOST SECURED AND EFFICIENT WAY TO AUTHENTICATE. IS THERE AN OBJECT ORIENTED WAY OF ACCOMPLISHING THIS?
thank you
-
September 8th, 2010, 02:09 PM
#2
Re: best authentication method PHP5
Always use session_name(), not session_register().
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
September 8th, 2010, 02:22 PM
#3
Re: best authentication method PHP5
 Originally Posted by PeejAvery
Always use session_name(), not session_register().
should i provide the name?
Also what should i check for in other pages to make sure un authenticated users donot access those pages?
-
September 8th, 2010, 02:38 PM
#4
Re: best authentication method PHP5
Always provide a name...unless you want session stealing and poor security.
Upon logging in, save the current user to a session variable named user. Then check for that session variable at the beginning of every page.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
September 8th, 2010, 02:54 PM
#5
Re: best authentication method PHP5
 Originally Posted by PeejAvery
Always provide a name...unless you want session stealing and poor security.
Upon logging in, save the current user to a session variable named user. Then check for that session variable at the beginning of every page.
would the below be rite
Code:
mysql query results in a match.
$user = data['username'];
$_SESSION['user'] = $user;
session_name($user);
AND ON EVERY PAGE CHECK BELOW
Code:
if(isset(session_name($_SESSION['user'])))
//good
else
//redirect to index.php
Please correct me if its not the most efficient way.
-
September 8th, 2010, 06:12 PM
#6
Re: best authentication method PHP5
It works...but instead of putting the code at the top of every page...create an authentication.php file and require it at the top of every page.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
September 8th, 2010, 08:41 PM
#7
Re: best authentication method PHP5
 Originally Posted by PeejAvery
It works...but instead of putting the code at the top of every page...create an authentication.php file and require it at the top of every page.
yea i know it works....... yea i will include it into a file but is this the best way ? i wish to know if there is a better way i can accomplish this.
-
September 8th, 2010, 10:35 PM
#8
Re: best authentication method PHP5
Yes. An required header file is the only way to assure security across all the pages.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
September 9th, 2010, 12:17 AM
#9
Re: best authentication method PHP5
 Originally Posted by PeejAvery
Yes. An required header file is the only way to assure security across all the pages.
wat do you mean by a required header file is the only way to assure security?
-
September 9th, 2010, 05:45 PM
#10
Re: best authentication method PHP5
If you don't require a header file at the top...then how do you expect to restrict it's access? Other than .htaccess...but that excludes any database interaction.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
September 9th, 2010, 10:57 PM
#11
Re: best authentication method PHP5
 Originally Posted by PeejAvery
If you don't require a header file at the top...then how do you expect to restrict it's access? Other than .htaccess...but that excludes any database interaction.
gotcha... would session_destroy be the right way on a logout ?
-
September 10th, 2010, 09:19 AM
#12
Re: best authentication method PHP5
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
September 20th, 2010, 10:01 AM
#13
Re: best authentication method PHP5
It may be interesting to keep your sessions in a database as well. On a shared server this may resolve security issues with other websites hosted on the same box.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|