Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/242.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php数组在第一次加载时不返回_Php_Ajax_Facebook_Json - Fatal编程技术网

php数组在第一次加载时不返回

php数组在第一次加载时不返回,php,ajax,facebook,json,Php,Ajax,Facebook,Json,我正在尝试调试一个facebook脚本,该脚本将用户配置文件加载到一个表单中,然后您可以编辑该表单 问题在于,当您第一次加载页面时,脚本没有返回$user\u profile数组。但是,随后的页面刷新将返回数组fine 如何让这个数组在第一次加载页面时返回,从而运行脚本的其余部分?它是一个AJAX解决方案还是JSON?如果是的话,我该怎么做 提前谢谢 <?php $is_fb = false; $is_linkedin = false; $reg_method = $_GET[

我正在尝试调试一个facebook脚本,该脚本将用户配置文件加载到一个表单中,然后您可以编辑该表单

问题在于,当您第一次加载页面时,脚本没有返回
$user\u profile
数组。但是,随后的页面刷新将返回数组fine

如何让这个数组在第一次加载页面时返回,从而运行脚本的其余部分?它是一个
AJAX
解决方案还是
JSON
?如果是的话,我该怎么做

提前谢谢

<?php
  $is_fb = false;
  $is_linkedin = false;
  $reg_method = $_GET['conn_social'];

  if (isset($_GET['in_uid'])){
    $cur_in_uid = $_GET['in_uid'];
  }

  if ($reg_method == "facebook"){
    $is_fb = true;
  }
  else if ($reg_method == "linkedin"){
    $is_linkedin = true;
  }

  if($is_fb) {
    global $fbconfig;
    $facebook = new Facebook(array( 'appId'  => $fbconfig['appid'],
                                    'secret' => $fbconfig['secret'],
                                    'cookie' => true ));

    $user = $facebook->getUser();

    if ($user) {
      try {
        // Proceed knowing you have a logged in user who's authenticated.
        $user_profile = $facebook->api('/me');

        //the below line is for debugging only - THIS PRINTS ON SCREEN REFRESH ONLY
        print_r($user_profile); 
      } catch (FacebookApiException $e) {
        error_log($e);
        $user = null;
      }
    }

    $is_fb_uid_exist = hl_check_fb_uid_exist($user_profile['id']);

    if($is_fb_uid_exist){
      $is_fb = false;
    }

    try{
      $fql = "select name, first_name, last_name, birthday_date, sex, profile_url, hometown_location, current_location, work, activities, interests, music, tv, movies, books, quotes, about_me, website, education, sports, inspirational_people, languages, pic_square from user where uid=" . $user;

      $param = array( 'method'    => 'fql.query',
                      'query'     => $fql,
                      'callback'  => '' );

      $fqlResult = $facebook->api($param);
    }

 }
?>

第一行可能有问题

    $is_fb=false;
当页面重定向时,这是否为false

如果是,则不执行此操作

   if($is_fb) {
     //Your Code
     //Your Code   
    }

你真的需要检查硬件在sohey发布一个查询它与你的问题无关,但我第一次看到一个格式良好的代码!表达敬意!谢谢,很抱歉在粘贴代码时不小心将其截断,现在已编辑。嘿,谢谢您的回复。是的,我确实使用了登录url。单击facebook按钮并完成身份验证后,我会被重定向到正确的页面。在这个页面上,数组在第一次加载时不会返回。如果我刷新页面,它会返回罚款…@user1917727我已经编辑了答案..检查..可能有用不,原来的$is_fb=false$当url为…/register?$social\u conn=facebook时,is\u fb设置为true。代码执行得很好,并跳过所有正确的环,直到我对其进行注释为止。此时,第一次加载时不会返回数组。如果您刷新,它会返回良好。