douzhun4124 2016-04-14 07:38
浏览 39

PHP和JSON在localhost上工作但不在共享主机上工作

I have an API I’m trying to integrate into my web application (a bitcoin website), which is written in php. The API has a php library, and they communicate through JSON. On my server I have 3 scripts: the script that calls the function I require (blockTest.php), the script that has all my credentials (i.e. API key, pin, API version; cred.php), and the library for the block.io API which has all their methods (block_io.php).

My first php script has the following code:

<?php

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

require_once 'block_io.php';
require_once 'cred.php';

$addressInfo = $block_io_btc->get_my_addresses(array())

?>

I’ve set up the development environment on my localhost and these scripts work fine. I can make all the calls to the block.io API and get the appropriate data. However, when I upload my scripts to my shared hosting i get the following errors:

Fatal error: Uncaught exception 'Exception' with message 'Failed: '
in/home/sites/public_html/vendor/block_io.php:124 Stack trace: #0
/home/sites/public_html/vendor/block_io.php(65): BlockIo-
>_request('get_my_addresse...', Array) #1
/home/sites/public_html/vendor/blockTest.php(14): BlockIo-
>__call('get_my_addresse...', Array) #2 
/home/sites/public_html/vendor/blockTest.php(14): BlockIo-
>get_my_addresses(Array) #3 {main} thrown in 
/home/sites/public_html/vendor/block_io.php on line 124

Step by step, this corresponds to the following lines of code in block_io.php(65):

$response = $this->_request($name, $args);

and in blockTest.php(14):

$addressInfo = $block_io_btc->get_my_addresses(array())

and in block_io.php(124):

if ($json_result->status != 'success') { throw new Exception('Failed: ' .    
$json_result->data->error_message); }

   // Spit back the response object or fail
  return $result ? $json_result : false;        
}

The error is that status != success. This is the http status, but there is no data->error_message. I went onto their website to play around with their API. If I enter my details correctly I get the following output:

status = 200:success

As you can see the response is a 200: success with the correct credentials. When I change the credentials by entering the wrong API key I get the following:

status = 404:error

In the latter case there is a 404: error. In my production environment I do not get any data->error_message. This lead me to believe that the php version my Web host uses might be creating the problem with json_decode(), since block_io.php line 121-130 is this:

$json_result = json_decode($result);

if ($json_result->status != 'success') { throw new Exception('Failed: ' .    
$json_result->data->error_message); }

   // Spit back the response object or fail
 return $result ? $json_result : false;        
}

I’ve made sure my php version on MAMP is the same as my web host (5.5). Still nothing (remember the exact same script works fine on localhost). I checked the http status of my script here and all is good:

(reputation isn't good enough to post more than 2 links, but my server is responding with a 200:success status)

So…. I really don’t know what the problem is. The phpinfo() for my web host shows that they have JSON enabled and as far as I can tell they do not have magic_quotes = on in their php.ini. If they did have magic_quotes on I attempted to stripslashes() on the $json_result & separately on $result in block_io.php but to no avail. Now I really don’t know what else to try!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 python的qt5界面
    • ¥15 无线电能传输系统MATLAB仿真问题
    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100