Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 9th, 2003, 02:55 PM
Authorized User
 
Join Date: Jun 2003
Location: , , USA.
Posts: 83
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to natmaster Send a message via AIM to natmaster Send a message via MSN to natmaster
Default Login Script

I was hoping someone here could help me with a login script.

I want it to work like this:
The user goes to the page, it prompts them with a login window with a username and password field. the script then checks to see if there is a text files in a particular folder that matches the username. if it finds a match, it reads the text file and checks to see if the password (encrypted) matches the one they entered. if some part of the login does not work, they are redirected to a page (maybe dynamically created) saying that they could not login because _____. if they do login, they are able to browse pages within the website and see information that their authorization level allows. (each page has content that can be displayed or hidden - using php - depending on the authorization level, where the higher the level, the more you can see)

thank you greatly for any assistance you give

Oh happyland!
__________________
----------------------------
Aeon of Darkness MUD - Free Online Roleplaying Game
http://aeonofdarkness.com
 
Old June 9th, 2003, 08:43 PM
Authorized User
 
Join Date: Jun 2003
Location: , , .
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Nat,

Here is a start for you on how to get a login script working, it is only a start but will give you the idea for progressing it further into a 'level of authentication' script. This only needs 2 criteria from the html form to get past the header section, username & password.

[php]
#ensure both form fields have entries
if( (!$username) or (!$password) )
{

  header("Location:login.php");
      exit();
}
$username = addslashes(trim( $username));
$password = addslashes(trim( $password));

$conn=@mysql_connect("**********", "*****", "*******")
         or die("Could not connect");

#select the specified database
$rs = @mysql_select_db("dbname", $conn)
        or die("Could not select database");

#create the query
$sql="select * from homes where username=\"$username\" and password = password(\"$password\") ";

#execute the query
$rs=mysql_query($sql,$conn)
        or die("Could not execute query");

#get number of rows that match username and password
$num = mysql_numrows($rs);

#if there is a match the log-in is authenticated
if($num != 0)
{ $msg = "<h3>Welcome - your log-in succeeded!</h3>";}
else
{
  #otherwise go back to the log-in page
  header("Location:login.php");
  exit();
}
[php]

if all is OK then go to <HTML> page..
 
Old June 10th, 2003, 01:19 PM
Authorized User
 
Join Date: Jun 2003
Location: , , USA.
Posts: 83
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to natmaster Send a message via AIM to natmaster Send a message via MSN to natmaster
Default

thank you for your help, but i also wanted each page to know who has logged on, not just an initial login so i can exclude certain information from some people, any ideas on how to do that?
(also, i am running my website off of server space i bought, and the owners will not install mysql, but they said that i could install it in my space if i wanted, but i haven't been able to figure that out, so i was going to use text files to store everyone's data, or someone could help me out in figuring out how to install mysql)
 
Old June 10th, 2003, 03:37 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Wien, Wien, Austria.
Posts: 158
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to NotNowJohn
Default

You can authenticate user and retreive his info in header.php file and include this file on all pages you need.
In that way user's info will be available on all pages.

HTH.

...but the Soon is eclipsed by the Moon
 
Old June 10th, 2003, 03:55 PM
Authorized User
 
Join Date: Jun 2003
Location: , , USA.
Posts: 83
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to natmaster Send a message via AIM to natmaster Send a message via MSN to natmaster
Default

but how will i keep them from having to login each time? will i have to use a cookie?

thx for ur help so far :)

Oh happyland!
 
Old June 11th, 2003, 03:19 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Wien, Wien, Austria.
Posts: 158
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to NotNowJohn
Default

Yes, you can use cookies or sessions.
When user submit his credentials for the first tame you can send a cookie to his browser, and in the authentication routine you have to check if the cookie exists (and what is the cookie's value), or if the session variable exists...
Do you need some code?

...but the Soon is eclipsed by the Moon
 
Old June 11th, 2003, 01:05 PM
Authorized User
 
Join Date: Jun 2003
Location: , , USA.
Posts: 83
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to natmaster Send a message via AIM to natmaster Send a message via MSN to natmaster
Default

well i created some code with cookies, but i know some ppl don't like cookies......so what is this about sessions, how does that work?

----------------------------
Oh happyland!
 
Old June 11th, 2003, 02:22 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Wien, Wien, Austria.
Posts: 158
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to NotNowJohn
Default

In session's mechanism all user related things are temporary saved on the Web server in the similar manner as the cookie exists on the client machine.
When a user request the page from the server for the first time, Server assign to this session a Session ID value (unique) and further communication between browser and server is based on this value.

User can send this Session ID either by cookie, posting a hidden field value and adding it on the end of the query string, so the cookies can be disabled.

Implementation of this is simple - with a few line of code you will save some user specific values between requests, but the server must be properly configured, and some problems may occurs when the site is hosted by the Web farm...



...but the Soon is eclipsed by the Moon
 
Old June 12th, 2003, 07:07 PM
Authorized User
 
Join Date: Jun 2003
Location: , , USA.
Posts: 83
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to natmaster Send a message via AIM to natmaster Send a message via MSN to natmaster
Default

well what kind of code would i need? and by web farm, do you mena many people buying webspace on one server?

----------------------------
Oh happyland!
 
Old June 19th, 2003, 03:06 PM
Friend of Wrox
Points: 2,570, Level: 21
Points: 2,570, Level: 21 Points: 2,570, Level: 21 Points: 2,570, Level: 21
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: San Diego, CA, USA
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

A web farm is when many servers are used for the same website. High-traffic sites need to have several servers handling requests for the same pages. The distribution of requests is called load balancing -- you want to make sure that none of your servers are more bogged down with requests than any other servers.


Take care,

Nik
http://www.bigaction.org/




Similar Threads
Thread Thread Starter Forum Replies Last Post
having a problem with login script dbwieler PHP Databases 1 November 14th, 2007 02:12 AM
login script: user can't hit "return" for login dmerrill Java Basics 13 July 14th, 2006 07:25 PM
login script jstewie Javascript How-To 1 July 13th, 2005 12:52 PM
login script Apocolypse2005 Javascript 3 June 24th, 2005 04:07 PM
login script problem hosefo81 PHP How-To 9 August 20th, 2004 11:28 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.