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
https://forums.phpfreaks.com/topic/236138-need-help-with-login-php/
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.';

                }
            }
        }
    }
}
?>



Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.