2017-09-16 13 views
0

私はPHPで作業しており、コードのブロック内で関数を呼び出そうとしていますが、なぜそれがエラーの原因であるのかわからないUncaught Error: Call to undefined function GetUserIDFromUsername()致命的なエラー:未定義の関数、PHPを呼び出す

PHPコード

if(isset($_GET["updateRow"])){ 
 
    
 
      $_fbURL = $_GET["ajaxified"]; 
 
       
 
      if(!empty($_fbURL)){ 
 
        $url = $_fbURL; 
 
        $urlParts = explode("facebook.com/", $url); 
 
        $username = GetUserIDFromUsername($urlParts[1]); 
 

 

 

 
       function GetUserIDFromUsername($username) { 
 
        // For some reason, changing the user agent does expose the user's UID 
 
        $options = array('http' => array('user_agent' => 'some_obscure_browser')); 
 
        $context = stream_context_create($options); 
 
        $fbsite = file_get_contents('https://www.facebook.com/' . $username, false, $context); 
 

 
        // ID is exposed in some piece of JS code, so we'll just extract it 
 
        $fbIDPattern = '/\"entity_id\":\"(\d+)\"/'; 
 
        if (!preg_match($fbIDPattern, $fbsite, $matches)) { 
 
         throw new Exception('Unofficial API is broken or user not found'); 
 
        } 
 
        return $matches[1]; 
 
       } 
 

 
       echo "My Id is : "." ".$username; 
 

 
      } 
 
       
 
       
 
        
 
      
 
      }

+0

** URL **から正確なデータを解析していますか?応答については必ず確認してください。 –

+0

私は同じコードをちょうどissetメソッドを削除しようとすると、それは必要なデータを返します、あなたはfacebookのURLを提供する簡単なPHPでそれを試すことができます – Nadeem

答えて

1

それを呼び出す前に、あなたの方法GetUserIDFromUsername($のparams)を宣言します。 メソッドを呼び出し元の上に移動できます。

+0

それは私のために働いてくれましたsoooooありがとう! – Nadeem

関連する問題