PHP数组没有返回第一次加载 [英] php array not returning on first load
问题描述
我试图调试加载用户的个人资料,可以在其中再编辑形式的Facebook的脚本。
现在的问题是,该脚本不返回 $ USER_PROFILE
数组当您第一次加载页面。但是,页的后续刷新返回数组细
我如何能得到这个数组在页面第一次加载恢复,因此得到了脚本的其余部分运行?它是一个 AJAX
解决方案,或 JSON
?如果是的话我将如何去呢?
在此先感谢。
< PHP
$ is_fb = FALSE;
$ is_linkedin = FALSE;
$ reg_method = $ _GET ['conn_social'];
如果(使用isset($ _ GET ['in_uid'])){
$ cur_in_uid = $ _GET ['in_uid'];
}
如果($ reg_method ==脸谱){
$ is_fb = TRUE;
}
否则,如果($ reg_method ==LinkedIn){
$ is_linkedin = TRUE;
}
如果($ is_fb){
全球$运行fbconfig;
$ = Facebook的新的Facebook(阵列('的appid => $运行fbconfig ['的appid'],
秘密=> $运行fbconfig ['秘密'],
'饼干'=>真正 ));
$ USER = $ facebook->的getUser();
如果($用户){
尝试 {
//继续知道你有一个登录谁的身份验证的用户。
$ USER_PROFILE = $ facebook-> API(/我);
//下面的线仅用于调试 - 这将打印ON SCREEN仅刷新
的print_r($ USER_PROFILE);
}赶上(FacebookApiException $ E){
error_log中($ E);
$ USER = NULL;
}
}
$ is_fb_uid_exist = hl_check_fb_uid_exist($ USER_PROFILE ['身份证']);
如果($ is_fb_uid_exist){
$ is_fb = FALSE;
}
尝试{
$ FQL =选择的名字,名字,姓氏,birthday_date,性别,PROFILE_URL,hometown_location,current_location,工作,活动,兴趣,音乐,电视,电影,书籍,报价,about_me,网站,教育,体育,inspirational_people,语言文字,pic_square从用户其中uid =。 $用户;
$参数=阵列('法'=>fql.query,
'查询'=> $ FQL,
'回调'=> '');
$ fqlResult = $ facebook-> API($参数);
}
}
?>
在第一行也许问题。
$ is_fb = FALSE;
当页面重定向这是该评估是假的呢?
如果是的话,这是没有执行。
如果($ is_fb){
//你的code
//你的code
}
I'm trying to debug a facebook script that loads a users profile into a form which you can then edit.
The problem is that the script does not return the $user_profile
array when you first load the page. However, subsequent refreshes of the page return the array fine.
How can I get this array to return on the first load of the page and therefore get the rest of the script to run? Is it an AJAX
solution, or JSON
? if so how would i go about it?
Thanks in Advance.
<?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);
}
}
?>
Maybe problem on the first line..
$is_fb=false;
when the page is redirecting this is this evaluating as false?
If yes then this is not executing.
if($is_fb) {
//Your Code
//Your Code
}
这篇关于PHP数组没有返回第一次加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!