首先,为了解决这个问题,我花了几个小时在StackOverflow上查看这个问题的答案,并尝试自己解决它,但它只是不起作用(不再)了.所以无论如何...
昨天,一切正常.去睡觉,醒来,用facebook登录在我的2个网站上不再工作了.登录链接将我发送到Facebook页面,这需要我批准应用程序,但在它重定向回到网站后,它不会登录我.我很快跟踪问题,getUser()总是返回0.所以我使用非常非常基本的代码设置一个新的(测试)应用程序,只是为了看看它是否有效.它没有.这是代码:
<?php
session_start();
require_once("facebook.php");
$config = array();
$config['appId'] = '199971880127910'; //test app so I don't mind showing these
$config['secret'] = 'e065588cb1edd96f821de8b3d362c488';
$config['trustForwarded'] = true;
$facebook = new Facebook($config);
try {
$user = $facebook->getUser();
var_dump($user);
} catch (Exception $e) {
$e->getMessage();
}
$loginUrl = $facebook->getLoginUrl(array('redirect_uri' => 'http://gtcrais.redirectme.net/test/'));
echo "<a href='".$loginUrl."'>Login</a>";
?>
Run Code Online (Sandbox Code Playgroud)
在第二个答案在这里吸引我的目光.我尝试了这个解决方案并且它不起作用,所以我打开了base_facebook.php并滚动到"代码"传递给某个变量的行 - 第458行:
$ code = $ this-> getCode();
我回应了这一点,它正确显示了从URL传递的代码参数.有问题的行原来是那一行下面的一对行:
$ access_token = $ this-> getAccessTokenFromCode($ code);
传递$ code变量时,此函数将值false返回给$ access_token.在该函数中,这部分代码抛出异常:
try {
// need to circumvent json_decode …Run Code Online (Sandbox Code Playgroud) 这样可行:
myphpfile.php:
<?php
header('Content-disposition: attachment; filename=myfile.pdf');
header('Content-type: application/pdf');
readfile('myfile.pdf');
?>
Run Code Online (Sandbox Code Playgroud)
在这里调用php文件,PDF下载工作正常:
<a class = "oglasavanje" href = "../../cjenik/myphpfile.php">download</a><br/>
Run Code Online (Sandbox Code Playgroud)
但这不起作用:
<?php
header('Content-disposition: attachment; filename=myfile.xlsx');
header('Content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
readfile('myfile.xlsx');
?>
Run Code Online (Sandbox Code Playgroud)
.pdf和.xlsx文件都在同一个文件夹中.当我点击"下载"链接弹出下载窗口时,我保存文件,但无法打开该文件.它给了我以下错误:
Excel无法打开文件'myfile.xlsx',因为文件格式或文件扩展名无效.验证文件是否已损坏,以及文件扩展名是否与文件格式匹配.
当我手动打开文件时(即不通过链接下载),文件打开正常
我正在使用WAMP,如果这很重要的话.
任何帮助表示赞赏.
---编辑---
我在php.net上找到了这段代码:
ob_clean();
flush();
Run Code Online (Sandbox Code Playgroud)
所以最终的代码看起来像这样,它的工作原理:
$file = "myfile.xlsx";
header('Content-disposition: attachment; filename='.$file);
header('Content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Length: ' . filesize($file));
header('Content-Transfer-Encoding: binary');
header('Cache-Control: must-revalidate');
header('Pragma: public');
ob_clean();
flush();
readfile($file);
Run Code Online (Sandbox Code Playgroud)
谢谢大家的答案.