2014-04-24 9 views
0

나는 PHP 서버 응용 프로그램을 만들기위한 지침을 따르려고 노력 중이며 몇 가지 구문 오류가 발생합니다.구문 분석 오류 : 예기치 않은 구문 오류, '?'

오류 메시지 :

:

Parse error: syntax error, unexpected '?' in 
D:\inetpub\wwwroot\cmpswoo1\CMPPROJ_Web\ServerApp\api2\db_functions2.php on line 134 

그래서 나는 오류가 있었다 알고, 난 그냥 작은 따옴표가 문제의 원인이 여기에

<?php 
class db_functions2 { 
private $db; 
//put your code here 
// constructor 
function __construct() { 
    require_once 'db_connect2.php'; 
    // connecting to database 
    $this->db = new db_connect2(); 
    $this->db->connect(); 
} 
// destructor 
function __destruct() { 
} 
/** 
* Random string which is sent by mail to reset password 
*/ 
public function random_string() 
{ 
$character_set_array = array(); 
$character_set_array[] = array('count' => 7, 'characters' => 'abcdefghijklmnopqrstuvwxyz'); 
$character_set_array[] = array('count' => 1, 'characters' => ''); 
$temp_array = array(); 
foreach ($character_set_array as $character_set) { 
    for ($i = 0; $i < $character_set['count']; $i++) { 
     $temp_array[] = $character_set['characters'][rand(0, strlen($character_set['characters']) - 1)]; 
    } 
} 
shuffle($temp_array); 
return implode('', $temp_array); 
} 
public function forgotPassword($forgotpassword, $newpassword, $salt){ 
$result = mysql_query("UPDATE `Users` SET `encryptedPassword` = '$newpassword',`salt` = '$salt' 
      WHERE `email` = '$forgotpassword'"); 
if ($result) { 
return true; 
} 
else 
{ 
return false; 
} 
} 
/** 
* Adding new user to mysql database 
* returns user details 
*/ 
public function storeUser($FirstName, $LastName, $DOB, $email, $Username, $Password) { 
    $uuid = uniqid('', true); 
    $hash = $this->hashSSHA($Password); 
    $encrypted_password = $hash["encrypted"]; // encrypted password 
    $salt = $hash["salt"]; // salt 
    $result = mysql_query("INSERT INTO Users(unique_id, FirstName, LastName, email, DOB, Username, encryptedPassword, salt, created_at) VALUES('$uuid', '$FirstName', '$LastName', '$email', '$DOB', '$Username', '$encryptedPassword', '$salt', NOW())"); 
    // check for successful store 
    if ($result) { 
     // get user details 
     $uid = mysql_insert_id(); // last inserted id 
     $result = mysql_query("SELECT * FROM Users WHERE uid = $id"); 
     // return user details 
     return mysql_fetch_array($result); 
    } else { 
     return false; 
    } 
} 
/** 
* Verifies user by username and password 
*/ 
public function getUserByUsernameAndPassword($Username, $Password) { 
    $result = mysql_query("SELECT * FROM Users WHERE usernameE = '$Username'") or die(mysql_error()); 
    // check for result 
    $no_of_rows = mysql_num_rows($result); 
    if ($no_of_rows > 0) { 
     $result = mysql_fetch_array($result); 
     $salt = $result['salt']; 
     $encrypted_password = $result['encryptedPassword']; 
     $hash = $this->checkhashSSHA($salt, $Password); 
     // check for password equality 
     if ($encryptedPassword == $hash) { 
      // user authentication details are correct 
      return $result; 
     } 
    } else { 
     // user not found 
     return false; 
    } 
} 
/** 
* Checks whether the username is valid or fake 
*/ 
public function validUsername($Username) 
{ 
$isValid = true; 
$atIndex = strrpos($Username, "@"); 
if (is_bool($atIndex) && !$atIndex) 
{ 
    $isValid = false; 
} 
else 
{ 
    $domain = substr($Username, $atIndex+1); 
    $local = substr($Username, 0, $atIndex); 
    $localLen = strlen($local); 
    $domainLen = strlen($domain); 
    if ($localLen < 1 || $localLen > 64) 
    { 
    // local part length exceeded 
    $isValid = false; 
    } 
    else if ($domainLen < 1 || $domainLen > 255) 
    { 
    // domain part length exceeded 
    $isValid = false; 
    } 
    else if ($local[0] == '.' || $local[$localLen-1] == '.') 
    { 
    // local part starts or ends with '.' 
    $isValid = false; 
    } 
    else if (preg_match('/\.\./', $local)) 
    { 
    // local part has two consecutive dots 
    $isValid = false; 
    } 
    else if (!preg_match('/^[A-Za-z0-9\-\.]+$/', $domain)) 
    { 
    // character not valid in domain part 
    $isValid = false; 
    } 
    else if (preg_match('/\.\./', $domain)) 
    { 
    // domain part has two consecutive dots 
    $isValid = false; 
    } 
    else if 
    (!preg_match('/^(\\.|[A-Za-z0-9!#%&`_=\/$'*+?^{}|~.-])+$/',str_replace("\\","",$local))) 
    { 
    // character not valid in local part unless 
    // local part is quoted 
    if (!preg_match('/^"(\\"|[^"])+"$/', 
     str_replace("\\","",$local))) 
    { 
     $isValid = false; 
    } 
    } 
    if ($isValid && !(checkdnsrr($domain,"MX") ||checkdnsrr($domain,"A"))) 
    { 
    // domain not found in DNS 
    $isValid = false; 
    } 
} 
return $isValid; 
} 
/** 
* Check user is existed or not 
*/ 
public function isUserExisted($Username) { 
    $result = mysql_query("SELECT Username from Users WHERE Username = '$Username'"); 
    $no_of_rows = mysql_num_rows($result); 
    if ($no_of_rows > 0) { 
     // user existed 
     return true; 
    } else { 
     // user not existed 
     return false; 
    } 
} 
/** 
* Encrypting password 
* returns salt and encrypted password 
*/ 
public function hashSSHA($Password) { 
    $salt = sha1(rand()); 
    $salt = substr($salt, 0, 10); 
    $encrypted = base64_encode(sha1($Password . $salt, true) . $salt); 
    $hash = array("salt" => $salt, "encrypted" => $encrypted); 
    return $hash; 
} 
/** 
* Decrypting password 
* returns hash string 
*/ 
public function checkhashSSHA($salt, $Password) { 
    $hash = base64_encode(sha1($Password . $salt, true) . $salt); 
    return $hash; 
} 
} 

?> 
+0

을해야 하는가? – Jenz

+2

http://ericlippert.com/2014/03/05/how-to-debug-small-programs/를 참조하십시오. – Samuel

답변

1

해결하는 방법을 모른다 따라서 변경하십시오

(!preg_match('/^(\\.|[A-Za-z0-9!#%&`_=\/$'*+?^{}|~.-])+$/',str_replace("\\","",$local))) 

는 사람 :

(!preg_match('/^(\\.|[A-Za-z0-9!#%&`_=\/$\'*+?^{}|~.-])+$/',str_replace("\\","",$local))) 
1

정규 표현식 문자열은 '을 열뿐만 아니라 ' 포함되어 있습니다. \으로 탈출하십시오. 오류는 없어야합니다.

(!preg_match('/^(\\.|[A-Za-z0-9!#%&`_=\/$'*+?^{}|~.-])+$/',str_replace("\\","",$local))) 

라인 134

(!preg_match('/^(\\.|[A-Za-z0-9!#%&`_=\/$\'*+?^{}|~.-])+$/',str_replace("\\","",$local))) 
관련 문제