Jump to content

Need help with login php


NewToPhP1

Recommended Posts

I currently am tring to setup a login page with a database for users while doing this everything i login with the info in my database it redirects me to my error page not sure why.

would love some help

website:mast.net78.net

i can show the php i am using

i attached the php and the login page i am wondering if anyone can see something wrong right off hand

and too see the login page go to thee website

 

 

i forgot a few things

Server: localhost    Database: a5542765_master  username: a5542765_perry

 

[attachment deleted by admin]

Link to comment
Share on other sites

  • 2 weeks later...

Im not sure whats going on with your script but heres one that works.

<?php

ob_start();
session_start();
if ($uId) {

    //If they are logged in, they don't need to be here
    header("Location: " . $siteurl . "index.php");

} else {


    if (!isset($_POST['login'])) {

        //If the post hasn't been submitted, then show the forms

        echo '<br /><p><form method="post" action="index.php?action=login">

<p>Username:'.form_input(text,username).'</p>
<p>Password:'.form_input(password,password).'</p>

<input class="submit" type="submit" name="login" value="Login"><p>
</form>
<br>
'.anchor ('index.php?action=forgot','Forgot Password?').' | '.anchor ('index.php?action=register','Register').'';

    } else {


        //secure the input
        $username = secure($_POST['username']);
        $password = secure($_POST['password']);

        //make sure the fields arn't empty
        if (!$username | !$password) {

            echo 'You left a field empty';

        } else {

            //make sure the user exists
            $user = mysql_query("SELECT * FROM `users` WHERE username = '$username'");

            if (($usez = mysql_num_rows($user)) == 0) {
                echo 'user doesnt exist';
            } else {
                //Encrypt the password to check with the encrypted one currently in the database
                $encpass = sha1($password . SALT);

                //Find the user
                $superquery = mysql_query("SELECT * FROM `users` WHERE username = '$username' AND password = '$encpass'");


                if (mysql_num_rows($superquery) == 1) {

                    //If the user is found, set the cookies

                    setcookie("username", $username, $cookieTime);
                    setcookie("password", $encpass, $cookieTime);


                    //send the user to the home page
				header("Location: " . $siteurl . "index.php");

                } else {

                    echo 'Password was incorrect. Please try again.';

                }
            }
        }
    }
}
?>



Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.