Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //Structura Database
- //DB: users
- //user_id INT(24) NOT NULL AUTO_INCREMENT
- //username VARCHAR(12) NOT NULL
- //password VARCHAR(10) NOT NULL
- if(isset($_POST['submit'])){
- $errors = array();
- if(isset($_POST['username']))
- {
- if(strlen($_POST['username']) < 2)
- {
- $errors[] = 'The username cannot be longer than 30 characters.<br /><a href="register.php">Back</a><br />';
- }
- if(strlen($_POST['username']) > 10)
- {
- $errors[] = 'The username cannot be longer than 10 characters.<br /><a href="register.php">Back</a><br />';
- }
- }
- else
- {
- $errors[] = 'The username field must not be empty.';
- }
- if(isset($_POST['password']))
- {
- if($_POST['password'] != $_POST['checkpassword'])
- {
- $errors[] = 'The two passwords did not match.<br /><a href="register.php">Back</a><br />';
- }
- }
- else
- {
- $errors[] = 'The password field cannot be empty.<br /><a href="register.php">Back</a><br />';
- }
- if(!empty($errors))
- {
- foreach($errors as $key => $value)
- {
- echo $value;
- }
- }
- else
- {
- $dbuser = $_POST['username'];
- $tabela_utilizator = $dbuser.'_table';
- $table = "CREATE TABLE $tabela_utilizator IF NOT EXISTS(
- user_id INT(24) NOT NULL AUTO_INCREMENT,
- username VARCHAR(12) NOT NULL,
- password VARCHAR(10) NOT NULL
- )";
- $sqlq = mysql_query($table);
- if(!$sqlq){
- print 'Table can′t be created';
- }else{
- $sql = "INSERT INTO $tabela_utilizator(username, password) VALUES('" . mysql_real_escape_string($_POST['username']) . "','" . md5($_POST['password']) . "')";
- $insert = mysql_query($sql);
- print 'Utilizator inregistrat cu succes.';
- }
- }
- }else{
- print '
- <form action="" method="POST">
- <input type="text" name="username" size="21">
- <input type="password" name="password" size="21">
- <input type="password" name="checkpassword" size="21">
- <input type="submit" name="submit" value="Inregistreaza cont">
- </form>
- ';
- }
- ?>
- Sign in(logare)
- <?php
- if(isset($_SESSION['logat']) && $_SESSION['logat'] == true)
- {
- echo 'Esti deja logat,te poti <a href="signout.php">deloga</a> daca vrei.';
- }
- else
- {
- if($_SERVER['REQUEST_METHOD'] != 'POST')
- {
- /*the form hasn't been posted yet, display it
- note that the action="" will cause the form to post to the same page it is on */
- echo '<form method="post" action="">
- <input type="text" name="username" size="21">
- <input type="password" name="password" size="21">
- <input type="submit" name="submit" value="Inregistreaza cont">
- <input type="submit" value="Sign in" />
- </form>';
- }
- else
- {
- $errors = array();
- if(empty($_POST['username']))
- {
- $errors[] = 'Campul userului este gol.';
- }
- if(empty($_POST['password']))
- {
- $errors[] = 'Campul parola este gol.';
- }
- if(!empty($errors))
- {
- echo 'Cateva probleme la logare<br /><br />';
- echo '<ul>';
- foreach($errors as $key => $value)
- {
- echo '<li>' . $value . '</li>';
- }
- echo '</ul>';
- }
- else
- {
- //the form has been posted without errors, so save it
- //notice the use of mysql_real_escape_string, keep everything safe!
- //also notice the sha1 function which hashes the password
- $sql = "SELECT
- user_id,
- username,
- password
- FROM
- users
- WHERE
- username = '" . mysql_real_escape_string($_POST['username']) . "'
- AND
- password = '" . md5($_POST['password']) . "'";
- $result = mysql_query($sql);
- if(!$result)
- {
- echo 'ERROR.';
- /
- }
- else
- if(mysql_num_rows($result) == 0)
- {
- echo 'Ai incercat gresit o combinatie de user si parola.Incearca mai tarziu.';
- }
- else
- {
- $_SESSION['logat'] = true;
- while($row = mysql_fetch_assoc($result))
- {
- $_SESSION['user_id'] = $row['user_id'];
- $_SESSION['username'] = $row['username'];
- }
- echo 'Bine ai venit, ' . $_SESSION['username'] . '. <br /><a href="index.php">Dute la pagina index.</a>.';
- }
- }
- }
- }
- }
- ?>
Add Comment
Please, Sign In to add comment