General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old November 6th, 2002, 06:43 AM
wAr-AnGeL wAr-AnGeL is offline
Forum Security
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Behind You
Posts: 479 wAr-AnGeL User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 m 50 sec
Reputation Power: 7
Send a message via ICQ to wAr-AnGeL Send a message via AIM to wAr-AnGeL
Lightbulb my login script

i know alot of people are wondering on how to make a password protected members area. here's a login script that you can use to verify a user's username & password against the database. it was derived from many other scripts. i have removed some parts like setting cookies... etc. enjoy

PHP Code:
<?php
ob_start
();
mysql_connect("host""username""password");
mysql_select_db("db");

global 
$HTTP_POST_VARS;
$username $_POST["username"];
$password $_POST["password"];

$auth authenticate($username$password);

// username/password correct
if($auth == 1) {
                 
// redirect to members page
    
header("Location: loggedin.php");
        
}

else
// username/password wrong
{
    
// redirect to error page
    
header("Location: [url]http://url.com[/url]");
    
}
ob_end_flush();

function 
authenticate($username$password) {
    
$sql "SELECT * FROM usersTable WHERE username = '$username' AND user_password = md5('$password')";
    
$query mysql_query($sql);

    if(
mysql_num_rows($query) == 1)
        return 
1;
    else
        return 
0;
}
?>


hope the copy & paste worked right. if it doesnt work tell me, i probably pasted something wrong.
__________________




"Only Linux users see the end of crashes."
- Pl4t0

Reply With Quote
  #2  
Old November 6th, 2002, 08:02 AM
Lindset Lindset is offline
weirdomoderator
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Location: Alta, Norway
Posts: 370 Lindset User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to Lindset Send a message via AIM to Lindset
Nice You don't need the line 'global $HTTP_POST_VARS;', though

and instead of having the multiline if structure at the end of the array, you could use this type of conditional

PHP Code:
return mysql_num_rows($query) ? true false


At least I think that's nicer

oh, and after the header() functions, you might want to exit;.. because I think it's possible to for example write a client that ignores Location headers




I found an error in this line: (I'm guessing that error got in while making it ready for posting)

header("Location: <a href="http://url.com" target="_blank">http://url.com</a>");


change it to

header('Location: <a href="http://url.com" target="_blank">http://url.com</a>');


or

header("Location: <a href=\"http://url.com\" target=\"_blank\">http://url.com</a>");

(I prefer the first one)
__________________
Best Regards,
Håvard Lindset

Reply With Quote
  #3  
Old November 6th, 2002, 11:58 AM
jpenn jpenn is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Washington, DC
Posts: 317 jpenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 3 sec
Reputation Power: 6
Just a question -> why are you using '$HTTP_POST_VARS' which is now depreciated?
__________________
~ Joe Penn

We work for free to help make this a valuable resource on the internet. Do you appreciate the help - did we provide help that will help you prosper and help that has contributed to sharpening your current skill set?

Show your appreciation and purchase something from our Amazon Wishlist's - it's simple and a great way to say thank you.




Reply With Quote
  #4  
Old November 6th, 2002, 12:48 PM
infamous-online infamous-online is offline
Moderator
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Posts: 404 infamous-online User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 24 m 44 sec
Reputation Power: 7
please guys don't bash me but how does this exactly work. i want to know exactly what does this script do. again don't bash me...
__________________
Apache Expert

Reply With Quote
  #5  
Old November 6th, 2002, 02:08 PM
Lindset Lindset is offline
weirdomoderator
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Location: Alta, Norway
Posts: 370 Lindset User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to Lindset Send a message via AIM to Lindset
Quote:
Originally posted by jpenn
Just a question -> why are you using '$HTTP_POST_VARS' which is now depreciated?


he's not actually using it, he's just declaring it as a global variable.. as I pointed out in the post above

btw, what's that xuldeveloper going to be?

Reply With Quote
  #6  
Old November 6th, 2002, 04:15 PM
jpenn jpenn is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Washington, DC
Posts: 317 jpenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 3 sec
Reputation Power: 6
Quote:
he's not actually using it, he's just declaring it as a global variable.. as I pointed out in the post above

Well, thats pretty much what I meant - why is it in his code as that syntax when it is depreciated - sorry, should of asked the question as that.......

Reply With Quote
  #7  
Old November 6th, 2002, 05:38 PM
wAr-AnGeL wAr-AnGeL is offline
Forum Security
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Behind You
Posts: 479 wAr-AnGeL User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 m 50 sec
Reputation Power: 7
Send a message via ICQ to wAr-AnGeL Send a message via AIM to wAr-AnGeL
Quote:
Originally posted by jpenn
Just a question -> why are you using '$HTTP_POST_VARS' which is now depreciated?


my server is weird. if use $_POST without declaring $HTTP_POST_VARS global it won't work.

as for the header error, yes it was an error i think dreamweaver automatically changed it into html format. it's originally: header("Location: http://url.com");

Reply With Quote
  #8  
Old November 6th, 2002, 07:18 PM
Ben Rowe
Guest
Dev Articles Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Im currently writing a 6 part series on creating a members area, make sure to keep an eye out for it, its going to be huge

Reply With Quote
  #9  
Old November 7th, 2002, 01:12 AM
Lindset Lindset is offline
weirdomoderator
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Location: Alta, Norway
Posts: 370 Lindset User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to Lindset Send a message via AIM to Lindset
Quote:
Originally posted by wAr-AnGeL


my server is weird. if use $_POST without declaring $HTTP_POST_VARS global it won't work.

as for the header error, yes it was an error i think dreamweaver automatically changed it into html format. it's originally: header("Location: http://url.com");


yeah, that is weird.. $_POST is a "superglobal" array, and should be available in all scopes

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > my login script


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT