Authentication Script - PHP Help #2 -- I need help tweaking it - it won't work

free web hosting
Free Web Hosting > Computers & Tech > Programming > Scripting > PHP

Authentication Script - PHP Help #2 -- I need help tweaking it - it won't work

FirefoxRocks
Okay, my first issue about the MySQL echo problem has been solved, thank you to those who helped. smile.gif
Now I am focusing on the login portion of my site, and I have this so far:
CODE
<?php
// we must never forget to start the session
session_start();

$errorMessage = '';
if (isset($_POST['username']) && isset($_POST['password']))
    {
   $username = $_POST['username'];
   $password = $_POST['password'];
//Connect to database
$con = mysql_connect("localhost","myDatabaseUsername","myDatabasePassword");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("myTable2", $con);
   // check if the user id and password combination exist in database
   $sql = "SELECT name FROM users WHERE name = '$username' AND password = PASSWORD('$password')";
   $result = mysql_query($sql) or die('Query failed. ' . mysql_error());
   if (mysql_num_rows($result) == 1)
     {
      // the user id and password match, check for authorization
            $sql_a = "SELECT auth FROM users WHERE auth = '$auth'";
            $result = mysql_query($sql_a)
             or die('Query failed. ' . mysql_error());
            if ($result == YES)
      // set the session
      $_SESSION['db_is_logged_in'] = true;
      // after login we move to the main page
            header("(anti-spam-content-type:) $mime;charset=$charset");
      header('Location: moderate.php');
      exit;
   }
     else
     {
     $errorMessage = 'Sorry, wrong user id / password';
     header("(anti-spam-content-type:) $mime;charset=$charset");
     }
    }
?>


I cannot figure out what is wrong with this! I tried moving parts around, removing parts, didn't work. It is on XKingdom Moderator Login. I have made an example account user Trap17 password 123 for testing purposes to help if necessary. Feel free to mess around with my code, I'm not very good at PHP. tongue.gif

 

 

 


Reply

faulty.lee
One of the most important thing to learn in programming is to "Troubleshoot". So you need to first troubleshoot where is your problem. This is where debugging comes in. Simplest way to debug in php is "echo" or "print".

I've tried your link, the the authentication failed. So, you should find out why it fail.
CODE
else
     {
         //Add echo here
     $errorMessage = 'Sorry, wrong user id / password';
     header("(anti-spam-(anti-spam-content-type:)) $mime;charset=$charset");
     }

You should maybe try to echo the number of rows, since you're checking the number of rows to determine the first step of authentication. Maybe it's returning 2 instead of 1. Maybe you have 2 identical record with the same username and password. To prevent identical username, you can either enable "unique" on the username column or do a check before you insert any new username. The later one is preferable, simply because you want to allow deleted/terminated username to be reuse.

On the second check
CODE
$sql_a = "SELECT auth FROM users WHERE auth = '$auth'";

i don't see the var $auth being initialized. What value should it contain?

That should get you started. But before you go futher, i have a few personal tips, might not be the most appropriate one, but should help you in your case.

1. For you second check, $auth, you should do it in 1 query.
CODE
//before
   $sql = "SELECT name FROM users WHERE name = '$username' AND password = PASSWORD('$password')";
  //after
   $sql = "SELECT name FROM users WHERE name = '$username' AND password = PASSWORD('$password') AND auth = '$auth'";

You can do this, since auth is compulsory. Or you can also retrive the value of auth from the db, then compare later.
CODE
//before
   $sql = "SELECT name FROM users WHERE name = '$username' AND password = PASSWORD('$password')";
  //after
   $sql = "SELECT name, auth FROM users WHERE name = '$username' AND password = PASSWORD('$password')";
   $result = mysql_query($sql) or die('Query failed. ' . mysql_error());
   if (mysql_num_rows($result) == 1)
   {
        $row_result = mysql_fetch_array($result)
        if ($row_result['auth'] == $auth)
        {
            //success
        }


Good luck

 

 

 


Reply


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.

Recent Queries:-
  1. reuse phpbb3 authentication - 271.84 hr back. (1)
Similar Topics

Keywords : authentication, script, php, 2, tweaking, work

  1. Domain Transfers
    How do they work? (1)
  2. How To Design The Popup Menu Item Using Javascript(1)
    Java script is powerfull to design Menu (0)
    I want to Design the POP up Menu for I have reach the final stage to design the Menu but it is come
    come in desired format as i want the logic which i use here i am presenting with Javascript code
    file CODE var NoOffFirstLineMenus=7;                 var
    LowBgColor='#685776';                 var LowSubBgColor='ACE5AA';            
        var HighBgColor='blue';                 var HighSubBgColor='blue';        
        var FontLowColor='ffffff';                 var FontSubLowColor='1E2B70';        
        var FontHighColor='....
  3. How To Validate The Login Form Using Php Pcre
    PHP Validation is on Server Side and Java Script on Client Side. (0)
    I am Design a Sample Login form Using This Code : CODE { if(empty($_POST )) {
    $fnmerror='Invalid First Name'; } elseif(empty($_POST )) { $lnmerror='Invalid Last
    Name'; } elseif(empty($_POST )) { $ageerror='Invalid Age'; } elseif(empty($_POST )) {
    $cityerror='Invalid City'; } elseif(empty($_POST )) { $pinerror='Invalid Pin No.'; }
    elseif(empty($_POST )) { $moberror='Invalid Mobile No.'; } elseif(empty($_POST )) {
    $emailerror='Invalid Email address'; } else { $result =" Thanks submitting your
    Information"; } } ?....
  4. Hard To Work With Spyware
    (5)
    I have a virus or a sort which disallows me to open the following things. .exe's / .lnk's I
    cannot even open my nortan and that didn't even detect it. I need major help. My OS is Windows
    XP Professional.....
  5. [fl]snow Effect
    Simple Snow Efect Script (4)
    Here is a simple snow script that i will show you. Its pretty nice /smile.gif"
    style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" />. Let's get started.
    1.Draw a snow flake. (Using circle tool) 2.Select it and conert it to a symbol ( Ctrl+F8 ). Press
    movie clip, but don't click "ok" yet. Where it says "Linkage" click on export for action script.
    3.For identifier put in, "flake". 4.Than put in following action script: CODE amount = 100;
    mWidth = Stage.width; mHeight = Stage.height; for (var i = 0; i thisFlake =
    this.attachMovie("flake", "fla....
  6. Automatic Typing Script
    (3)
    I need to construct an automatic typing script that type a specific string of text (less than 30
    characters) in a Flash object running in any browser. It must be run in Windows. What programming
    language do I do this in? How do I do it? Another option is to have a GreaseMonkey script to do
    this within Firefox. But I have no clue how to do this. The program needs to "type" a predefined
    string into a Flash object (there isn't a text field in the Flash object). Timing must be
    controllable so that the program types 5 characters per second or whatever I define it to. T....
  7. Type Checking Not Work On For .. In Loop
    Flash 8 - actionscript 2.0 (2)
    It seems that the actionscript 2.0 type checking was not work as expected on some place. When
    variables was created on for .. in loop. It will allow any variable type to be used. Or it is
    default construt !? CODE var dayNames1:Array = ; for (var dayName:String in dayNames1) {
        trace(dayNames1 );     trace(typeof(dayNames1 )); } CODE 5 number Tuesday string Monday
    string Sunday string ....
  8. Cpu Upgrade But It Doesn't Work
    (11)
    Okay, so, here's the deal. The guy who originally installed my old CPU installed it in a manner
    that the fan on top of it melted off any product numbers and all that. All I know is that the place
    it hooks into says mPGA478B. It was originally a Celeron. Well, when taking it out, the pins were
    bent, so I needed to buy a new one. I went online to find one, searched the mPGA478B thing, cross
    referenced it with the Dell, it said everything was a-okay. BUT, once I received it, it didn't
    work. The new one is an Intel Pentium 4, Northwood Core 478 Socket with spe....
  9. Myspacetv Download Php Script Help
    (6)
    I was trying to make a php script that can view myspace videos with jw flv player and wont to know
    how to do so if i put in
    "http://vids.myspace.com/index.cfm?fuseaction=vids.individual&videoid=38105626" it show the video
    "http://cache01-videos02.myspacecdn.com/11/vid_e382054c036835500bacfef1ebb5157e.flv(its the flv
    video file from myspacetv), I cant see the similarity with the links please help, thanks for viewing
    this topic /smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" />....
  10. Creating A Php Login Script
    A thorough look at the process behind it (3)
    Hey all, after reading through a fair number of tutorials on this subject I decided to write a
    pretty detailed one myself. Apologies for those who don't like my structured layout, it's
    just the way I do things. /wink.gif" style="vertical-align:middle" emoid=";)" border="0"
    alt="wink.gif" /> Title: Creating a PHP Login Script Objective: To go through a series of basic
    steps required to create a method of user registration, login and permission management using PHP
    and MySQL. Notes: The information is designed to work fully on AstaHost's hosting plans. ....
  11. Choice Of Motherboard For Linux Virtualization
    Who knows which ones work well? (5)
    Virtualization is a relatively arcane subject, but it is one which is very rapidly growing, and
    apparently very "hot" in commercial enterprises. For the hobbyist with multiple computers (I have
    8), it offers the possibility of taking snapshots of running, fully configured applications and
    operating systems, and transferring some or all of them onto a single computer platform. First, it
    saves energy. Second, once the conversion has been made from real hardware to a virtual "guest,"
    the driver problems associated with moving from one hardware platform to another are sol....
  12. Need Help Making My Ftp Work
    my ftp is not working (14)
    I get this message: Status: Resolving IP-Address for ftp.losangelesmagazine.net Status: Connecting
    to 68.178.232.100:21... Error: Connection timed out Error: Could not connect to server I have used
    this this ftp before so I know it works. Is there any help anyone can give me? I would really
    appreciate any help with this and anyother topic I posted as I just activated my account today and
    I'm trying to figure out what to do to make this work so I can upload wordpress. I used the
    server and users name that I saw on cpanel and the message above is what I got. Tha....
  13. Looking For Script
    need help (5)
    i am making a web site about cell phones (tones-themes-wallpapers) and i am looking for good script
    for my site with some nice options ....can any body help me /rolleyes.gif"
    style="vertical-align:middle" emoid=":rolleyes:" border="0" alt="rolleyes.gif" />....
  14. Myspace Gold Script
    How to install (2)
    Hello, I have a MySpace Gold Script but do not know how to use it. Can someone help!? I have a
    MySpace gold script, this will let me build my own social networking site. I dont know much about
    MySQL or Myphpadmin. This is my installation instructions To start with open the mainfile.php and
    edit the settings to reflect your own. You will need to know your mysql database settings. If you do
    not know what these are please ask you webhost and they will provide them to you. After this file
    has been edited to your server settings, make sure that it is chmod to 444 (read only....
  15. I6networks....does Not Work!
    (4)
    This hosting site (i6networks.com)should be avoided at all costs ,its a big waste of time.......
    They send the confirmation email four days late (and it is supposed to be "automated") And heres
    exactly what they send QUOTE === Please print for future reference === 2008/02/16
    Congratulations! Your web hosting account is ready! This e-mail contains basic setup instructions
    and details on the features of your hosting package. For more information you can always reference
    our online customer support area at: http://www.i6networks.com/support.shtml ---------------....
  16. Auto-click Script
    (7)
    I wanna know how to make a "auto-click" script in web browser.... i want it to do this: I am on a
    web page...I have 3 options to click....so i want it to click one,after it reloads it waits for 25
    seconds and clicks 2nd,and again waits to reload and that 25 seconds and clicks 3rd option... is it
    possible to create that kind of script?it would be better if it was executable program so u can set
    it where exactly it should click... if you don't understand some of things i said tell me and i
    will "translate" it into English XD....
  17. A Simple Register Script
    This Is a Very Simple Register-Script (3)
    Some time ago, i made a login-script. But how do you use a login-script, if you can't register.
    So this morning, I decided to make a register-script.. What you should already know: The php
    basics and a little more. How to use php and mysql together. The HTML basics (to make the forms).
    The first thing we should do, is creating the database tables. Here is the code: CODE CREATE
    TABLE `user` (   `id` int(4) unsigned NOT NULL auto_increment,   `username` varchar(32) NOT NULL,
      `password` varchar(32) NOT NULL,   `level` int(4) default '1',   PRIMARY K....
  18. Attack Script In Php
    This is a funny attack script that i made (5)
    Hey! I am going to share an attack script that i made for some time ago. I made it, as a test for
    my game.. And ofc, you can use it for your game to. It is still version 1.0. But I want you to learn
    something from it /wink.gif" style="vertical-align:middle" emoid=";)" border="0" alt="wink.gif" />
    This is my second tutorial here, and I will try to make it better than my first one /smile.gif"
    style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> Here is the SQL File.
    CODE CREATE TABLE `characterss` (   `health` int(200) NOT NULL default '10....
  19. Very Simple Login-script
    This is a very simple and secure login-script (18)
    Hi. This is my first post here. please Tell me if i do something wrong. This is a very simple and
    secure login script. I will try to add as many comments as possible, to make it easier to
    understand. Lets start with the database. Just make a new SQL file, and call it whatever you want.
    Paste this code: CODE CREATE TABLE `user` (   `id` int(4) unsigned NOT NULL auto_increment,
      `username` varchar(32) NOT NULL,   `password` varchar(32) NOT NULL,   `level` int(4) default
    '1',   PRIMARY KEY  (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=27 DEFAULT CHARSET=latin1; ....
  20. Theme Hospital Cheats Don't Work
    (10)
    QUOTE Cheat Mode - To enter the cheat mode, press 2,4,3,2,8, on the fax machine. Extra $10,000 -
    While in cheat mode, press + C together. I tried that and a few others but nothing happens.
    It's Xp.....
  21. Need A Javascript To Enable / Disable Buttons
    I need a script! (2)
    Hey... I need a javascript script(I think its java) What i want the script to do: You have 2
    buttons on a page 1 is a enter a different part of the site the other one is a vote which brings up
    a pop-up page. i want the script to make it so you have to click the vote button before being able
    to click the enter button. If you can do it, Thanks. post the script here....
  22. Running Vba Script In Excel
    (7)
    Hi, I need help. Im generating a excel file using jakarta poi. I have added a vba to my excel
    template so that it creates a chart on file open using the data populated using the poi map. Now
    this works fine in a windows machine. But on a linux machine the vba does not execute. I need to
    release my prod in linux too and im losing time. Is there any workaround for this???? Thanks in
    advance Karthik....
  23. PHP Tutorial: Form Verification And Simple Validation
    A One Page script for PHP form verification. (12)
    Having used various means of verifying HTML forms I believe that this method of verifying a form
    to be the best mostly because it does everything on one page. It presents the form on one page and
    then when the submit button is pressed, if all the required fields are not filled out then it will
    present the form again with all the fields intact and in red lettering will point out the fields
    that are required to be filled out in red. It is not possible to click submit using this method even
    if the user has turned JavaScript off. While it is possible to use javascript to ....
  24. Plasma Effect In Photoshop
    Done in CS, but should work in other ver (7)
    This is a tutorial to create a plasma background effect. We are trying to get with a few filters.
    Step 1) Press 'D' to reset your colours, choose linear gradient, uncheck all bozes, black
    to white, and go crazy. Step 2)Do a wave filter (filter>distort>wave) and hit randomize a few
    times. Step 3)Press ctrl+j(duplicate layer) and repeat step 2 on the duplicated layer. Set layer
    belnding mode to lighten. Step 4)Repeat steps 2-3 once. Step 5)Press ctrl+u, check colorize, and
    change colour! Congratulations, now you're done!....
  25. Need Help With A PHP - MySQL Registration Script
    Wont INSERT into the database (13)
    hey well can some one helpme make this code work it won't INSERT INTO THE DATABSE CODE #
    register1.php # common include file to MySQL include("DB.PHP"); $Username=$_POST ; $Password=$_POST
    ; $Name=$_POST ; $Last=$_POST ; $Sex=$_POST ; $Month=$_POST ; $Day=$_POST ; $Year=$_POST ;
    $Adresse=$_POST ; $City=$_POST ; $State=$_POST ; $Zipcode=$_POST ; $Country=$_POST ; $Phone=$_POST ;
    $Email=$_POST ; $Father_Name=$_POST ; $Mother_Name=$_POST ; $Parent_Phone=$_POST ;
    $Parent_Email=$_POST ; $Level=$_POST ; $Academic=$_POST ; $Image_Link=$_POST ; $sql9="INSERT INTO
    U....
  26. Help Needed To Create Login Script With Perl/cgi
    Need Script (21)
    Have a format in mind and have a good idea how it works. So here what I need: step 1::: person must
    register: create handle // enter password // enter password // enter email : it then takes the
    person to acsepted page or reject per reason page. step 2::: login page: enter handle // enter
    password : takes them on it to the site of their control pages for each handle controls their own
    pages yet all pages interacts with the others. or bad password re login page. Have the page
    designed already have the script in html lang but one can create a password on the html page but....
  27. Bash Script To Display Your Ip
    Script to display your ip (9)
    If your behind a router , and like me too lazy to open a browser and find a site that displays your
    ip , heres a simple Bash script (Bash is a shell in linux, main shell in Slackware Linux) Open a
    text editor , copy and paste the following: CODE #! /bin/bash exip=`lynx -dump
    http://www.whatismyip.com | head -n 2` echo "$exip" Save the txt ( for the sake of agrument we
    will refer the file as ip.sh) From console type: chmod a+x ip.sh Now run the script like so:
    ./ip.sh (which will display something like the following) Your IP Is XX.X....
  28. How To Save A Image In Pdf File And Download It?
    Programming script need hepl. (10)
    Can anyone tell how to save an image into a PDF file and download it without need to save it on the
    server? Thanks. All sugesstions are welcome! Wrong section. Topic moved to Software > Graphics &
    Web Design. ....
  29. PHP: Writing A Generic Login And Register Script
    (15)
    Now there are basically 3 functions that a user management system provides: login, register, and
    protection. A user management system can do more than this but that is all that this tutorial will
    be covering. I will try to explain what I am doing as I go along but to fully understand what is
    happening you should have a basic knowledge of PHP, SQL, and HTML. This tutorial assumes you are
    using MySQL, adjust accordingly for a different DBMS. First off lets define the database table
    where our users will be stored. Using phpMyAdmin run this statement to create our table....
  30. How To Make A Text Based Online Game Script ?
    (24)
    Does anyone know if there is a easy was to make a text base online game, Like a free templet, or if
    anyone know how to make one and can help me.....

    1. Looking for authentication, script, php, 2, tweaking, work






*SIMILAR VIDEOS*
Searching Video's for authentication, script, php, 2, tweaking, work
Similar
Domain Transfers - How do they work?
How To Design The Popup Menu Item Using Javascript(1) - Java script is powerfull to design Menu
How To Validate The Login Form Using Php Pcre - PHP Validation is on Server Side and Java Script on Client Side.
Hard To Work With Spyware
[fl]snow Effect - Simple Snow Efect Script
Automatic Typing Script
Type Checking Not Work On For .. In Loop - Flash 8 - actionscript 2.0
Cpu Upgrade But It Doesn't Work
Myspacetv Download Php Script Help
Creating A Php Login Script - A thorough look at the process behind it
Choice Of Motherboard For Linux Virtualization - Who knows which ones work well?
Need Help Making My Ftp Work - my ftp is not working
Looking For Script - need help
Myspace Gold Script - How to install
I6networks....does Not Work!
Auto-click Script
A Simple Register Script - This Is a Very Simple Register-Script
Attack Script In Php - This is a funny attack script that i made
Very Simple Login-script - This is a very simple and secure login-script
Theme Hospital Cheats Don't Work
Need A Javascript To Enable / Disable Buttons - I need a script!
Running Vba Script In Excel
PHP Tutorial: Form Verification And Simple Validation - A One Page script for PHP form verification.
Plasma Effect In Photoshop - Done in CS, but should work in other ver
Need Help With A PHP - MySQL Registration Script - Wont INSERT into the database
Help Needed To Create Login Script With Perl/cgi - Need Script
Bash Script To Display Your Ip - Script to display your ip
How To Save A Image In Pdf File And Download It? - Programming script need hepl.
PHP: Writing A Generic Login And Register Script
How To Make A Text Based Online Game Script ?
advertisement




Authentication Script - PHP Help #2 -- I need help tweaking it - it won't work



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute your information that might help someone here.
Ask your Doubts & Queries to get answers.. "Together, We enlight each other!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE