2 erotiseis peri php & MySQL

Σε αυτή την περιοχή μπορείτε να βρείτε ή να αναζητήσετε πληροφορίες σχετικές με την PHP

Συντονιστές: WebDev Moderators, Super-Moderators, PHP Moderators

Απάντηση
Άβαταρ μέλους
AAT
Δημοσιεύσεις: 379
Εγγραφή: 23 Αύγ 2007 16:31
Τοποθεσία: Lemesos, Limassol
Επικοινωνία:

2 erotiseis peri php & MySQL

Δημοσίευση από AAT » 21 Απρ 2008 19:46

Geia sas paidia, exw 2 erotiseis

1. Exw ton parakato kodika:

Κώδικας: Επιλογή όλων

<?php
if &#40;$_POST&#91;'fname'&#93; && $_POST&#91;'lname'&#93; && $_POST&#91;'gender'&#93; && $_POST&#91;'bm'&#93; && $_POST&#91;'bd'&#93; && $_POST&#91;'by'&#93; && $_POST&#91;'cty'&#93; && $_POST&#91;'cou'&#93; && $_POST&#91;'inter'&#93; && $_POST&#91;'pcode'&#93; && $_POST&#91;'email'&#93; && $_POST&#91;'vemail'&#93; && $_POST&#91;'password'&#93; && $_POST&#91;'password2'&#93;&#41; &#123;
	    if &#40;!function_exists&#40;'checkdnsrr'&#41;&#41; &#123;
    	function checkdnsrr&#40;$host, $type = ''&#41; &#123;
    		if&#40;!empty&#40;$host&#41;&#41; &#123;
    			if&#40;$type == ''&#41; $type = "MX";
    			@exec&#40;"nslookup -type=$type $host", $output&#41;;
    			while&#40;list&#40;$k, $line&#41; = each&#40;$output&#41;&#41; &#123;
    				if&#40;eregi&#40;"^$host", $line&#41;&#41; &#123;
    					return true;
    				&#125;
    			&#125;
    			return false;
    		&#125;
    	&#125;
    &#125;
    function check_email_mx&#40;$email&#41; &#123; 
    	if&#40; &#40;preg_match&#40;'/&#40;@.*@&#41;|&#40;\.\.&#41;|&#40;@\.&#41;|&#40;\.@&#41;|&#40;^\.&#41;/', $email&#41;&#41; || 
    		&#40;preg_match&#40;'/^.+\@&#40;\&#91;?&#41;&#91;a-zA-Z0-9\-\.&#93;+\.&#40;&#91;a-zA-Z&#93;&#123;2,3&#125;|&#91;0-9&#93;&#123;1,3&#125;&#41;&#40;\&#93;?&#41;$/',$email&#41;&#41; &#41; &#123; 
    		$host = explode&#40;'@', $email&#41;;
    		if&#40;checkdnsrr&#40;$host&#91;1&#93;.'.', 'MX'&#41; &#41; return true;
    		if&#40;checkdnsrr&#40;$host&#91;1&#93;.'.', 'A'&#41; &#41; return true;
    		if&#40;checkdnsrr&#40;$host&#91;1&#93;.'.', 'CNAME'&#41; &#41; return true;
    	&#125;
    	return false;
    &#125;
  if &#40;$_POST&#91;'email'&#93; == $_POST&#91;'vemail'&#93;&#41; &#123;
  if &#40;check_email_mx&#40;$_POST&#91;'email'&#93;&#41;&#41; &#123;
    if &#40;$_POST&#91;'password'&#93; == $_POST&#91;'password2'&#93;&#41; &#123;
	 $con = mysql_connect&#40;"localhost","root",""&#41;;
     if &#40;!$con&#41;
      &#123;
      die&#40;'Error while connectiong to the database&#58; ' . mysql_error&#40;&#41;&#41;;
      &#125;
     mysql_select_db&#40;"db", $con&#41;;
	 $pass = md5&#40;base64_encode&#40;$_POST&#91;'password'&#93;&#41;&#41;;
	 $fname_p = mysql_real_escape_string&#40;$_POST&#91;'fname'&#93;&#41;;
	 $lname_p = mysql_real_escape_string&#40;$_POST&#91;'lname'&#93;&#41;;
	 $gender_p = mysql_real_escape_string&#40;$_POST&#91;'gender'&#93;&#41;;
	 $bm_p = mysql_real_escape_string&#40;$_POST&#91;'bm'&#93;&#41;;
	 $bd_p = mysql_real_escape_string&#40;$_POST&#91;'bd'&#93;&#41;;
	 $by_p = mysql_real_escape_string&#40;$_POST&#91;'by'&#93;&#41;;
	 $cty_p = mysql_real_escape_string&#40;$_POST&#91;'cty'&#93;&#41;;
	 $cou_p = mysql_real_escape_string&#40;$_POST&#91;'cou'&#93;&#41;;
	 $inter_p = mysql_real_escape_string&#40;$_POST&#91;'inter'&#93;&#41;;
	 $pcode_p = mysql_real_escape_string&#40;$_POST&#91;'pcode'&#93;&#41;;
	 $email_p = mysql_real_escape_string&#40;$_POST&#91;'email'&#93;&#41;;
	 $password_p = mysql_real_escape_string&#40;$pass&#41;;
function uip&#40;&#41;&#123;
	$ipParts = explode&#40;".", $_SERVER&#91;"REMOTE_ADDR"&#93;&#41;;
	if &#40;$ipParts&#91;0&#93; == "165" && $ipParts&#91;1&#93; == "21"&#41; &#123;    
    	if &#40;getenv&#40;"HTTP_CLIENT_IP"&#41;&#41; &#123;
        	$ip = getenv&#40;"HTTP_CLIENT_IP"&#41;;
        &#125; elseif &#40;getenv&#40;"HTTP_X_FORWARDED_FOR"&#41;&#41; &#123;
            $ip = getenv&#40;"HTTP_X_FORWARDED_FOR"&#41;;
        &#125; elseif &#40;getenv&#40;"REMOTE_ADDR"&#41;&#41; &#123;
            $ip = getenv&#40;"REMOTE_ADDR"&#41;;
        &#125;
    &#125; else &#123;
       return $_SERVER&#91;"REMOTE_ADDR"&#93;;
   	&#125;
   	return $ip;
&#125;
function gen&#40;&#41; &#123;
    $length        =    8;
    $num=array&#40;"1","2","3","4","5","6","7","8","9"&#41;;
    $password="";
    srand &#40;&#40;double&#41;microtime&#40;&#41;*1000000&#41;;
    $max = $length/2;
    for&#40;$i=1; $i<=$max; $i++&#41;
    &#123;
    $idt.=$num&#91;rand&#40;0,6&#41;&#93;;
    &#125;
	$id = $idt . "-" . rand&#40;1,1000000&#41;;
   $con = mysql_connect&#40;"localhost","root",""&#41;;
   if &#40;!$con&#41;
    &#123;
    die&#40;'Error while connectiong to the database&#58; ' . mysql_error&#40;&#41;&#41;;
    &#125;
  mysql_select_db&#40;"db", $con&#41;;
  $sql = mysql_query&#40;"SELECT * FROM users WHERE userid='$id'"&#41;;
  $result = mysql_num_rows&#40;$sql&#41;;
  if&#40;$result=="0"&#41;&#123;
  $reok = $id;
  &#125; else &#123;
   gen&#40;&#41;;
  &#125;
&#125;
gen&#40;&#41;;
$userip = uip&#40;&#41;;
	 mysql_query&#40;"INSERT INTO users &#40;userid, ip, fname, lname, gender, bm, bd, by, cty, cou, inter, pcode, email, password&#41; VALUES &#40;'&#123;$reok&#125;', '&#123;$userip&#125;', '&#123;$fname_p&#125;', '&#123;$lname_p&#125;', '&#123;$gender_p&#125;', '&#123;$bm_p&#125;', '&#123;$bd_p&#125;', '&#123;$by_p&#125;', '&#123;$cty_p&#125;', '&#123;$cou_p&#125;', '&#123;$inter_p&#125;', '&#123;$pcode_p&#125;', '&#123;$email_p&#125;', '&#123;$password_p&#125;'&#41;", $con&#41;;
      $message = "<b>Thank you for your registration at WebB3V.</b>";
mysql_close&#40;$con&#41;;
	&#125; else &#123;
	  $message = "<b>Please verify your password again.</b>";
	&#125;
  &#125; else &#123;
    $message = "<b>Please verify your email again.</b>";
  &#125;
  &#125; else &#123;
    $message = "<b>Please verify your email again.</b>";
  &#125;
&#125; else &#123;
  $message = "<b>Please fill all the fields correctly.</b>";
&#125;
echo $message;
?>
Edo ti lete na fteei, ola pane kala alla den moy bazei auta poy thelw sthn bash....

2. Nomizete oti to sistima einai arketa asfales?

Euxaristw,
AAT

Απάντηση

Επιστροφή στο “PHP Προγραμματισμός”

Μέλη σε σύνδεση

Μέλη σε αυτήν τη Δ. Συζήτηση: Δεν υπάρχουν εγγεγραμμένα μέλη και 0 επισκέπτες