5, December 2008

repeating result with login function - webmaster forum

 
Webdigity webmaster forums
This forum shares its ad revenue with its members!
[ Home | Help | Search | Forum's Shop | Archive | Login | Register | Webmaster Directory ]
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: repeating result with login function
« previous next »
Pages: [1] Print

Author Topic: repeating result with login function  (Read 479 times)
aka J Love
Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
Posts: 884
1636 credits
Members referred : 4



« on: Jan 21, 2007, 08:18:25 AM »

Code:
<?php
ob_start
();  
require("config.php"); 
if (!
$logged['username']){ 
if (!$_POST['login']){ 
echo "<center><form method='POST'><table><tr> <td align='center'> 
Username: <input type='text' size='15' maxlength='25' name='username'> 
</td></tr><tr><td align='center'>
Password: <input type='password' size='15' maxlength='25' name='password'> 
</td></tr><tr><td align='center'><input type='submit' name='login' value='Login'> 
</td></tr><tr><td align='center'><a href='?open=16'>Register Here</a><br>
<a href='?open=13' alt='Click here to reset your password'>Forgot Password?</a>
</td></tr></table></form></center>"


if ($_POST['login']){ 
$username $_POST['username']; 
$password md5($_POST['password']); 
$info mysql_query("SELECT * FROM users WHERE username = ".$username) or die(mysql_error()); 
$data mysql_fetch_array($info); 
if($data['password'] != $password){ 
echo "<B>Incorrect username or password!</B>\n"
include('login.php');
} else { 
$query mysql_query("SELECT * FROM users WHERE username = '$username'") or die(mysql_error()); 
$user mysql_fetch_array($query); 
setcookie("id"$user['id'],time()+(60*60*24*5), "/"""); 
setcookie("pass"$user['password'],time()+(60*60*24*5), "/"""); 
echo "<meta http-equiv='Refresh' content=\"'0'; URL='http://www.sleekpixel.net'\">Thank You! Please wait for page refresh.\n"


} else { 
$new mysql_query("SELECT * FROM pmessages WHERE unread = 'unread' AND touser = ".$logged['username']); 
$new mysql_num_rows($new); 
echo ("<meta http-equiv='Refresh' content=\"'0'; URL='http://www.sleekpixel.net'\">Thank You! Please wait for page refresh.\n"); 

?>

The problem here is when you enter the wrong password for a user account which does happen to exist. It repeats this line:

Code:
<?php
echo "<B>Incorrect username or password!</B>\n"?>


Screenshot of result of error:

« Last Edit: Jan 21, 2007, 08:24:14 AM by Meth0d »

Visit through proxy Visit through proxy Visit through proxy

Last blog : phpHaze 1.59.1 in Development
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 8272
42619 credits
Members referred : 3



« Reply #1 on: Jan 21, 2007, 01:34:28 PM »

The problem is not the login function, but that you include the login function page more than once in the left sidebar (probably inside of a loop?)

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy or twitter Visit through proxy

Last blog : Free Unlimited Bandwith and disk space to good to be true?
aka J Love
Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
Posts: 884
1636 credits
Members referred : 4



« Reply #2 on: Jan 21, 2007, 05:02:32 PM »

hmm so how do i accomplish the same task and remove it from repeating in this loop?

edit- after rexamining the code i noticd that i included login.php inside of the incorrect password coding, where the name of the page u see for that code is already login.php, created a new page login_panel.php which is the code for displaying the login box , and then included that instead, along with some other syntax changes

new code

Code:
<?php
ob_start
();  
require("config.php"); 
if (!
$logged['username']){ 
if (!$_POST['login']){ 
include('login_panel.php');

if ($_POST['login']){ 
$username $_POST['username']; 
$password md5($_POST['password']); 
$info mysql_query("SELECT * FROM users WHERE username = '".$username."'") or die(mysql_error()); 
$data mysql_fetch_array($info); 
if($data['password'] != $password){ 
echo "<B>Incorrect username or password!</B><br>\n"
include('login_panel.php');
} else { 
$query mysql_query("SELECT * FROM users WHERE username = '".$username."'") or die(mysql_error()); 
$user mysql_fetch_array($query); 
setcookie("id"$user['id'],time()+(60*60*24*5), "/"""); 
setcookie("pass"$user['password'],time()+(60*60*24*5), "/"""); 
echo "<meta http-equiv='Refresh' content=\"'0'; URL='http://www.sleekpixel.net'\">Thank You! Please wait for page refresh.\n"


} else { 
$new mysql_query("SELECT * FROM pmessages WHERE unread = 'unread' AND touser = ".$logged['username']); 
$new mysql_num_rows($new); 
echo ("<meta http-equiv='Refresh' content=\"'0'; URL='http://www.sleekpixel.net'\">Thank You! Please wait for page refresh.\n"); 

?>



new page login_panel.php

Code:
<?php
echo "<center><form method='POST'><table><tr> <td align='center'> 
Username: <input type='text' size='15' maxlength='25' name='username'> 
</td></tr><tr><td align='center'>
Password: <input type='password' size='15' maxlength='25' name='password'> 
</td></tr><tr><td align='center'><input type='submit' name='login' value='Login'> 
</td></tr><tr><td align='center'><a href='?open=16'>Register Here</a><br>
<a href='?open=13' alt='Click here to reset your password'>Forgot Password?</a>
</td></tr></table></form></center>"

?>
« Last Edit: Jan 21, 2007, 05:36:55 PM by Meth0d »

Visit through proxy Visit through proxy Visit through proxy

Last blog : phpHaze 1.59.1 in Development
Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=5714
Tags : php login function Bookmark this thread : Digg Del.icio.us Dzone more....

Topic sponsors:
Get a permanent link here for $1.99!


Pages: [1] Print 
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: repeating result with login function
« previous next »
Jump to:
User Area
Welcome, Guest. Please login or register.
Did you miss your activation email?
Dec 05, 2008, 09:42:11 AM





Login with username, password and session length

Donate to our community, and get a permanent link back to your site!

Donate to our community, and get a permanent link back to your site!


Forum Statistics
Total Posts: 37.995
Total Topics: 7.685
Total Members: 4.470
Tutorials : 56
Resources : 143
Designs : 220
Latest Member: srinivasarao

22 Guests, 5 Users online :

10 users online today:



Readers

Web Design Gallery · Whois Lookup · Pagerank · Tag Browsing · Lo-fi version · Syndication · Webmaster forum history · Advertise
Developed by HumanWorks © 2005 - 2008 Webdigity webmaster community · sublime directory
Webdigity Webmaster Forums | Powered by SMF 1.0.12. © 2001-2005, Lewis Media. All Rights Reserved.