Преглед на урок

PHP/MySQL регистрация за вашия сайт.

PHP/MySQL регистрация за вашия сайт.




[color=#FF0000]Install.php

Код
<?php 

    require_once("connect.php"); 
     
    $query = mysql_query(" 
CREATE TABLE `members` ( 
`id` MEDIUMINT( 8 ) NOT NULL AUTO_INCREMENT , 
`username` VARCHAR( 50 ) NOT NULL , 
`firstname` VARCHAR( 50 ) NOT NULL , 
`lastname` VARCHAR( 50 ) NOT NULL , 
`password` VARCHAR( 50 ) NOT NULL , 
`date` VARCHAR( 50 ) NOT NULL , 
`ip` VARCHAR( 50 ) NOT NULL , 
PRIMARY KEY ( `id` ) , 
UNIQUE ( 
`username` 
) 
)"); 

echo "Installed! Please delete this file."; 
     

?> 

[color=#FF0000]Connect.php

Код
<?php 

    // MySQL connect information. 
    $c_username = "database_username"; 
    $c_password = "database_password"; 
    $c_host = "localhost"; 
    $c_database = "database_name"; 

    // Connect. 
    $connection = mysql_connect($c_host, $c_username, $c_password) 
    or die ("It seems this site's database isn't responding."); 

    mysql_select_db($c_database) 
    or die ("It seems this site's database isn't responding."); 

?> 

[color=#FF0000]Register.php

Код
<?php 

// Check if he wants to register: 
if (!empty($_POST[username])) 
undefined 

?> 

<html> 
    <head> 
        <title>Register</title> 
    </head> 
    <body> 
        <form action="register.php" method="post"> 
            <table width="75%" border="1" align="center" cellpadding="3" cellspacing="1"> 
                <tr> 
                    <td width="100%">Registration</td> 
                </tr> 
                <tr> 
                    <td width="100%"><label>Desired Username: <input type="text" name="username" size="25" value="<? echo $_POST[username]; ?>"></label></td> 
                </tr> 
                <tr> 
                    <td width="100%"><label>First Name: <input type="text" name="firstname" size="25" value="<? echo $_POST[firstname]; ?>"></label></td> 
                </tr> 
                <tr> 
                    <td width="100%"><label>Last Name: <input type="text" name="lastname" size="25" value="<? echo $_POST[lastname]; ?>"></label></td> 
                </tr> 
                <tr> 
                    <td width="100%"><label>Password: <input type="password" name="password" size="25" value="<? echo $_POST[password]; ?>"></label></td> 
                </tr> 
                <tr> 
                    <td width="100%"><label>Verify Password: <input type="password" name="password2" size="25" value=""></label></td> 
                </tr> 
                <tr> 
                    <td width="100%"><input type="submit" value="Register!"></td> 
                </tr> 
            </table> 
        </form> 
    </body> 
</html> 

[color=#FF0000]Login.php

Код
<?php 
session_start(); 
// Check if he wants to login: 
if (!empty($_POST[username])) 
undefined 

?> 

<html> 
    <head> 
        <title>Login</title> 
    </head> 
    <body> 
        <form action="login.php" method="post"> 
            <table width="75%" border="1" align="center" cellpadding="3" cellspacing="1"> 
                <tr> 
                    <td width="100%">Login</td> 
                </tr> 
                <tr> 
                    <td width="100%"><label>Username: <input type="text" name="username" size="25" value="<? echo $_POST[username]; ?>"></label></td> 
                </tr> 
                <tr> 
                    <td width="100%"><label>Password: <input type="password" name="password" size="25" value=""></label></td> 
                </tr> 
                <tr> 
                    <td width="100%"><input type="submit" value="Login!"></td> 
                </tr> 
            </table> 
        </form> 
    </body> 
</html> 

[color=#FF0000]Logout.php

Код
<?php 
    $_SESSION[username] = ""; 
?> 

[color=#FF0000]Members.php

Код
<?php 
session_start(); 

// Check his status. 
if (!empty($_SESSION[username])) // he got it. 
undefined 
else // bad info. 
undefined 

?> 

Урока е предоставен от bobby2007

Ако урокът ви допада, споделете го в Twitter и Facebook или го запазете в Delicious.




Урокът е добавен от: Красимир!

Добави коментар

Трябва да сте регистиран потребител за може да оставяте коментари! Направете своята безплатна регистрация още сега.