0

I am working with php, and trying to call a function within a block of code, but I do not know why it causing the error that Uncaught Error: Call to undefined function GetUserIDFromUsername(), while it is defined later then.

The PHP Code

 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;

             } 
               
               
                    
           
           }

2
  • Are you sure you are parsing exact data from the URL? Be sure about the response. Commented Sep 16, 2017 at 7:43
  • when I try the same code just removing the isset method, then it returns the required data, you can try that on a simple php, providing your facebook url Commented Sep 16, 2017 at 7:44

1 Answer 1

2

Declare your method GetUserIDFromUsername($params) before calling it. You can move the method to the top of the caller.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.