php 代码适用于 mamp 但不适用于 ubuntu 服务器
我已经开始查看 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
确保你已经安装了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);
if you're not getting any clues from error messages.error_reporting(E_ALL|E_STRICT);