Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a PHP script that displays Tweets embedded in a site I built out on my local machine. When I uploaded the site to my IIS 8.0 server, the PHP script no longer works and I receive this error:

Warning: Invalid argument supplied for foreach() in C:\inetpub\wwwroot\i360_new\footer.php on line 76

The script is:

    ini_set('display_errors', 1);

    /** Set access tokens here - see: **/
    $settings = array(
        'oauth_access_token' => "xxxxx",
        'oauth_access_token_secret' => "xxxxx",
        'consumer_key' => "xxxxx",
        'consumer_secret' => "xxxxx"

    /** Perform a GET request and echo the response **/
    /** Note: Set the GET field BEFORE calling buildOauth(); **/
    $url = "";
    $getfield = '?screen_name=interactive360&count=1';
    $requestMethod = 'GET';
    $twitter = new TwitterAPIExchange($settings);
    $string = json_decode($twitter->setGetfield($getfield)
    ->buildOauth($url, $requestMethod)
    ->performRequest(),$assoc = TRUE);
    foreach($string as $items)
            echo $items['text']."<br />";

I thought it might be a PHP version issue but my local machine is running 5.4.10 and my server is running 5.4.14.

share|improve this question
Which line is line 76? "Warning" is not an error -- "warning" can often be completely ignored. Put a "print_r($string)" lin in just before the foreach() to see what is actually in that sucker – JDS Sep 30 '13 at 14:45
$string is actually returning empty which is causing the error. I don't know why it's returning empty though. – user715564 Sep 30 '13 at 16:08

Did you compare both servers phpinfo()? While running in almost the same environment each server can work differently depending on which modules are installed.

share|improve this answer
The only comparison I did was the version number. Is there something else I should specifically be looking for? They also both have JSON 1.2.1 enabled. – user715564 Sep 30 '13 at 14:33

You might want to make sure that the $string isn't empty. I believe a ForEach will throw this error if you provide a string that is empty. It looks like the string depends on TwitterAPIExchange.php, I see the 'Require Once', but ensure it's configured correctly.

share|improve this answer
Actually, it looks like you are correct. The $string variable is returning empty. I looked through TwitterAPIExchange.php and the only thing that I noticed might be the problem is that is uses CURL. My IIS server has CURL enabled though. – user715564 Sep 30 '13 at 14:50
Could this possibly have something to do with user permissions on the IIS side? – user715564 Sep 30 '13 at 15:11
Have you checked to see what $twitter has in it? I'm assuming that $settings hasn't changed since you copied it over to production, but might wanna check that as well. – Noobixide Sep 30 '13 at 15:43
Ok so when I echo $twitter I get this error: Catchable fatal error: Object of class TwitterAPIExchange could not be converted to string in C:\inetpub\wwwroot\i360_new\footer.php on line 80 – user715564 Sep 30 '13 at 15:51
Don't do "echo" do "print_r( $twitter );" -- you can't "echo" an Object – JDS Sep 30 '13 at 16:15

It turns out this was an SSL/CURL issue. In the TwitterAPIExchange.php file, I had to add these two lines to the CURL options array:

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.