Jump to content
Fórum Script Brasil
  • 0

Ajuda com preg_match


nabilfx
 Share

Question

 

Tenho um script para me enviar o email cadastrado em php por  preg_match.

Mais a Arroba @ e o que vem escrito antes, fica invisível, O que esta escrito na frente aparece, tipo gmail.com

 

Como poderia arrumar isso para aparecer o email completo no registro online.

Aqui esta o script.

 

<?php
 
    function Connect(){
        //Set global variables so they can be used in this function
        global $hostName; global $userName;
        global $password; global $database;
        $status = mysql_connect($hostName,$userName,$password); //Attempt to connect to Database
     
        if(!$status){echo 'Server Not Found'; exit;} //Hosting Server not found
        if(!@mysql_select_db($database)){echo 'Database Not Found'; exit;} //Database not found
        return $status; //Return link on established connection
    }
    function CheckKey($hash,$name){  //Check weather Md5 hash matches
        global $secretKey;
        $checkHash = md5($name.$secretKey);
        if(strcmp($checkHash,$hash) == 0){
            return 'pass'; //hash matches
        }else{
            return 'fail'; //hash failed
        }
    }
    function CleanInput($input){ //Sanitize user input
        $cleanInput = mysql_real_escape_string($input); //Use string escape
        if(preg_match('/[^@.a-z_\-0-9\s]/i',$cleanInput) == 1){ // Using regular expression
            echo 'Bad Input ==> ' . $input; exit; //Failed, exit to prevemt sql injection hacks
        }
        return $cleanInput; //Return clean input
    }
?>

 

unnamed.png

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

aqui o código RegisterUser.php que registra o serverconect.php

<?php
	include('ServerConnect.php');
	$connection = Connect();//Attempt to Connect to MYSQL Server & DataBase
	
	//Get variables from unity
	$name = $_POST['name'];
	$date = strtotime(date("Y-m-d"));
	$tables = $_POST['tables'];
	//Security Check
	$hash = $_POST['hash'];
	if(CheckKey($hash,$name) == 'fail'){ //Check if hash is valid
		echo 'Security Failure'; exit;
	}
		//Make sure all input is sql injection safe
	$name =  CleanInput($name);
	$tables = CleanInput($tables);
	//Split difficulty tables
	$tablesBroken = explode(' ', $tables);
	$arr = Array();
	$i = 0;$x = 0;
	foreach($tablesBroken as $table){ //Check if name is in any of our tables
		$sql = "SELECT * FROM $table WHERE name = '$name'";
		$result = mysql_query($sql) or Die('Query failed: ' . mysql_error()); 
		$count = mysql_num_rows($result);
		//Process Results : Tally up how many times we fing the name 
		if($count > 0){ 
			$arr[$i] = 1;
			$x++;
		}else{
			$arr[$i] = 0;
		}
		$i++;
	}
	if($x == 0){ //Name not in use in any table
		foreach($tablesBroken as $table){//Insert the user in all tables
			$sql = "INSERT INTO $table (name,score,date)
			VALUES('$name',0,'$date')";
			$result = mysql_query($sql) or Die('Query failed: ' . mysql_error()); 
		}echo 'Registration Complete'; exit;
	}else if($x >= Count($tablesBroken)){//Name in use in all tables
		echo 'Already Used'; exit; //exit
	}else{//In use but not complete in all tables
		for($c = 0; $c < Count($tablesBroken); $c++){
			if($arr[$c] == 0){ //Insert name in tables where it is not present
				$toTable = $tablesBroken[$c];
				$sql = "INSERT INTO $toTable(name,score,date)
				VALUES('$name',0,'$date')";
				$result = mysql_query($sql) or Die('Query failed: ' . mysql_error()); 
			}
		}echo 'Registration Complete'; exit;
	}
?>
 
Link to comment
Share on other sites

  • 0

aqui o DatabaseTools.php

<?php
	include('ServerConnect.php');
	$connection = Connect();//Attempt to Connect to MYSQL Server & DataBase
	//Get variables from Unity
	$mode = $_POST['mode'];
	$table = $_POST['table'];
	if($mode == 0){ //Create current table
		$sql = "CREATE TABLE $table(id INT(10) AUTO_INCREMENT,
		PRIMARY KEY(id),
		name VARCHAR(25),
		score INT(10),
		date VARCHAR(25))"; //we keep date a varchar in the database
		$result = mysql_query($sql) or Die('Query failed: ' . mysql_error()); 
		echo $table.' Created'; exit;
	}else if ($mode == 1){
		//Delete scores below input score
		$score = $_POST['score'];
	    $sql = "DELETE FROM $table WHERE score < '$score'";
		$result = mysql_query($sql) or Die('Query failed: ' . mysql_error()); 	
		echo 'Deleted'; exit;
	}else if ($mode == 2){
		//Delete scores below posted date
		$date = strtotime($_POST['date']);
		$sql = "DELETE FROM $table WHERE date < '$date'";
		$result = mysql_query($sql) or Die('Query failed: ' . mysql_error()); 
		echo 'Deleted'; exit;
	}
?>

 

aqui o SendHighScores.php

<?php
	include('ServerConnect.php');
	$connection = Connect(); //Attempt to Connect to MYSQL Server & DataBase
	
	//Get variables from Unity
	$table = $_POST['table'];
	$name = $_POST['name'];
	$score = $_POST['score'];
	$updating = $_POST['updating'];
	$date = strtotime(date("Y-m-d")); //Get Time
	//Security Check
	$hash = $_POST['hash'];
	if(CheckKey($hash,$name) == 'fail'){ //Check if hash is valid
		echo 'Security Failure'; exit;
	}
		//Make sure all input is sql injection safe
	$name =  CleanInput($name);
	$table = CleanInput($table);
	$score =  CleanInput($score);
	$updating =  CleanInput($updating);
	//Run Query (inser or update)
	if($updating == 0){ //Free entry So make new row
		$sql = "INSERT INTO $table (name,score,date)
		VALUES('$name','$score','$date')";
	}else{ //We are updating a previously registered user
		$sql = "UPDATE $table SET score = '$score',
		date = '$date' WHERE name = '$name'";
	}
	$result = mysql_query($sql) or Die('Query failed: ' . mysql_error()); 
	
	//Now update our table, by ordering it by descending score
	$sql = "ALTER TABLE $table ORDER BY score DESC,id DESC";
	$result = mysql_query($sql) or Die('Query failed: ' . mysql_error()); 
	
	echo 'Accepted';
?>

 

aqui o GetHighScores.php

<?php
	include('ServerConnect.php');
	$connection = Connect();//Attempt to Connect to MYSQL Server & DataBase
	
	//Get variables from unity
	$table = $_POST['table'];
	$scope = $_POST['scope'];
	$limit = $_POST['limit'];
	//Security Check
	$hash = $_POST['hash'];
	if(CheckKey($hash,$table) == 'fail'){ //Check if hash is valid
		echo 'Security Failure'; exit;
	}
		//Make sure all input is sql injection safe
	$table = CleanInput($table);
	$scope =  CleanInput($scope);
	$limit =  CleanInput($limit);
	//Create a Query For The Right Table
	if($scope == 'AllTime'){ //Get All scores
		$sql = "SELECT * FROM $table LIMIT 0,$limit";
	}else{ //Get scores posted today
		$date = strtotime(date("Y-m-d")); //Today's date
		$sql = "SELECT * FROM $table WHERE date = '$date' LIMIT 0,$limit";
	}
	$result = mysql_query($sql) or Die('Query failed: ' . mysql_error());
	//1.Build a string of all scores to send back
	$info = "";
	while($found = mysql_fetch_array($result)){
		$info = $info .'@'. $found['name'] .':'. $found['score'];
	}
	echo $info;
?>

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Forum Statistics

    • Total Topics
      149.6k
    • Total Posts
      646.2k
×
×
  • Create New...