LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-02-2004, 08:48 AM   #1
spyghost
Member
 
Registered: Jun 2003
Distribution: Redhat
Posts: 245

Rep: Reputation: 30
php user authentication


hi,

i don't get the logic behind user authentication in php, or other server side languages

isn't it that after the authentication, the script simply redirects the browser to another page/site? why not type the site on the address box... right?

sorry if this is a foolish question, but i am just wondering...

opinions are highly appreciated...

thanks
 
Old 01-02-2004, 08:52 AM   #2
ter_roshak
Member
 
Registered: May 2001
Location: Everett, WA
Distribution: Gentoo, RedHat
Posts: 102

Rep: Reputation: 15
What I normally do is use session variables to initiate a state-ful connection with specific users. This requires that I place session_start() at the top of each PHP file. With this, I can require that the user have a cookie on their machine to access every page except for the login page. This prevents them from typing in the URL to get to any other pages.

Josh
 
Old 01-02-2004, 09:42 AM   #3
spyghost
Member
 
Registered: Jun 2003
Distribution: Redhat
Posts: 245

Original Poster
Rep: Reputation: 30
if that is the case then, it wont be totally secure afterall. if the cookie remains on the client's hard disk, then he still has full access to any page without undergoing the login process.

is there a way of eliminating this scenario?
 
Old 01-02-2004, 01:05 PM   #4
ter_roshak
Member
 
Registered: May 2001
Location: Everett, WA
Distribution: Gentoo, RedHat
Posts: 102

Rep: Reputation: 15
In the first case that I described, the cookie would be valid for as long as the browser was not shut down. If you shut down the browser, you would then have to login again.

Another option is to manually set a cookie, which would allow you to have it expire after 15 minutes, (arbitrary time), so that you could force users to login if their session was idle for more than 15 minutes. This would require that you refresh the cookie at each page though. The following URL is a good resource.

http://www.php.net/manual/en/function.setcookie.php

Josh
 
Old 01-02-2004, 01:17 PM   #5
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
Also, isn't there a way to configure the session so that it doesn't use a cookie? Instead, it automatically appends a session ID to the list of query string variables. It's been awhile since I've played with my PHP configuration, but I seem to remember something about that.
 
Old 01-02-2004, 01:30 PM   #6
ter_roshak
Member
 
Registered: May 2001
Location: Everett, WA
Distribution: Gentoo, RedHat
Posts: 102

Rep: Reputation: 15
I think that's what the 'session_start()' does when included at the beginning of each page. It does have to set a cookie though, but its done automatically, all taken care with no further interaction. I don't know how to force a session to expire on its own using that method though. In the past, when using that method, I have set a session variable to some pre-defined value to indicate logged in, and when the user logs out, the variable is set to a value not like the previous one. I would not be the expert, just some of my experience.

Josh
 
Old 01-04-2004, 07:11 PM   #7
w0000422
Member
 
Registered: Dec 2003
Distribution: redhat linux 9.0
Posts: 60

Rep: Reputation: 15
i'm new to php programming and never use the cookies before, what actually the cookies does? only used for user authentication or got any other functions?

do we really need to use cookies? can i use the cookies for passing value?

ck
 
Old 01-04-2004, 07:22 PM   #8
coolman0stress
Member
 
Registered: Jun 2003
Location: Toronto, Ontario, Canada
Posts: 288

Rep: Reputation: 30
Quote:
Originally posted by w0000422
i'm new to php programming and never use the cookies before, what actually the cookies does? only used for user authentication or got any other functions?

do we really need to use cookies? can i use the cookies for passing value?

ck
Cookies are a great way to *hide* pieces of information so you don't have to manually keep track of them.

Usually it's authentication info, but you could also use it for, say, keeping track of user settings/preferences. It's especially nice since you can make it so they stay for long terms. So when a user returns after a few days to your site, the site will remember him/her, etc.

Ofcourse you could also use them for more evil purposes

Hope this helps...
 
Old 01-04-2004, 09:15 PM   #9
w0000422
Member
 
Registered: Dec 2003
Distribution: redhat linux 9.0
Posts: 60

Rep: Reputation: 15
ic, what a wonderful method to protect my confidential information...thks man!
i will try to learn more abt cookies...

ck
 
Old 01-07-2004, 04:59 PM   #10
Electric_Blue
Member
 
Registered: Aug 2003
Distribution: RedHat
Posts: 35

Rep: Reputation: 15
Quote:
isn't it that after the authentication, the script simply redirects the browser to another page/site? why not type the site on the address box... right?
Most of my secured pages (php) will look for the cookie on the users machine first, if the cookie is not found it does a redirect to a login page. Therefore it never loads the page if a user types the address in, or has it bookmarked, UNLESS they have the cookie that I sent them on their machine.

For instance:
if (!$authenticated_cookie) {
header ("HTTP 302 Redirect");
header("location: login.php");
}

This is just one way of securing a page.
 
Old 01-07-2004, 10:13 PM   #11
sendit
LQ Newbie
 
Registered: Jan 2004
Location: Pune
Distribution: RedHat, Mandrake
Posts: 1

Rep: Reputation: 0
Post Re: php user authentication

Hello!

It's not just about redirecting the pages.
The server side script sets some values into
either cookies or appends something to url.
This lets you access the redirected page/Web Site.

Is that OK?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Authentication jpbarto Programming 1 09-07-2004 10:11 AM
HTTP AUTHENTICATION with PHP lemotion Programming 1 04-22-2004 02:08 PM
PHP Authentication against /etc/shadow mpgram Programming 1 04-13-2004 11:55 PM
Squid proxy with user authentication and user rights duvanhorn Linux - Networking 0 08-07-2003 03:40 AM
PHP and Username Authentication Graanco Linux - Software 0 07-31-2003 03:35 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:07 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration