(PHP) Register & Login

Page 1 of 2 12 LastLast
Results 1 to 15 of 25
  1. #1
    Infraction Banned Pulkkine is offline
    MemberRank
    May 2007 Join Date
    FinlandLocation
    34Posts

    (PHP) Register & Login

    Before someone says theres many register scripts, blah blah blah.
    I'll say I know, but this is the first one with checking if email is valid without email activation.


    If you dont have 'email' row at your 'users' table, create it.

    Register Features:
    - Checks if email is valid
    - Checks if password is 5-12 characters
    - Checks if username is 5-12 characters
    - Checks if username is already in use
    - Checks if email is already in use
    - Checks if 'password' and 'password again' are same

    PHP Code:
    <?php
    $con 
    mysql_connect("127.0.0.1","root","");
    mysql_select_db("maplestory"$con);
    $username $_POST['id'];
    $password $_POST['pw'];
    $password2 $_POST['pw2'];
    $email $_POST['email'];
    $query sprintf("SELECT username FROM users WHERE username= '%s'"$username);
    $result mysql_query($query$con) or die (mysql_error());
    $found mysql_num_rows($result);
    $query2 sprintf("SELECT email FROM users WHERE email= '%s'"$email);
    $result2 mysql_query($query2$con) or die (mysql_error());
    $found2 mysql_num_rows($result2);
    $reg "^([a-zA-Z0-9]+[_a-zA-Z0-9]+)(\.[-_a-zA-Z0-9]+)*@([-_a-zA-Z0-9]{2,}\.){1,}([a-zA-Z]{2,7})$"
    if(
    strlen($username) < 5)
    {
    echo 
    "<font color=red>Login ID must be 5 to 12 characters long.</font><br />";
    }
    else if(
    strlen($password) < 5)
    {
    echo 
    "<font color=red>Password must be 5 to 12 characters long.</font><br />";
    }
    else if(!
    ereg($reg$email))
    {
    echo 
    "<font color=red>Please enter a valid email.</font><br />";
    }
    else if(
    $found)
    {
    echo 
    "<font color=red>Login ID <i>$username</i> is already registered.</font><br />";
    }
    else if(
    $password !== $password2)
    {
    echo 
    "<font color=red>Passwords didn't match.</font><br />";
    }
    else if(
    $found2)
    {
    echo 
    "<font color=red>Email <i>$email</i> is already in use.</font><br />";
    }
    else
    {
    $id 1;
    $result mysql_query("SELECT * FROM Users ORDER BY id ASC");
    while(
    $row mysql_fetch_array($result))
      {
        if(
    $id==$row['ID'])
        {
        
    $id++;
        }
      }
    mysql_query("INSERT INTO users (ID,username,password,email,pin,gender,gm) VALUES ('".$id."', '".$username."', '".$password."', '".$email."', 0, 0, 0)") or die (mysql_error());
    echo 
    "<font color=green>Succesfully registered! Press <a href=\"login.php\">here</a> to login.</font><br />";
    $username "";
    $password "";
    $password2 "";
    $email "";
    }
    mysql_close($con);
    ?>
    <form action="<?php echo $_server['php-self'?>" method="post">
    <table cellpadding="5" cellspacing="0" border="0">
    <tr>
    <td id="txt">Login ID:</td>
    <td><input value="<?php echo $username?>" type="text" name="id" maxlength="12" style="width:150px; border: 1px solid gray;"></td>
    </tr>
    <tr>
    <td id="txt">Password:</td>
    <td><input value="<?php echo $password?>" type="password" name="pw" maxlength="12" style="width:150px; border: 1px solid gray;"></td>
    </tr>
    <tr>
    <td id="txt">Password again:</td>
    <td><input value="<?php echo $password2?>" type="password" name="pw2" maxlength="12" style="width:150px; border: 1px solid gray;"></td>
    </tr>
    <tr>
    <td id="txt">Email:</td>
    <td><input value="<?php echo $email?>" type="text" name="email" maxlength="30" style="width:150px; border: 1px solid gray;"></td>
    </tr>
    <tr>
    <td colspan="2"><input type="submit" value="Submit""></td>
    </tr>
    </table>
    </form>


    Login Features:
    - Checks if password is valid
    - Checks if that password belongs to the username entered
    - Cookie for 1 hour

    Replace 'yourcookie' with something. Ex. your maplestory servers name.
    (Theres 2 of them)

    PHP Code:
    <?php
    if(isset($_COOKIE['yourcookie']))
    {
    echo 
    "<br /><br />You've already logged in.";
    }
    else
    {
    $con mysql_connect("127.0.0.1","root","");
    mysql_select_db("maplestory"$con);
    if (isset(
    $_POST['submit'])) {
    $username $_POST['id']; 
    $password $_POST['pw'];
    $query sprintf("SELECT username, password FROM users WHERE username= '%s' AND password= '%s' "$username$password);
    $result mysql_query($query$con) or die (mysql_error());
    $found mysql_num_rows($result);
    if(
    $found)
    {
    $hour time() + 3600
    setcookie(yourcookie$username$hour); 
    header("Location: index.php");
    }
    else
    {
    echo 
    "<br /><br /><font color=red>Incorrect login id or password, please try again.</font><br />";
    }
    }
    mysql_close($con);
    ?>
    <form action="<?php echo $_server['php-self'?>" method="post">
    <table cellpadding="5" cellspacing="0" border="0">
    <tr>
    <td id="txt">Login ID:</td>
    <td><input value="" type="text" name="id" style="width:150px; border: 1px solid gray;"></td>
    <td rowspan="2"><input type="submit" name="submit" value="Login"></td>
    </tr>
    <tr>
    <td id="txt">Password:</td>
    <td><input value="" type="password" name="pw" style="width:150px; border: 1px solid gray;"></td>
    </tr>
    </table>
    </form>
    + <a href="register.php">Haven't signed up yet?</a><br />
    <?php
    }
    ?>
    And yeah, It's ugly from outside. But it's ment to include at your site so, doesn't matter.
    Last edited by Pulkkine; 04-05-08 at 11:50 AM. Reason: fixed code tags


  2. #2
    Valued Member mvrb is offline
    MemberRank
    Apr 2008 Join Date
    DenmarkLocation
    133Posts

    Re: [RELEASE] (PHP) Register & Login

    where do i paste it? in new files or excisting files?

  3. #3
    Account Upgraded | Title Enabled! boy toy is offline
    MemberRank
    Apr 2008 Join Date
    262Posts

    Re: [RELEASE] (PHP) Register & Login

    can u post an example?

  4. #4
    Account Upgraded | Title Enabled! PixmaDragon is offline
    MemberRank
    Apr 2008 Join Date
    Planet EarthLocation
    560Posts

    Re: [RELEASE] (PHP) Register & Login

    u open notepad and paste it and save it as a something.php i think u can name it anything not sure

  5. #5
    Account Upgraded | Title Enabled! renegod is offline
    MemberRank
    Aug 2005 Join Date
    SingaporeLocation
    630Posts

    Re: [RELEASE] (PHP) Register & Login

    Quote Originally Posted by PixmaDragon View Post
    u open notepad and paste it and save it as a something.php i think u can name it anything not sure
    Yes u can name it anything but if you want it as your homepage you'll have to name it as index.php in your htdocs folder(if you know what i mean)

    Quote Originally Posted by rroobbiinn View Post
    if u look in the code u will see it name loginscript to login.php and registerscript to register.php
    Whoops, my bad x), yea, this has to go with a certain website, but you can just use another name for those.. but it would be troublesome.

  6. #6
    Account Upgraded | Title Enabled! rroobbiinn is offline
    MemberRank
    Apr 2008 Join Date
    278Posts

    Re: [RELEASE] (PHP) Register & Login

    if u look in the code u will see it name loginscript to login.php and registerscript to register.php

  7. #7
    Member Lorrenzo is offline
    MemberRank
    Apr 2008 Join Date
    OH - - - IOLocation
    97Posts

    Re: [RELEASE] (PHP) Register & Login

    Looks nice, thanks!

  8. #8
    Apprentice RifleMarine is offline
    MemberRank
    Aug 2007 Join Date
    12Posts

    Re: [RELEASE] (PHP) Register & Login

    Nice!
    onks sul omaa privaa ?... 8D

  9. #9
    Infraction Banned Pulkkine is offline
    MemberRank
    May 2007 Join Date
    FinlandLocation
    34Posts

    Re: [RELEASE] (PHP) Register & Login

    Quote Originally Posted by RifleMarine View Post
    Nice!
    onks sul omaa privaa ?... 8D
    Tekovaiheessa, jossain vaiheessa pist

  10. #10
    Account Upgraded | Title Enabled! mikle is offline
    MemberRank
    Apr 2008 Join Date
    532Posts

    Re: [RELEASE] (PHP) Register & Login

    All that i get is
    index of /
    index.php.txt
    login.php.txt

  11. #11
    Valued Member Wiw3K is offline
    MemberRank
    Apr 2008 Join Date
    115Posts

    Re: [RELEASE] (PHP) Register & Login

    when i log in it says:
    Warning: Cannot modify header information - headers already sent by (output started at D:\xampp\htdocs\login.php:1) in D:\xampp\htdocs\login.php on line 19

    Warning: Cannot modify header information - headers already sent by (output started at D:\xampp\htdocs\login.php:1) in D:\xampp\htdocs\login.php on line 20
    HUH?

  12. #12
    Smoke & Fly Kars is offline
    MemberRank
    Apr 2008 Join Date
    The NetherlandsLocation
    3,383Posts

    Re: [RELEASE] (PHP) Register & Login

    Quote Originally Posted by mikle View Post
    All that i get is
    index of /
    index.php.txt
    login.php.txt
    select all files *.* instead of *.txt

  13. #13
    Account Upgraded | Title Enabled! mikle is offline
    MemberRank
    Apr 2008 Join Date
    532Posts

    Re: [RELEASE] (PHP) Register & Login

    Alright now i see
    index of /
    Index.php
    Login.php

  14. #14
    Novice HolySlime is offline
    MemberRank
    May 2008 Join Date
    3Posts

    Re: [RELEASE] (PHP) Register & Login

    [QUOTE=Pulkkine;3380445]Tekovaiheessa, jossain vaiheessa pist

  15. #15
    Infraction Banned Pulkkine is offline
    MemberRank
    May 2007 Join Date
    FinlandLocation
    34Posts

    Re: [RELEASE] (PHP) Register & Login

    Quote Originally Posted by mikle View Post
    Alright now i see
    index of /
    Index.php
    Login.php
    Rename 'Index.php' to 'index.php', don't use capital letters.

    May i help 8D....

    Oon toi riflemarine mut tein uuden ^^
    Jaa-a, meit



Page 1 of 2 12 LastLast

Advertisement