This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2011-06-12 22:50:34

kayybee
Scratcher
Registered: 2009-12-07
Posts: 1000+

PHP Login

Does anyone know how to make a login/register page for a website? Please?  smile

All help will be appreciated.

Offline

 

#2 2011-06-12 23:05:05

MrMokey
Scratcher
Registered: 2009-05-06
Posts: 1000+

Re: PHP Login

Google it.


http://i1193.photobucket.com/albums/aa344/mrmokey1/Thankyouitfitsperfectlysig.png

Offline

 

#3 2011-06-12 23:13:13

kayybee
Scratcher
Registered: 2009-12-07
Posts: 1000+

Re: PHP Login

I tried.

Offline

 

#4 2011-06-12 23:22:38

MrMokey
Scratcher
Registered: 2009-05-06
Posts: 1000+

Re: PHP Login

No idea if this works, because I dont even know what php is.


http://i1193.photobucket.com/albums/aa344/mrmokey1/Thankyouitfitsperfectlysig.png

Offline

 

#5 2011-06-12 23:33:10

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: PHP Login

Yeah, its not as easy as copy and pasting a script. First you need a server with php and sql, then you have to connect to your sql database, make the required tables and write the login/signup scripts.

Go here http://www.w3schools.com and learn all the php stuff. When you are done, you can make what you need.


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

#6 2011-06-13 02:03:34

meew0
Scratcher
Registered: 2010-02-22
Posts: 1000+

Re: PHP Login

That's really complicated. You need 4 pages and a mysql database for that...
As archmage said, look at some php tutorials (or get a book, like me  cool ) and then script it.

Last edited by meew0 (2011-06-13 02:03:58)


http://i.imgur.com/mJV3j.pnghttp://i.imgur.com/HwWAX.pnghttp://i.imgur.com/sZ7Ui.pnghttp://i.imgur.com/0y6yh.pnghttp://i.imgur.com/nOC4l.png

Offline

 

#7 2011-06-13 02:25:04

what-the
Scratcher
Registered: 2009-10-04
Posts: 1000+

Re: PHP Login

I have made my own php login with very little help from tutorials. I can Get you started.

Php database

Users | Password | Active | Other stuff for your site like email and account details


Here is my php for loging in on a website.

Code:

<?php
session_start();
//Database Information

$dbhost = "localhost";
$dbname = "****";
$dbuser = "****;
$dbpass = "****";

//Connect to database

mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());


Print"<head><meta content=\"text/html; charset=ISO-8859-1\" http-equiv=\"content-type\"><title>Confirming login</title><link rel=\"icon\" type=\"image/ico\" href=\"/*/database/favicon.ico\"></head>";
$username = $_POST['username'];
$password = $_POST['password'];
$query = "SELECT * FROM `users` WHERE `username` LIKE '$username' and `password` LIKE'$password'";
$result = mysql_query($query) or die ( "An error has occured.");

if (mysql_num_rows($result) != 1) {
$error = "Bad Login";
    include "login.html";
    Print"Username and password combo is incorrect";
} else {

    $query = "SELECT * FROM `users` WHERE `username` LIKE '$username' and `password`     LIKE'$password' and `active` =1";
    $result = mysql_query($query) or die ( "An error has occured.");
    if (mysql_num_rows($result) != 1) {
        $error = "Username not activated";
        Print"You have not activated your account. Please check your email address that you provided for instructions on how to active your account.";
            include "login.html";

    }else{
            $_SESSION['username'] = "$username";
            include "memberspage.php";
        
    }
}
mysql_close();

?>

The following is for activating the account. confirming email.

Code:

<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"><title>Main</title>


<link rel="icon" type="image/ico" href="/*/database/favicon.ico">

</head>
<?php

if ((isset($_GET["id"]))&&(isset($_GET["string"]))){
    $id = $_GET["id"];
    $usernames = $_GET["string"];

    $username="****";
    $password="****";
    $database="****";

    mysql_connect(localhost,$username,$password);
    @mysql_select_db($database) or die( "Unable to select database");
    

    $sql = "SELECT * FROM `users` WHERE `username` LIKE '$usernames' AND `userid` LIKE '$id'";

    $result = mysql_query($sql) or die ( "An error has occured. Please reload this page to see if the problem is fixed");
    $data = mysql_fetch_row($result);

    if ($data == ""){

        Print"Your account could not be verified. Please verify that the url has not been modified from the e-mail. We were unable to relsove the username. If you are still unsuccessful please contact us.";

    }else{

        
        $query = "update `users` set active=1 where userid=$id";
        $result = mysql_query($query) or die ( "An error has occured. Please reload this page to see if the problem is fixed");
        Print"Congratulations <b> \"$usernames\" </b>. You are now able to login and start creating domain names";
include "login.html";
mysql_close();
    }
} else {


die("Extentions not found!");
}
?>

Finally Requesting an account

HTML form code

Code:

<form action="insert.php" method="post">
Username: <input type="text" name="username"><br>
Password: <input type="password" name="password"><br>
E-mail: <input type="text" name="email"><br>

<input type="submit" name="submit" value="Sign me up!"
</form>

Php code

Code:

<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"><title>Main</title>


<link rel="icon" type="image/ico" href="/*/database/favicon.ico">

</head>
<?

// check e-mail address
// display success or failure message
if (!preg_match("/^([a-zA-Z0-9])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+/", $_POST['email']))
{
    include 'signup.html';
    $email=$_POST['email'];
    die("Invalid e-mail address <b>$email</b>. Please check your email address<br>");
    

} else {
//echo "Valid e-mail address, processing...<br>";
    $length=strlen($_POST['password']);
    

    if ($length < 6)
    {
        include 'signup.html';
        echo "Password is not at least 6 characters long<br>";
        die(" ");

    }else{

        //echo "Valid password<br>";

        $length=strlen($_POST['username']);
        if ($length < 3)
        {
            include 'signup.html';
            echo "Please enter a username with at least three characters.<br>";
            die(" ");

        }else{


            $username="****";
            $password="****";
            $database="****";

            $username1=$_POST['username'];
            $password1=$_POST['password'];
            $email=$_POST['email'];


            mysql_connect(localhost,$username,$password);
            @mysql_select_db($database) or die( "Unable to select database");

            $sql = "SELECT * FROM `users` WHERE `username` LIKE '$username1'";
            //Print"$sql<br>";
            $result = mysql_query($sql) or die ( "Username entered conflicts with something");
            $data = mysql_fetch_row($result);


            if ($data == ""){
    
                $sql = "SELECT * FROM `users` WHERE `email` LIKE '$email'";
                $result = mysql_query($sql) or die ( "email entered conflicts with something");
                $data = mysql_fetch_row($result);
                //Print"<br>$sql";
                if ($data == ""){

                    $query = "INSERT INTO users VALUES ('','$username1','$password1','$email','0')";
                    mysql_query($query) or die ( "Query error");
                    $user_id = mysql_insert_id();
                    //Print" Your user Id is $user_id";
                    $validate_link = "http://***/validate.php?id=$user_id&string=$username1";

                    //Print"Added user. Now checking";
                    $sql = "SELECT * FROM `users` WHERE `username` LIKE '$username1' AND `password` LIKE '$password1'";
                    $result = mysql_query($sql) or die ( "Query error can not find user");
                    //Print"<br>$sql";


                    

                    include 'signup.html';
                    Print"<br>The data you entered<br> ";
        
                    $data = mysql_fetch_row($result);
                    Print"Your Id $data[0] .Keep this for reference <br> Your username: $data[1] <br> Your password: $data[2] <br> Your email: $data[3] .We                     will send you important information about your account here<br><br>";



                $headers = "From: ***@***.***.*** \r\n";
                $subject = "Confirm account information";
                $message = "Welcome to **** To confirm your e-mail address and activate you account please click this link \n\n $validate_link \n\n.If there are any problems with signing up please let us know. \n\n If you did not create an account with us please disregard this message.";
                $yoursite = "***";


                if(mail("$email", "$subject", "$message", $headers)){

                    echo "An email has been sent to ".$email.". Please check your e-mail for steps to activate your account. Check your spam folder as sometimes these e-mail can be marked as spam. If you still do not see your e-mail, please <a href='sendemail.php?function=validation&id=$user_id&user=$username1&e=$email'> Click Here</a> to resend.<br>";

                }else{

                echo "There was an error sending an e-mail to your e-mail address. Please contact us to let us know of the issue.";

                }

                } else {
        
                include 'signup.html';
                Print"Another user has alreadly registered with that email address. If this is you and you can not access your account, you should request a password reset or contact us straight away if otherwise";
                
                }
            } else {

                include 'signup.html';
                Print"We are very sorry but that username already exists on this server. Please go back and try a new username";
                
            }
        mysql_close();

        }
    
    }
}

Tell me if you want the resend activation email code.

PLEASE GIVE ME CREDIT OR DON'T USE.

Last edited by what-the (2011-06-13 02:27:34)


http://imageshack.us/m/64/9034/ddfss.pngMy site
Find someone post count. Click posts under username. Find number of pages. Times that by 40 for min and 60 for max and you have a rough estimate of post count.

Offline

 

#8 2011-06-13 08:24:18

MrMokey
Scratcher
Registered: 2009-05-06
Posts: 1000+

Re: PHP Login

Whoa. I didnt understand ang of that


http://i1193.photobucket.com/albums/aa344/mrmokey1/Thankyouitfitsperfectlysig.png

Offline

 

#9 2011-06-14 21:48:30

kayybee
Scratcher
Registered: 2009-12-07
Posts: 1000+

Re: PHP Login

what-the wrote:

I have made my own php login with very little help from tutorials. I can Get you started.

Php database

Users | Password | Active | Other stuff for your site like email and account details


Here is my php for loging in on a website.

Code:

<?php
session_start();
//Database Information

$dbhost = "localhost";
$dbname = "****";
$dbuser = "****;
$dbpass = "****";

//Connect to database

mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());


Print"<head><meta content=\"text/html; charset=ISO-8859-1\" http-equiv=\"content-type\"><title>Confirming login</title><link rel=\"icon\" type=\"image/ico\" href=\"/*/database/favicon.ico\"></head>";
$username = $_POST['username'];
$password = $_POST['password'];
$query = "SELECT * FROM `users` WHERE `username` LIKE '$username' and `password` LIKE'$password'";
$result = mysql_query($query) or die ( "An error has occured.");

if (mysql_num_rows($result) != 1) {
$error = "Bad Login";
    include "login.html";
    Print"Username and password combo is incorrect";
} else {

    $query = "SELECT * FROM `users` WHERE `username` LIKE '$username' and `password`     LIKE'$password' and `active` =1";
    $result = mysql_query($query) or die ( "An error has occured.");
    if (mysql_num_rows($result) != 1) {
        $error = "Username not activated";
        Print"You have not activated your account. Please check your email address that you provided for instructions on how to active your account.";
            include "login.html";

    }else{
            $_SESSION['username'] = "$username";
            include "memberspage.php";
        
    }
}
mysql_close();

?>

The following is for activating the account. confirming email.

Code:

<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"><title>Main</title>


<link rel="icon" type="image/ico" href="/*/database/favicon.ico">

</head>
<?php

if ((isset($_GET["id"]))&&(isset($_GET["string"]))){
    $id = $_GET["id"];
    $usernames = $_GET["string"];

    $username="****";
    $password="****";
    $database="****";

    mysql_connect(localhost,$username,$password);
    @mysql_select_db($database) or die( "Unable to select database");
    

    $sql = "SELECT * FROM `users` WHERE `username` LIKE '$usernames' AND `userid` LIKE '$id'";

    $result = mysql_query($sql) or die ( "An error has occured. Please reload this page to see if the problem is fixed");
    $data = mysql_fetch_row($result);

    if ($data == ""){

        Print"Your account could not be verified. Please verify that the url has not been modified from the e-mail. We were unable to relsove the username. If you are still unsuccessful please contact us.";

    }else{

        
        $query = "update `users` set active=1 where userid=$id";
        $result = mysql_query($query) or die ( "An error has occured. Please reload this page to see if the problem is fixed");
        Print"Congratulations <b> \"$usernames\" </b>. You are now able to login and start creating domain names";
include "login.html";
mysql_close();
    }
} else {


die("Extentions not found!");
}
?>

Finally Requesting an account

HTML form code

Code:

<form action="insert.php" method="post">
Username: <input type="text" name="username"><br>
Password: <input type="password" name="password"><br>
E-mail: <input type="text" name="email"><br>

<input type="submit" name="submit" value="Sign me up!"
</form>

Php code

Code:

<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"><title>Main</title>


<link rel="icon" type="image/ico" href="/*/database/favicon.ico">

</head>
<?

// check e-mail address
// display success or failure message
if (!preg_match("/^([a-zA-Z0-9])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+/", $_POST['email']))
{
    include 'signup.html';
    $email=$_POST['email'];
    die("Invalid e-mail address <b>$email</b>. Please check your email address<br>");
    

} else {
//echo "Valid e-mail address, processing...<br>";
    $length=strlen($_POST['password']);
    

    if ($length < 6)
    {
        include 'signup.html';
        echo "Password is not at least 6 characters long<br>";
        die(" ");

    }else{

        //echo "Valid password<br>";

        $length=strlen($_POST['username']);
        if ($length < 3)
        {
            include 'signup.html';
            echo "Please enter a username with at least three characters.<br>";
            die(" ");

        }else{


            $username="****";
            $password="****";
            $database="****";

            $username1=$_POST['username'];
            $password1=$_POST['password'];
            $email=$_POST['email'];


            mysql_connect(localhost,$username,$password);
            @mysql_select_db($database) or die( "Unable to select database");

            $sql = "SELECT * FROM `users` WHERE `username` LIKE '$username1'";
            //Print"$sql<br>";
            $result = mysql_query($sql) or die ( "Username entered conflicts with something");
            $data = mysql_fetch_row($result);


            if ($data == ""){
    
                $sql = "SELECT * FROM `users` WHERE `email` LIKE '$email'";
                $result = mysql_query($sql) or die ( "email entered conflicts with something");
                $data = mysql_fetch_row($result);
                //Print"<br>$sql";
                if ($data == ""){

                    $query = "INSERT INTO users VALUES ('','$username1','$password1','$email','0')";
                    mysql_query($query) or die ( "Query error");
                    $user_id = mysql_insert_id();
                    //Print" Your user Id is $user_id";
                    $validate_link = "http://***/validate.php?id=$user_id&string=$username1";

                    //Print"Added user. Now checking";
                    $sql = "SELECT * FROM `users` WHERE `username` LIKE '$username1' AND `password` LIKE '$password1'";
                    $result = mysql_query($sql) or die ( "Query error can not find user");
                    //Print"<br>$sql";


                    

                    include 'signup.html';
                    Print"<br>The data you entered<br> ";
        
                    $data = mysql_fetch_row($result);
                    Print"Your Id $data[0] .Keep this for reference <br> Your username: $data[1] <br> Your password: $data[2] <br> Your email: $data[3] .We                     will send you important information about your account here<br><br>";



                $headers = "From: ***@***.***.*** \r\n";
                $subject = "Confirm account information";
                $message = "Welcome to **** To confirm your e-mail address and activate you account please click this link \n\n $validate_link \n\n.If there are any problems with signing up please let us know. \n\n If you did not create an account with us please disregard this message.";
                $yoursite = "***";


                if(mail("$email", "$subject", "$message", $headers)){

                    echo "An email has been sent to ".$email.". Please check your e-mail for steps to activate your account. Check your spam folder as sometimes these e-mail can be marked as spam. If you still do not see your e-mail, please <a href='sendemail.php?function=validation&id=$user_id&user=$username1&e=$email'> Click Here</a> to resend.<br>";

                }else{

                echo "There was an error sending an e-mail to your e-mail address. Please contact us to let us know of the issue.";

                }

                } else {
        
                include 'signup.html';
                Print"Another user has alreadly registered with that email address. If this is you and you can not access your account, you should request a password reset or contact us straight away if otherwise";
                
                }
            } else {

                include 'signup.html';
                Print"We are very sorry but that username already exists on this server. Please go back and try a new username";
                
            }
        mysql_close();

        }
    
    }
}

Tell me if you want the resend activation email code.

PLEASE GIVE ME CREDIT OR DON'T USE.

Looks cool, I'll implement it tomorrow. I think you're suited for helping with my mmorpg.

Offline

 

#10 2011-06-14 22:07:27

ScratchReallyROCKS
Scratcher
Registered: 2009-04-22
Posts: 1000+

Re: PHP Login

I made a really complicated php login/registration system that uses a database and cookies. I'll see if I can get some of the most important parts of it out so that it makes more sense.


http://imageshack.us/a/img694/3806/sigmad.png

Offline

 

Board footer