php 代码适用于 mamp 但不适用于 ubuntu 服务器

标签 php session ubuntu twitter mamp

我已经开始查看 twitter php 库 http://github.com/abraham/twitteroauth ,但我无法让它在我的 ubuntu 服务器上运行,但在我的 mac 上,使用 mamp 它可以正常工作。

这是不会在我的服务器上工作的代码,但在 mamp.是的,我有编辑配置文件

<?php

/* Start session and load library. */
session_start();
require_once('twitteroauth/twitteroauth.php');
require_once('config.php');

/* Build TwitterOAuth object with client credentials. */
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);

/* Get temporary credentials. */
$request_token = $connection->getRequestToken(OAUTH_CALLBACK);

/* Save temporary credentials to session. */
$_SESSION['oauth_token'] = $token = $request_token['oauth_token'];
$_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];

/* If last connection failed don't display authorization link. */
switch ($connection->http_code) {
  case 200:
    /* Build authorize URL and redirect user to Twitter. */
    $url = $connection->getAuthorizeURL($token);
    header('Location: ' . $url); 
    break;
  default:
    /* Show notification if something went wrong. */
    echo 'Could not connect to Twitter. Refresh the page or try again later.';
}

我在我的 ubuntu 服务器上启用了 php session ,因为这段代码有效
<?php
       session_start();
       $_SESSION["secretword"] = "hello there";
       $secretword = $_SESSION["secretword"] ;
?>
<html>
<head>
<title>A PHP Session Example</title>
</head>
<body>
    <?php echo $secretword; ?>
</body>
</html>

最佳答案

确保你安装了 curl - ubuntu 应该像 sudo apt-get install curl 一样简单

同时打开你的 PHP 错误 ini_set('display_errors',1); error_reporting(E_ALL|E_STRICT);如果您没有从错误消息中获得任何线索。

关于php 代码适用于 mamp 但不适用于 ubuntu 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2950582/

相关文章:

python3 glob.glob 正则表达式只得到第一个匹配项

PHP:计算重复项并删除重复行

php - 从数据库中检查和返回值

scala - Safari 未发送 Play session cookie

linux - SVN。访问权

ubuntu - docker 群 : How to manually set node names?

PHPMailer 发送邮件但客户端收不到

php - Slick Carousel 中的垂直对齐图像

c# - 在每个异常上触发特定的ErrorHandlerAttribute?

java - 使用 Hibernate 拦截器时,我应该在 Struts2 Web 应用程序中的哪里打开和关闭 Hibernate session