Current location: Hot Scripts Forums » Programming Languages » PHP » login script


login script

Reply
  #1 (permalink)  
Old 12-23-08, 07:00 AM
chazze06 chazze06 is offline
Newbie Coder
 
Join Date: Apr 2008
Location: Pangasinan, Philippines
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
login script

uhm.. this is my first time to make a php script.. how can i make a login script that goes this way:

if login is successful goto loggedinpage
if not then it stays in the same page and shows a message that says login failed..

can anyone please help..
Reply With Quote
  #2 (permalink)  
Old 12-23-08, 07:47 AM
therocket954's Avatar
therocket954 therocket954 is offline
Community Liaison
 
Join Date: Jul 2007
Location: Michigan, USA
Posts: 334
Thanks: 2
Thanked 8 Times in 8 Posts
One of your best options is to Google "PHP login script", you'll find literally hundreds of different code snippits... you'll probably find quite a few searching these boards too A great way to "learn" if that's what you're looking to do.

If you want a script to get you up and running, you can also check out hotscripts.com under PHP -> Scripts & Programs -> User Authentication. Tons of stuff there to do exactly what you're looking to do.

Hope this helps!
__________________
--Eric Allison
Twitter: http://www.twitter.com/Eric_Allison
Reply With Quote
  #3 (permalink)  
Old 12-23-08, 09:04 PM
xTROEngine.com xTROEngine.com is offline
New Member
 
Join Date: Dec 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
try to this

PHP Code:

function vblogin($site$coo$username$password)
{
//echo $site, $coo, $username, $password;
$passwordMD5=md5($password);
$ch curl_init();
curl_setopt($chCURLOPT_COOKIEJAR$coo);
curl_setopt($chCURLOPT_URL$site .  "/login.php?do=login");
curl_setopt($chCURLOPT_POST1);
curl_setopt($chCURLOPT_POSTFIELDS"vb_login_username=" $username "&vb_login_password=" $password "&s=&do=login&vb_login_md5password=" $passwordMD5 "&vb_login_md5password_utf=" $passwordMD5);
ob_start();      // prevent any output
$buf="0";
$buf=curl_exec ($ch); // execute the curl command
$ee=$buf;
ob_end_clean();  // stop preventing output
curl_close ($ch);
unset(
$ch);
return 
$ee;
}

function 
linkoku($url$coo$post)
{
global 
$db;
$ch curl_init();
curl_setopt($chCURLOPT_RETURNTRANSFER,1);
curl_setopt($chCURLOPT_COOKIEFILE$coo);
curl_setopt($chCURLOPT_HEADER1);
curl_setopt($chCURLOPT_URL$url);
curl_setopt($chCURLOPT_POST1);
curl_setopt($chCURLOPT_POSTFIELDS$post);
curl_setopt($chCURLOPT_FOLLOWLOCATION1);
ob_start();      // prevent any output
$buf="0";
$buf=curl_exec ($ch); // execute the curl command
ob_end_clean();  // stop preventing output
curl_close ($ch);
unset(
$ch);
return 
$buf;

$cookies="xTRO";

vblogin('http://xtroengine.com', $cookies, 'Username', 'Password');
echo linkoku('http://xtroengine.com', $cookies, '');

Last edited by Nico; 12-24-08 at 02:07 AM.
Reply With Quote
  #4 (permalink)  
Old 12-23-08, 10:57 PM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
No offense, xTROEngine, but why in the world would you use cURL for a simple login script?
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data | Oracle Date & Substring Functions | Code Snippet Library | [url=http://www.codmb.com/Call Of Duty[/url]
Reply With Quote
  #5 (permalink)  
Old 12-24-08, 03:38 AM
DAL's Avatar
DAL DAL is offline
Code Master
 
Join Date: Jun 2003
Location: North East England/UK
Posts: 874
Thanks: 0
Thanked 0 Times in 0 Posts
chazze06 you're going to need to store the usernames and passwords somewhere, probably the easiest way to do this is MySQL although it is something else to learn but once you do, you will use it constantly to store all sorts.

Plenty tutorials out there for both php and Mysql, I dont know what you have installed to run your scripts but if it didnt come with MySQL then consider xampp from Apache Friends for all your needs.

$_SESSIONS are also going to be your friend throughout your time with php... I've never once used a cookie* so can't say that your going to need them however thats my own personal pref so you might find a need for them.

*Actually $_SESSION refs are stored as cookies but it all automatic

Kind regards
Dal
__________________
"once upon a midnight dreary, while i pron surfed, weak and weary, over many a strange and spurious site of 'hot xxx galore'. While i clicked my fav'rite bookmark, suddenly there came a warning, and my heart was filled with mourning, mourning for my dear amour," 'Tis not possible!", i muttered, "give me back my free hardcore!" quoth the server, 404."
Reply With Quote
  #6 (permalink)  
Old 12-24-08, 09:41 AM
Jambone Jambone is offline
Newbie Coder
 
Join Date: Oct 2008
Location: Solihull, UK
Posts: 45
Thanks: 1
Thanked 0 Times in 0 Posts
HTML Code:
Username: <input type="text" name="username">
Password: <input type="password" name="password">
<input type="submit" name="submit" value="Submit">
PHP Code:

require_once('mysql_connect.php');

$submit $_POST['submit'];
$username$_POST['username'];
$password $_POST['password'];
$password_1 md5($password'];
$username_r = mysql_real_escape_string($username);
$password_r = mysql_real_escape_string($password_1);
$query = MYSQL_QUERY("SELECT * FROM `users` WHERE Username = $username_r AND Password = $password_r")

if($submit) {
if(empty($username) || empty($password)) {
echo '
Please complete all fields';
} else {
session_start();
$_SESSION['
[B]session_name[/B]'] = $Username; //Add $username as you can echo it out by doing - echo $_SESSION['session_name'];
if($_SESSION['
session_name'] {
header ('
location: [B]newpage.php[/B]');
}
}


Last edited by Jambone; 12-24-08 at 09:44 AM.
Reply With Quote
  #7 (permalink)  
Old 12-24-08, 10:31 AM
Jambone Jambone is offline
Newbie Coder
 
Join Date: Oct 2008
Location: Solihull, UK
Posts: 45
Thanks: 1
Thanked 0 Times in 0 Posts
^ Just noticed - ignore the bold tags in the php, they were just meant to emphasize the parts you could change.

Last edited by Jambone; 12-24-08 at 10:56 AM.
Reply With Quote
  #8 (permalink)  
Old 12-24-08, 12:12 PM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
I think that this:

PHP Code:

$query MYSQL_QUERY("SELECT * FROM `users` WHERE Username = $username_r AND Password = $password_r"
should actually be this:

PHP Code:

$query MYSQL_QUERY("SELECT * FROM `users` WHERE Username = $username_r"
If a match is found, check to see if the password matches the one submitted. This way of doing things is intended to help prevent some common SQL injection attempts.
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data | Oracle Date & Substring Functions | Code Snippet Library | [url=http://www.codmb.com/Call Of Duty[/url]
Reply With Quote
  #9 (permalink)  
Old 12-24-08, 12:54 PM
Jambone Jambone is offline
Newbie Coder
 
Join Date: Oct 2008
Location: Solihull, UK
Posts: 45
Thanks: 1
Thanked 0 Times in 0 Posts
Ah, my bad
Reply With Quote
  #10 (permalink)  
Old 12-25-08, 04:28 AM
chazze06 chazze06 is offline
Newbie Coder
 
Join Date: Apr 2008
Location: Pangasinan, Philippines
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
to sir xTROEngine.com,
i find it hard to understand the script you posted but i really appreciate the help..

to sir Jambone,
what's the use of the require_once and md5 function? i'm sorry for the st**d question..
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Login script - Secure? Deansatch PHP 5 06-05-08 12:16 PM
Looking for help with a PHP Login script... garry2005 PHP 5 10-10-05 09:00 PM
login script works fine in firefox, nothing in IE! varial PHP 3 03-14-05 08:36 AM
Login script not working in frame... varial PHP 6 03-04-05 09:26 AM


All times are GMT -5. The time now is 08:25 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.