[TuT]Tot despre PhP/Mysql(Varianta Avansati)

Vezi subiectul anterior Vezi subiectul urmator In jos

[TuT]Tot despre PhP/Mysql(Varianta Avansati)

Mesaj Scris de MasteR la data de Sam Mai 26, 2012 6:27 pm

[size=150]Buna Seara, Stimati fani 4metin![/size]
Este o onoare sa postez un asemenea tutorial pe unicul 4metin si sper sa devina cea mai frumoasa comunitate despre metin2 din lume !
Printre altelea, sa incepem!
1. Cum sa pui un login pe pagina ta!
[size=150]Tutorial:[/size]
a) Creem un folder numit index, format '.php' .
b) Intram in el si bagam acestea:
Cod:
<html>
<?php
/*************** PHP LOGIN SCRIPT*********************
(c) SouL 2009. All Rights Reserved
***********************************************************/
include 'dbc.php';

$err = array();

foreach($_GET as $key => $value) {
   $get[$key] = filter($value); //get variables are filtered.
}

if ($_POST['doLogin']=='Login')
{

foreach($_POST as $key => $value) {
   $data[$key] = filter($value); // post variables are filtered
}


$user_email = $data['usr_email'];
$pass = $data['pwd'];


if (strpos($user_email,'@') === false) {
    $user_cond = "user_name='$user_email'";
} else {
      $user_cond = "user_email='$user_email'";
   
}

   
$result = mysql_query("SELECT `id`,`pwd`,`full_name`,`approved`,`user_level` FROM users WHERE
          $user_cond
         AND `banned` = '0'
         ") or die (mysql_error());
$num = mysql_num_rows($result);

  // Match row found with more than 1 results  - the user is authenticated.
    if ( $num > 0 ) {
   
   list($id,$pwd,$full_name,$approved,$user_level) = mysql_fetch_row($result);
   
   if(!$approved) {
   //$msg = urlencode("Account not activated. Please check your email for activation code");
   $err[] = "Account not activated. Please check your email for activation code";
   
   //header("Location: login.php?msg=$msg");
    //exit();
    }
   
      //check against salt
   if ($pwd === PwdHash($pass,substr($pwd,0,9))) {
   if(empty($err)){         

    // this sets session and logs user in 
      session_start();
     session_regenerate_id (true); //prevent against session fixation attacks.

     // this sets variables in the session
      $_SESSION['user_id']= $id; 
      $_SESSION['user_name'] = $full_name;
      $_SESSION['user_level'] = $user_level;
      $_SESSION['HTTP_USER_AGENT'] = md5($_SERVER['HTTP_USER_AGENT']);
      
      //update the timestamp and key for cookie
      $stamp = time();
      $ckey = GenKey();
      mysql_query("update users set `ctime`='$stamp', `ckey` = '$ckey' where id='$id'") or die(mysql_error());
      
      //set a cookie
      
     if(isset($_POST['remember'])){
              setcookie("user_id", $_SESSION['user_id'], time()+60*60*24*COOKIE_TIME_OUT, "/");
              setcookie("user_key", sha1($ckey), time()+60*60*24*COOKIE_TIME_OUT, "/");
              setcookie("user_name",$_SESSION['user_name'], time()+60*60*24*COOKIE_TIME_OUT, "/");
              }
        header("Location: myaccount.php");
       }
      }
      else
      {
      //$msg = urlencode("Invalid Login. Please try again with correct user email and password. ");
      $err[] = "Invalid Login. Please try again with correct user email and password.";
      //header("Location: login.php?msg=$msg");
      }
   } else {
      $err[] = "Error - Invalid login. No such user exists";
     }      
}
               
               

?>
<html>
<head>
<title>Members Login</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script language="JavaScript" type="text/javascript" src="js/jquery.validate.js"></script>
  <script>
  $(document).ready(function(){
    $("#logForm").validate();
  });
  </script>
<link href="styles.css" rel="stylesheet" type="text/css">

</head>

<body>
<table width="100%" border="0" cellspacing="0" cellpadding="5" class="main">
  <tr>
    <td colspan="3">&nbsp;</td>
  </tr>
  <tr>
    <td width="160" valign="top"><p>&nbsp;</p>
      <p>&nbsp; </p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p></td>
    <td width="732" valign="top"><p>&nbsp;</p>
      <h3 class="titlehdr">Login Users
      </h3> 
     <p>
     <?php
     /******************** ERROR MESSAGES*************************************************
     This code is to show error messages
     **************************************************************************/
     if(!empty($err))  {
     echo "<div class=\"msg\">";
     foreach ($err as $e) {
       echo "$e <br>";
       }
     echo "</div>";   
     }
     /******************************* END ********************************/    
     ?></p>
      <form action="login.php" method="post" name="logForm" id="logForm" >
        <table width="65%" border="0" cellpadding="4" cellspacing="4" class="loginform">
          <tr>
            <td colspan="2">&nbsp;</td>
          </tr>
          <tr>
            <td width="28%">Username / Email</td>
            <td width="72%"><input name="usr_email" type="text" class="required" id="txtbox" size="25"></td>
          </tr>
          <tr>
            <td>Password</td>
            <td><input name="pwd" type="password" class="required password" id="txtbox" size="25"></td>
          </tr>
          <tr>
            <td colspan="2"><div align="center">
                <input name="remember" type="checkbox" id="remember" value="1">
                Remember me</div></td>
          </tr>
          <tr>
            <td colspan="2"> <div align="center">
                <p>
                  <input name="doLogin" type="submit" id="doLogin3" value="Login">
                </p>
                <p><a href="register.php">Register Free</a><font color="#FF6600">
                  |</font> <a href="forgot.php">Forgot Password</a> <font color="#FF6600">
                  </font></p>
                <p><span style="font: normal 9px verdana">Powered by <a href="http://php-login-script.com">PHP
                  Login Script v2.3</a></span></p>
              </div></td>
          </tr>
        </table>
        <div align="center"></div>
        <p align="center">&nbsp; </p>
      </form>
      <p>&nbsp;</p>
    
      </td>
    <td width="196" valign="top">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="3">&nbsp;</td>
  </tr>
</table>

</body>
</html>
Ce face acest script?
Acest script pune pe sit-ul tau numele de utilizator si parola (+ Sa te Inregistrezi + Parola Uitata).
c) Creem un fisier numit dbc( puneti sal redenumiti in script, la fel si folderul) , format '.php' .
d) Punem Acestea:
Cod:
<?php
/*************** PHP LOGIN SCRIPT V 2.3*********************
(c) Balakrishnan SouL. All Rights Reserved

/******************** MAIN SETTINGS - PHP LOGIN SCRIPT **********************
Please complete wherever marked xxxxxxxxx

/************* MYSQL DATABASE SETTINGS *****************
1. Specify Database name in $dbname
2. MySQL host (localhost or remotehost)
3. MySQL user name with ALL previleges assigned.
4. MySQL password

Note: If you use cpanel, the name will be like account_database
*************************************************************/

define ("DB_HOST", "xxxxxx"); // set database host
define ("DB_USER", "xxxxxx"); // set database user
define ("DB_PASS","xxxxxxx"); // set database password
define ("DB_NAME","xxxxxx"); // set database name

$link = mysql_connect(DB_HOST, DB_USER, DB_PASS) or die("Couldn't make connection.");
$db = mysql_select_db(DB_NAME, $link) or die("Couldn't select database");

/* Registration Type (Automatic or Manual)
 1 -> Automatic Registration (Users will receive activation code and they will be automatically approved after clicking activation link)
 0 -> Manual Approval (Users will not receive activation code and you will need to approve every user manually)
*/
$user_registration = 1;  // set 0 or 1

define("COOKIE_TIME_OUT", 10); //specify cookie timeout in days (default is 10 days)
define('SALT_LENGTH', 9); // salt for password

//define ("ADMIN_NAME", "admin"); // sp

/* Specify user levels */
define ("ADMIN_LEVEL", 5);
define ("USER_LEVEL", 1);
define ("GUEST_LEVEL", 0);



/*************** reCAPTCHA KEYS****************/
$publickey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$privatekey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";


/**** PAGE PROTECT CODE  ********************************
This code protects pages to only logged in users. If users have not logged in then it will redirect to login page.
If you want to add a new page and want to login protect, COPY this from this to END marker.
Remember this code must be placed on very top of any html or php page.
********************************************************/

function page_protect() {
session_start();

global $db;

/* Secure against Session Hijacking by checking user agent */
if (isset($_SESSION['HTTP_USER_AGENT']))
{
    if ($_SESSION['HTTP_USER_AGENT'] != md5($_SERVER['HTTP_USER_AGENT']))
    {
        logout();
        exit;
    }
}

// before we allow sessions, we need to check authentication key - ckey and ctime stored in database

/* If session not set, check for cookies set by Remember me */
if (!isset($_SESSION['user_id']) && !isset($_SESSION['user_name']) )
{
   if(isset($_COOKIE['user_id']) && isset($_COOKIE['user_key'])){
   /* we double check cookie expiry time against stored in database */
   
   $cookie_user_id  = filter($_COOKIE['user_id']);
   $rs_ctime = mysql_query("select `ckey`,`ctime` from `users` where `id` ='$cookie_user_id'") or die(mysql_error());
   list($ckey,$ctime) = mysql_fetch_row($rs_ctime);
   // coookie expiry
   if( (time() - $ctime) > 60*60*24*COOKIE_TIME_OUT) {

      logout();
      }
/* Security check with untrusted cookies - dont trust value stored in cookie.       
/* We also do authentication check of the `ckey` stored in cookie matches that stored in database during login*/

    if( !empty($ckey) && is_numeric($_COOKIE['user_id']) && isUserID($_COOKIE['user_name']) && $_COOKIE['user_key'] == sha1($ckey)  ) {
         session_regenerate_id(); //against session fixation attacks.
   
        $_SESSION['user_id'] = $_COOKIE['user_id'];
        $_SESSION['user_name'] = $_COOKIE['user_name'];
      /* query user level from database instead of storing in cookies */   
        list($user_level) = mysql_fetch_row(mysql_query("select user_level from users where id='$_SESSION[user_id]'"));

        $_SESSION['user_level'] = $user_level;
        $_SESSION['HTTP_USER_AGENT'] = md5($_SERVER['HTTP_USER_AGENT']);
       
     } else {
     logout();
     }

  } else {
   header("Location: login.php");
   exit();
   }
}
}



function filter($data) {
   $data = trim(htmlentities(strip_tags($data)));
   
   if (get_magic_quotes_gpc())
      $data = stripslashes($data);
   
   $data = mysql_real_escape_string($data);
   
   return $data;
}



function EncodeURL($url)
{
$new = strtolower(ereg_replace(' ','_',$url));
return($new);
}

function DecodeURL($url)
{
$new = ucwords(ereg_replace('_',' ',$url));
return($new);
}

function ChopStr($str, $len)
{
    if (strlen($str) < $len)
        return $str;

    $str = substr($str,0,$len);
    if ($spc_pos = strrpos($str," "))
            $str = substr($str,0,$spc_pos);

    return $str . "...";
}   

function isEmail($email){
  return preg_match('/^\S+@[\w\d.-]{2,}\.[\w]{2,6}$/iU', $email) ? TRUE : FALSE;
}

function isUserID($username)
{
   if (preg_match('/^[a-z\d_]{5,20}$/i', $username)) {
      return true;
   } else {
      return false;
   }
 }   
 
function isURL($url)
{
   if (preg_match('/^(http|https|ftp):\/\/([A-Z0-9][A-Z0-9_-]*(?:\.[A-Z0-9][A-Z0-9_-]*)+):?(\d+)?\/?/i', $url)) {
      return true;
   } else {
      return false;
   }
}

function checkPwd($x,$y)
{
if(empty($x) || empty($y) ) { return false; }
if (strlen($x) < 4 || strlen($y) < 4) { return false; }

if (strcmp($x,$y) != 0) {
 return false;
 }
return true;
}

function GenPwd($length = 7)
{
  $password = "";
  $possible = "0123456789bcdfghjkmnpqrstvwxyz"; //no vowels
 
  $i = 0;
   
  while ($i < $length) {

   
    $char = substr($possible, mt_rand(0, strlen($possible)-1), 1);
     
   
    if (!strstr($password, $char)) {
      $password .= $char;
      $i++;
    }

  }

  return $password;

}

function GenKey($length = 7)
{
  $password = "";
  $possible = "0123456789abcdefghijkmnopqrstuvwxyz";
 
  $i = 0;
   
  while ($i < $length) {

   
    $char = substr($possible, mt_rand(0, strlen($possible)-1), 1);
     
   
    if (!strstr($password, $char)) {
      $password .= $char;
      $i++;
    }

  }

  return $password;

}


function logout()
{
global $db;
session_start();

if(isset($_SESSION['user_id']) || isset($_COOKIE['user_id'])) {
mysql_query("update `users`
         set `ckey`= '', `ctime`= ''
         where `id`='$_SESSION[user_id]' OR  `id` = '$_COOKIE[user_id]'") or die(mysql_error());
}         

/************ Delete the sessions****************/
unset($_SESSION['user_id']);
unset($_SESSION['user_name']);
unset($_SESSION['user_level']);
unset($_SESSION['HTTP_USER_AGENT']);
session_unset();
session_destroy();

/* Delete the cookies*******************/
setcookie("user_id", '', time()-60*60*24*COOKIE_TIME_OUT, "/");
setcookie("user_name", '', time()-60*60*24*COOKIE_TIME_OUT, "/");
setcookie("user_key", '', time()-60*60*24*COOKIE_TIME_OUT, "/");

header("Location: login.php");
}

// Password and salt generation
function PwdHash($pwd, $salt = null)
{
    if ($salt === null)    {
        $salt = substr(md5(uniqid(rand(), true)), 0, SALT_LENGTH);
    }
    else    {
        $salt = substr($salt, 0, SALT_LENGTH);
    }
    return $salt . sha1($pwd . $salt);
}

function checkAdmin() {

if($_SESSION['user_level'] == ADMIN_LEVEL) {
return 1;
} else { return 0 ;
}

}

?>
Acest Script ne arata unde am gresit , la majoriatea serverelor nu am mysql_query , ceea ce este grav
Deoarece el configureaza tot sistemul de login(si la registru), astfel incat sa mearga repede , dar si sa functioneze Acel Submit ->> si sa te duca la greseala!

[size=150]Mai sus tot ce trebuie sa faceti este sa editati cu notepad ++ astea 'xxxxxx' (fara virgula) , este necesar pentru configurarea loginului dupa serverul vostru! ( HOST: ip-ul tau. 100 ; User: root; pass: 123456; name: numele serverului!)[/size]
[size=150]ASA![/size]
2.Acum am sa va invat cum se face un registru(varianta pentru avansati!->> cea pentru incepatori sau buni este aiciea : http://4metin.ro/scripturi-tutoriale-php-mysql/cum-sa-faci-o-pagina-de-metin-t22602.html
a) Creem un folderul numit register, format '.php' .
b) Intram in el si bagam urmatoarele:
Cod:
<?php
/*************** PHP LOGIN SCRIPT V 2.0*********************
***************** Auto Approve Version**********************
(c) Balakrishnan 2009. All Rights Reserved

Usage: This script can be used FREE of charge for any commercial or personal projects.

Limitations:
- This script cannot be sold.
- This script may not be provided for download except on its original site.

For further usage, please contact me.

***********************************************************/


include 'dbc.php';

$err = array();
               
if($_POST['doRegister'] == 'Register')
{
/******************* Filtering/Sanitizing Input *****************************
This code filters harmful script code and escapes data of all POST data
from the user submitted form.
*****************************************************************/
foreach($_POST as $key => $value) {
   $data[$key] = filter($value);
}

/********************* RECAPTCHA CHECK *******************************
This code checks and validates recaptcha
****************************************************************/
 require_once('recaptchalib.php');
   
      $resp = recaptcha_check_answer ($privatekey,
                                      $_SERVER["REMOTE_ADDR"],
                                      $_POST["recaptcha_challenge_field"],
                                      $_POST["recaptcha_response_field"]);

      if (!$resp->is_valid) {
        die ("<h3>Image Verification failed!. Go back and try again.</h3>" .
            "(reCAPTCHA said: " . $resp->error . ")");         
      }
/************************ SERVER SIDE VALIDATION **************************************/
/********** This validation is useful if javascript is disabled in the browswer ***/

if(empty($data['full_name']) || strlen($data['full_name']) < 4)
{
$err[] = "ERROR - Invalid name. Please enter atleast 3 or more characters for your name";
//header("Location: register.php?msg=$err");
//exit();
}

// Validate User Name
if (!isUserID($data['user_name'])) {
$err[] = "ERROR - Invalid user name. It can contain alphabet, number and underscore.";
//header("Location: register.php?msg=$err");
//exit();
}

// Validate Email
if(!isEmail($data['usr_email'])) {
$err[] = "ERROR - Invalid email address.";
//header("Location: register.php?msg=$err");
//exit();
}
// Check User Passwords
if (!checkPwd($data['pwd'],$data['pwd2'])) {
$err[] = "ERROR - Invalid Password or mismatch. Enter 5 chars or more";
//header("Location: register.php?msg=$err");
//exit();
}
    
$user_ip = $_SERVER['REMOTE_ADDR'];

// stores sha1 of password
$sha1pass = PwdHash($data['pwd']);

// Automatically collects the hostname or domain  like example.com)
$host  = $_SERVER['HTTP_HOST'];
$host_upper = strtoupper($host);
$path  = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');

// Generates activation code simple 4 digit number
$activ_code = rand(1000,9999);

$usr_email = $data['usr_email'];
$user_name = $data['user_name'];

/************ USER EMAIL CHECK ************************************
This code does a second check on the server side if the email already exists. It
queries the database and if it has any existing email it throws user email already exists
*******************************************************************/

$rs_duplicate = mysql_query("select count(*) as total from users where user_email='$usr_email' OR user_name='$user_name'") or die(mysql_error());
list($total) = mysql_fetch_row($rs_duplicate);

if ($total > 0)
{
$err[] = "ERROR - The username/email already exists. Please try again with different username and email.";
//header("Location: register.php?msg=$err");
//exit();
}
/***************************************************************************/

if(empty($err)) {

$sql_insert = "INSERT into `users`
           (`full_name`,`user_email`,`pwd`,`address`,`tel`,`fax`,`website`,`date`,`users_ip`,`activation_code`,`country`,`user_name`
         )
          VALUES
          ('$data[full_name]','$usr_email','$sha1pass','$data[address]','$data[tel]','$data[fax]','$data[web]'
         ,now(),'$user_ip','$activ_code','$data[country]','$user_name'
         )
         ";
         
mysql_query($sql_insert,$link) or die("Insertion Failed:" . mysql_error());
$user_id = mysql_insert_id($link); 
$md5_id = md5($user_id);
mysql_query("update users set md5_id='$md5_id' where id='$user_id'");
//   echo "<h3>Thank You</h3> We received your submission.";

if($user_registration)  {
$a_link = "
*****ACTIVATION LINK*****\n
http://$host$path/activate.php?user=$md5_id&activ_code=$activ_code
";
} else {
$a_link =
"Your account is *PENDING APPROVAL* and will be soon activated the administrator.
";
}

$message =
"Hello \n
Thank you for registering with us. Here are your login details...\n

User ID: $user_name
Email: $usr_email \n
Passwd: $data[pwd] \n

$a_link

Thank You

Administrator
$host_upper
______________________________________________________
THIS IS AN AUTOMATED RESPONSE.
***DO NOT RESPOND TO THIS EMAIL****
";

   mail($usr_email, "Login Details", $message,
    "From: \"Member Registration\" <auto-reply@$host>\r\n" .
    "X-Mailer: PHP/" . phpversion());

  header("Location: thankyou.php"); 
  exit();
   
    }
 }               

?>
<html>
<head>
<title>PHP Login :: Free Registration/Signup Form</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script language="JavaScript" type="text/javascript" src="js/jquery.validate.js"></script>

  <script>
  $(document).ready(function(){
    $.validator.addMethod("username", function(value, element) {
        return this.optional(element) || /^[a-z0-9\_]+$/i.test(value);
    }, "Username must contain only letters, numbers, or underscore.");

    $("#regForm").validate();
  });
  </script>

<link href="styles.css" rel="stylesheet" type="text/css">
</head>

<body>
<table width="100%" border="0" cellspacing="0" cellpadding="5" class="main">
  <tr>
    <td colspan="3">&nbsp;</td>
  </tr>
  <tr>
    <td width="160" valign="top"><p>&nbsp;</p>
      <p>&nbsp; </p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p></td>
    <td width="732" valign="top"><p>
   <?php
    if (isset($_GET['done'])) { ?>
     <h2>Thank you</h2> Your registration is now complete and you can <a href="login.php">login here</a>";
    <?php exit();
     }
   ?></p>
      <h3 class="titlehdr">Free Registration / Signup</h3>
      <p>Please register a free account, before you can start posting your ads.
        Registration is quick and free! Please note that fields marked <span class="required">*</span>
        are required.</p>
    <?php   
    if(!empty($err))  {
     echo "<div class=\"msg\">";
     foreach ($err as $e) {
       echo "* $e <br>";
       }
     echo "</div>";   
     }
    ?>
   
     <br>
      <form action="register.php" method="post" name="regForm" id="regForm" >
        <table width="95%" border="0" cellpadding="3" cellspacing="3" class="forms">
          <tr>
            <td colspan="2">Your Name / Company Name<span class="required"><font color="#CC0000">*</font></span><br>
              <input name="full_name" type="text" id="full_name" size="40" class="required"></td>
          </tr>
          <tr>
            <td colspan="2">&nbsp;</td>
          </tr>
          <tr>
            <td colspan="2">Contact Address (with ZIP)<span class="required"><font color="#CC0000">*</font></span><br>
              <textarea name="address" cols="40" rows="4" id="address" class="required"></textarea>
              <span class="example">VALID CONTACT DETAILS</span> </td>
          </tr>
          <tr>
            <td>Country <font color="#CC0000">*</font></span></td>
            <td><select name="country" class="required" id="select8">
                <option value="" selected></option>
                <option value="Afghanistan">Afghanistan</option>
                <option value="Albania">Albania</option>
                <option value="Algeria">Algeria</option>
                <option value="Andorra">Andorra</option>
                <option value="Anguila">Anguila</option>
                <option value="Antarctica">Antarctica</option>
                <option value="Antigua and Barbuda">Antigua and Barbuda</option>
                <option value="Argentina">Argentina</option>
                <option value="Armenia ">Armenia </option>
                <option value="Aruba">Aruba</option>
                <option value="Australia">Australia</option>
                <option value="Austria">Austria</option>
                <option value="Azerbaidjan">Azerbaidjan</option>
                <option value="Bahamas">Bahamas</option>
                <option value="Bahrain">Bahrain</option>
                <option value="Bangladesh">Bangladesh</option>
                <option value="Barbados">Barbados</option>
                <option value="Belarus">Belarus</option>
                <option value="Belgium">Belgium</option>
                <option value="Belize">Belize</option>
                <option value="Bermuda">Bermuda</option>
                <option value="Bhutan">Bhutan</option>
                <option value="Bolivia">Bolivia</option>
                <option value="Bosnia and Herzegovina">Bosnia and Herzegovina</option>
                <option value="Brazil">Brazil</option>
                <option value="Brunei">Brunei</option>
                <option value="Bulgaria">Bulgaria</option>
                <option value="Cambodia">Cambodia</option>
                <option value="Canada">Canada</option>
                <option value="Cape Verde">Cape Verde</option>
                <option value="Cayman Islands">Cayman Islands</option>
                <option value="Chile">Chile</option>
                <option value="China">China</option>
                <option value="Christmans Islands">Christmans Islands</option>
                <option value="Cocos Island">Cocos Island</option>
                <option value="Colombia">Colombia</option>
                <option value="Cook Islands">Cook Islands</option>
                <option value="Costa Rica">Costa Rica</option>
                <option value="Croatia">Croatia</option>
                <option value="Cuba">Cuba</option>
                <option value="Cyprus">Cyprus</option>
                <option value="Czech Republic">Czech Republic</option>
                <option value="Denmark">Denmark</option>
                <option value="Dominica">Dominica</option>
                <option value="Dominican Republic">Dominican Republic</option>
                <option value="Ecuador">Ecuador</option>
                <option value="Egypt">Egypt</option>
                <option value="El Salvador">El Salvador</option>
                <option value="Estonia">Estonia</option>
                <option value="Falkland Islands">Falkland Islands</option>
                <option value="Faroe Islands">Faroe Islands</option>
                <option value="Fiji">Fiji</option>
                <option value="Finland">Finland</option>
                <option value="France">France</option>
                <option value="French Guyana">French Guyana</option>
                <option value="French Polynesia">French Polynesia</option>
                <option value="Gabon">Gabon</option>
                <option value="Germany">Germany</option>
                <option value="Gibraltar">Gibraltar</option>
                <option value="Georgia">Georgia</option>
                <option value="Greece">Greece</option>
                <option value="Greenland">Greenland</option>
                <option value="Grenada">Grenada</option>
                <option value="Guadeloupe">Guadeloupe</option>
                <option value="Guatemala">Guatemala</option>
                <option value="Guinea-Bissau">Guinea-Bissau</option>
                <option value="Guinea">Guinea</option>
                <option value="Haiti">Haiti</option>
                <option value="Honduras">Honduras</option>
                <option value="Hong Kong">Hong Kong</option>
                <option value="Hungary">Hungary</option>
                <option value="Iceland">Iceland</option>
                <option value="India">India</option>
                <option value="Indonesia">Indonesia</option>
                <option value="Ireland">Ireland</option>
                <option value="Israel">Israel</option>
                <option value="Italy">Italy</option>
                <option value="Jamaica">Jamaica</option>
                <option value="Japan">Japan</option>
                <option value="Jordan">Jordan</option>
                <option value="Kazakhstan">Kazakhstan</option>
                <option value="Kenya">Kenya</option>
                <option value="Kiribati ">Kiribati </option>
                <option value="Kuwait">Kuwait</option>
                <option value="Kyrgyzstan">Kyrgyzstan</option>
                <option value="Lao People's Democratic Republic">Lao People's
                Democratic Republic</option>
                <option value="Latvia">Latvia</option>
                <option value="Lebanon">Lebanon</option>
                <option value="Liechtenstein">Liechtenstein</option>
                <option value="Lithuania">Lithuania</option>
                <option value="Luxembourg">Luxembourg</option>
                <option value="Macedonia">Macedonia</option>
                <option value="Madagascar">Madagascar</option>
                <option value="Malawi">Malawi</option>
                <option value="Malaysia ">Malaysia </option>
                <option value="Maldives">Maldives</option>
                <option value="Mali">Mali</option>
                <option value="Malta">Malta</option>
                <option value="Marocco">Marocco</option>
                <option value="Marshall Islands">Marshall Islands</option>
                <option value="Mauritania">Mauritania</option>
                <option value="Mauritius">Mauritius</option>
                <option value="Mexico">Mexico</option>
                <option value="Micronesia">Micronesia</option>
                <option value="Moldavia">Moldavia</option>
                <option value="Monaco">Monaco</option>
                <option value="Mongolia">Mongolia</option>
                <option value="Myanmar">Myanmar</option>
                <option value="Nauru">Nauru</option>
                <option value="Nepal">Nepal</option>
                <option value="Netherlands Antilles">Netherlands Antilles</option>
                <option value="Netherlands">Netherlands</option>
                <option value="New Zealand">New Zealand</option>
                <option value="Niue">Niue</option>
                <option value="North Korea">North Korea</option>
                <option value="Norway">Norway</option>
                <option value="Oman">Oman</option>
                <option value="Pakistan">Pakistan</option>
                <option value="Palau">Palau</option>
                <option value="Panama">Panama</option>
                <option value="Papua New Guinea">Papua New Guinea</option>
                <option value="Paraguay">Paraguay</option>
                <option value="Peru ">Peru </option>
                <option value="Philippines">Philippines</option>
                <option value="Poland">Poland</option>
                <option value="Portugal ">Portugal </option>
                <option value="Puerto Rico">Puerto Rico</option>
                <option value="Qatar">Qatar</option>
                <option value="Republic of Korea Reunion">Republic of Korea Reunion</option>
                <option value="Romania">Romania</option>
                <option value="Russia">Russia</option>
                <option value="Saint Helena">Saint Helena</option>
                <option value="Saint kitts and nevis">Saint kitts and nevis</option>
                <option value="Saint Lucia">Saint Lucia</option>
                <option value="Samoa">Samoa</option>
                <option value="San Marino">San Marino</option>
                <option value="Saudi Arabia">Saudi Arabia</option>
                <option value="Seychelles">Seychelles</option>
                <option value="Singapore">Singapore</option>
                <option value="Slovakia">Slovakia</option>
                <option value="Slovenia">Slovenia</option>
                <option value="Solomon Islands">Solomon Islands</option>
                <option value="South Africa">South Africa</option>
                <option value="Spain">Spain</option>
                <option value="Sri Lanka">Sri Lanka</option>
                <option value="St.Pierre and Miquelon">St.Pierre and Miquelon</option>
                <option value="St.Vincent and the Grenadines">St.Vincent and the
                Grenadines</option>
                <option value="Sweden">Sweden</option>
                <option value="Switzerland">Switzerland</option>
                <option value="Syria">Syria</option>
                <option value="Taiwan ">Taiwan </option>
                <option value="Tajikistan">Tajikistan</option>
                <option value="Thailand">Thailand</option>
                <option value="Trinidad and Tobago">Trinidad and Tobago</option>
                <option value="Turkey">Turkey</option>
                <option value="Turkmenistan">Turkmenistan</option>
                <option value="Turks and Caicos Islands">Turks and Caicos Islands</option>
                <option value="Ukraine">Ukraine</option>
                <option value="UAE">UAE</option>
                <option value="UK">UK</option>
                <option value="USA">USA</option>
                <option value="Uruguay">Uruguay</option>
                <option value="Uzbekistan">Uzbekistan</option>
                <option value="Vanuatu">Vanuatu</option>
                <option value="Vatican City">Vatican City</option>
                <option value="Vietnam">Vietnam</option>
                <option value="Virgin Islands (GB)">Virgin Islands (GB)</option>
                <option value="Virgin Islands (U.S.) ">Virgin Islands (U.S.) </option>
                <option value="Wallis and Futuna Islands">Wallis and Futuna Islands</option>
                <option value="Yemen">Yemen</option>
                <option value="Yugoslavia">Yugoslavia</option>
              </select></td>
          </tr>
          <tr>
            <td>Phone<span class="required"><font color="#CC0000">*</font></span>
            </td>
            <td><input name="tel" type="text" id="tel" class="required"></td>
          </tr>
          <tr>
            <td>Fax </td>
            <td><input name="fax" type="text" id="fax">
         </td>
          </tr>
          <tr>
            <td>Website </td>
            <td><input name="web" type="text" id="web" class="optional defaultInvalid url">
              <span class="example">http://www.example.com</span></td>
          </tr>
          <tr>
            <td colspan="2">&nbsp;</td>
          </tr>
          <tr>
            <td colspan="2"><h4><strong>Login Details</strong></h4></td>
          </tr>
          <tr>
            <td>Username<span class="required"><font color="#CC0000">*</font></span></td>
            <td><input name="user_name" type="text" id="user_name" class="required username" minlength="5" >
              <input name="btnAvailable" type="button" id="btnAvailable"
           onclick='$("#checkid").html("Please wait..."); $.get("checkuser.php",{ cmd: "check", user: $("#user_name").val() } ,function(data){  $("#checkid").html(data); });'
           value="Check Availability">
             <span style="color:red; font: bold 12px verdana; " id="checkid" ></span>
            </td>
          </tr>
          <tr>
            <td>Your Email<span class="required"><font color="#CC0000">*</font></span>
            </td>
            <td><input name="usr_email" type="text" id="usr_email3" class="required email">
              <span class="example">** Valid email please..</span></td>
          </tr>
          <tr>
            <td>Password<span class="required"><font color="#CC0000">*</font></span>
            </td>
            <td><input name="pwd" type="password" class="required password" minlength="5" id="pwd">
              <span class="example">** 5 chars minimum..</span></td>
          </tr>
          <tr>
            <td>Retype Password<span class="required"><font color="#CC0000">*</font></span>
            </td>
            <td><input name="pwd2"  id="pwd2" class="required password" type="password" minlength="5" equalto="#pwd"></td>
          </tr>
          <tr>
            <td colspan="2">&nbsp;</td>
          </tr>
          <tr>
            <td width="22%"><strong>Image Verification </strong></td>
            <td width="78%">
              <?php
         require_once('recaptchalib.php');
         
            echo recaptcha_get_html($publickey);
         ?>
            </td>
          </tr>
        </table>
        <p align="center">
          <input name="doRegister" type="submit" id="doRegister" value="Register">
        </p>
      </form>
      <p align="right"><span style="font: normal 9px verdana">Powered by <a href="http://php-login-script.com">PHP
                  Login Script v2.0</a></span></p>
    
      </td>
    <td width="196" valign="top">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="3">&nbsp;</td>
  </tr>
</table>
[code][/code]
</body>
</html>
ce face acest scirpt?
Acest script ne pune numele de utilizator, parola, etc... + mysql_query( daca nu il gasiti , lam pus eu cu ajutorul unui program mysql executor->> nu il gasiti pe net(cred) caci eu il aveam cumparat!
c) Ne trebuie si la register 'dbc.php' ->> pentru configurare
[size=150]ASA![/size]
Sa continuam! Daca tot am implementat Forgot Password, sa va prezint!
1. Creem un folder recparola, format '.php' .
2. Intram in el si bagam acestea(spam, recunosc) :
Cod:
<?php
include 'dbc.php';




/******************* ACTIVATION BY FORM**************************/
if ($_POST['doReset']=='Reset')
{
$err = array();
$msg = array();

foreach($_POST as $key => $value) {
   $data[$key] = filter($value);
}
if(!isEmail($data['user_email'])) {
$err[] = "ERROR - Please enter a valid email";
}

$user_email = $data['user_email'];

//check if activ code and user is valid as precaution
$rs_check = mysql_query("select id from users where user_email='$user_email'") or die (mysql_error());
$num = mysql_num_rows($rs_check);
  // Match row found with more than 1 results  - the user is authenticated.
    if ( $num <= 0 ) {
   $err[] = "Error - Sorry no such account exists or registered.";
   //header("Location: forgot.php?msg=$msg");
   //exit();
   }


if(empty($err)) {

$new_pwd = GenPwd();
$pwd_reset = PwdHash($new_pwd);
//$sha1_new = sha1($new);   
//set update sha1 of new password + salt
$rs_activ = mysql_query("update users set pwd='$pwd_reset' WHERE
                   user_email='$user_email'") or die(mysql_error());
                  
$host  = $_SERVER['HTTP_HOST'];
$host_upper = strtoupper($host);                  
                  
//send email

$message =
"Here are your new password details ...\n
User Email: $user_email \n
Passwd: $new_pwd \n

Thank You

Administrator
$host_upper
______________________________________________________
THIS IS AN AUTOMATED RESPONSE.
***DO NOT RESPOND TO THIS EMAIL****
";

   mail($user_email, "Reset Password", $message,
    "From: \"Member Registration\" <auto-reply@$host>\r\n" .
    "X-Mailer: PHP/" . phpversion());                  
                  
$msg[] = "Your account password has been reset and a new password has been sent to your email address.";                  
                  
//$msg = urlencode();
//header("Location: forgot.php?msg=$msg");                  
//exit();
 }
}
?>
<html>
<head>
<title>Forgot Password</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script language="JavaScript" type="text/javascript" src="js/jquery.validate.js"></script>
  <script>
  $(document).ready(function(){
    $("#actForm").validate();
  });
  </script>
<link href="styles.css" rel="stylesheet" type="text/css">
</head>

<body>
<table width="100%" border="0" cellspacing="0" cellpadding="5" class="main">
  <tr>
    <td colspan="3">&nbsp;</td>
  </tr>
  <tr>
    <td width="160" valign="top"><p>&nbsp;</p>
      <p>&nbsp; </p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p></td>
    <td width="732" valign="top">
<h3 class="titlehdr">Forgot Password</h3>

      <p>
        <?php
     /******************** ERROR MESSAGES*************************************************
     This code is to show error messages
     **************************************************************************/
   if(!empty($err))  {
     echo "<div class=\"msg\">";
     foreach ($err as $e) {
       echo "* $e <br>";
       }
     echo "</div>";   
     }
     if(!empty($msg))  {
       echo "<div class=\"msg\">" . $msg[0] . "</div>";

     }
     /******************************* END ********************************/    
     ?>
      </p>
      <p>If you have forgot the account password, you can <strong>reset password</strong>
        and a new password will be sent to your email address.</p>
   
      <form action="forgot.php" method="post" name="actForm" id="actForm" >
        <table width="65%" border="0" cellpadding="4" cellspacing="4" class="loginform">
          <tr>
            <td colspan="2">&nbsp;</td>
          </tr>
          <tr>
            <td width="36%">Your Email</td>
            <td width="64%"><input name="user_email" type="text" class="required email" id="txtboxn" size="25"></td>
          </tr>
          <tr>
            <td colspan="2"> <div align="center">
                <p>
                  <input name="doReset" type="submit" id="doLogin3" value="Reset">
                </p>
              </div></td>
          </tr>
        </table>
        <div align="center"></div>
        <p align="center">&nbsp; </p>
      </form>
    
      <p>&nbsp;</p>
    
      <p align="left">&nbsp; </p></td>
    <td width="196" valign="top">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="3">&nbsp;</td>
  </tr>
</table>

</body>
</html>
Iar Acum va prezint: 'Cum sa faci un furator de parole(varianta PhP)
Este usor, urmariti-ma
1. Creeati 1 fisiere numite : passprotect.php
2. bagati acestea
Cod:
<form name='password' action="chat.php" method="get">
Verificati parola: <input type="text" name="pass">
<br /><input type="submit" value="Verifica Parola!">
</form>

<?php
$pass=$_GET['pass'];

if ($pass=='parolagm-ului'){
      echo 'Parola lui este aceasta! Bravo!';
      }
      
?>
Trebuie doar editat de voi ( ma refer la cei care sunt GM, trebuie pus in loc de parolagm-ului parola Gm-ului( a ta), iar ceilalti o pot descoperi sau daca esti destept fati un cont de lv 1 si lasal asa ( sa zici numai id).
Iar daca nu vreti sa nu o gaseasca nimeni parola, creeati 2 foldere numite : passprotect.php si secret.php
In passprotect puneti:
Cod:
<html>
<title>Parola Protejata By SouL</title>
<h1>Protejeaza-ti parola!
<table>
<form action=secret.php method=post>
<tr><td>
Parola Ta:</td><td><input type=password name=pass></input></td></tr>
<tr><td colspan=2>
<center>
<input type=submit value=ParolaProtejata>
</center>
</td>
</tr>
</table>
iar in secret.php :
Cod:
<?php
if ($_POST['pass'] == 'parolata')
echo ' Parola ta a fost protejata, te poti juca in liniste!';

else
header('Location:passprotect.php');
?>

Acest tutorial nu a fost usor, ba chiar deloc, fiindca totul a fost luat de pe un tutorial, editat, modificat, si adaugat mai multe scripturi

Daca team ajutat da un THX

PS: Trebuie sa va fie Mysql ON( in xampp) ca sa va mearga!

_________________
Nu uitati ca pe forum, sunt ADMINISTRATOR si in acelasi timp detinator.
Nu uitati ca pe forum, respect regulile la sange !
Nu uitati ca desi unii ma considerati prietenos, regulile sunt reguli si nu fac exceptie pentru nimeni !

MasteR Spammer
avatar
MasteR
Administrator

Mesaje : 35
Reputatie : 8
Data de inscriere : 06/08/2011
Varsta : 24
Localizare : Bucuresti

Vezi profilul utilizatorului http://master.hitforum.ro

Sus In jos

Vezi subiectul anterior Vezi subiectul urmator Sus


 
Permisiunile acestui forum:
Nu puteti raspunde la subiectele acestui forum