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

发布于 2024-09-04 03:37:11 字数 1613 浏览 2 评论 0原文

我已经开始查看 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 会话,因为此代码有效

<?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>

I have start looking at a twitter php library http://github.com/abraham/twitteroauth, but i can't get it to work on my ubuntu server, but on my mac, with mamp it works without any problems.

This is the code that don't won't to work on my server, but in mamp. Yes i have edit config file

<?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.';
}

I have enable php session on my ubuntu server, because this code works

<?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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

停顿的约定 2024-09-11 03:37:11

确保你已经安装了curl - 对于ubuntu来说应该像sudo apt-get install curl一样简单

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

Make sure you have curl installed - for ubuntu should be as easy as sudo apt-get install curl

Also turn your PHP errors on ini_set('display_errors',1);
error_reporting(E_ALL|E_STRICT);
if you're not getting any clues from error messages.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文