Please Help Me Fix This Php Problem

Discussion in 'PHP' started by gpo85, Oct 1, 2010.

  1. #1
    This is the error I get

    http://img841.imageshack.us/img841/9560/errorreport.png

    I'm on a namecheap shared hosting account which should have curl so I do not know why this error comes up

    This is the php code


    <?php
    function twitterCapture() {
    // Set your username and password here
    $user = 'ENTER USERNAME HERE'; // Twitter Username
    $password = 'ENTER PASSWORD HEREc'; // Twitter Password

    $tw = curl_init("http://twitter.com"); //grabs the JSON format of your timelines
    curl_setopt($tw,CURLOPT_TIMEOUT, 30); // Timeout (for when Twitter is down)
    curl_setopt($tw,CURLOPT_USERPWD,$user . ":" . $password); // Uses your username and password
    curl_setopt($tw,CURLOPT_RETURNTRANSFER,1); // returns
    $json = curl_exec ($tw); // Executes the cURL and puts it into the varible
    return $json; // returns what was grabbed
    }
    $cachefile = 'cache/twitterCache.json'; // the location to your cache file
    $cachetime = 10 * 60; // set the cach time 10 * 60 (1 hour)
    // if the file exists // if and the time it was created is less then cache time
    if ( (file_exists($cachefile)) && ( time() - $cachetime < filemtime($cachefile) ) ) {
    // script will not use the cached version
    }else{ // the file didn't exist or is old
    ob_start(); // turn on the output buffering
    fwrite($fp, twitterCapture()); // writes to the file what was grabbed from the previouse function
    fclose($fp); // closes
    ob_end_flush(); // finishes and flushes the output buffer
    }
    ?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">

    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Little Twitter Widget</title>

    <!-- Start of CSS -->
    <link rel="stylesheet" type="text/css" href="css/reset.css" />
    <link rel="stylesheet" type="text/css" href="css/main.css" />
    <!-- Start of JS -->
    <script type="text/javascript" src="js/jquery-1.4.js"></script>
    <script type="text/javascript" src="js/main.js"></script>
    </head>
    <body>
    <div id="twitter_widget_top" class="center" ></div><!-- The top of the widget -->
    <div id="twitter_widget_body" class="center"> <!-- The body wrap -->

    <div id="twitter_widget_tweet"> <!-- The tweet area -->
    <div id="twitter_movement"> <!-- To position the icon reletive to -->
    <a id="twitter_icon" href="http://twitter.com/"></a> <!-- Twitter icon -->
    <div id="twitterWrap"> <!-- The blue area -->
    <div id="twitter"> <!-- The main twitter data -->
    <noscript>JavaScript must be on to view tweets</noscript> <!-- Incase no js -->
    <p class="tweet">Loading...</p> <!-- The Tweet -->
    <p class="created_at"></p> <!-- Date created -->
    </div>
    </div>
    <p class="clear"></p> <!-- Clear the floats -->
    </div>
    <a href="" class="previous tweetNav"></a><!-- Next button -->
    <p class="follow_me">Follow me - <a href="http://twitter.com/alexanderbor" class="screen_name"></a></p> <!-- Follow me link -->
    <a href="" class="next tweetNav"></a> <!-- Pre button -->
    <p class="clear"></p>
    </div>
    </div>
    <div id="twitter_widget_bottom" class="center"></div><!-- Bottom of widet -->
    <p class="info">Join my <span class="followedNumber"></span> followers - <span class="user_name"></span></p>
    </body>
    </html>
     
    gpo85, Oct 1, 2010 IP
  2. NuLLByTe

    NuLLByTe Active Member

    Messages:
    382
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    80
    #2
    
    <?php
    function twitterCapture() {
    // Set your username and password here
    $user = 'ENTER USERNAME HERE'; // Twitter Username
    $password = 'ENTER PASSWORD HEREc'; // Twitter Password
    $fp = "something.txt";
    $tw = curl_init("http://twitter.com"); //grabs the JSON format of your timelines
    curl_setopt($tw,CURLOPT_TIMEOUT, 30); // Timeout (for when Twitter is down)
    curl_setopt($tw,CURLOPT_USERPWD,$user . ":" . $password); // Uses your username and password
    curl_setopt($tw,CURLOPT_RETURNTRANSFER,1); // returns
    $json = curl_exec ($tw); // Executes the cURL and puts it into the varible
    return $json; // returns what was grabbed
    }
    $cachefile = 'cache/twitterCache.json'; // the location to your cache file
    $cachetime = 10 * 60; // set the cach time 10 * 60 (1 hour)
    // if the file exists // if and the time it was created is less then cache time
    if ( (file_exists($cachefile)) && ( time() - $cachetime < filemtime($cachefile) ) ) {
    // script will not use the cached version
    }else{ // the file didn't exist or is old
    ob_start(); // turn on the output buffering
    fopen ($fp, w);
    fwrite($fp, twitterCapture()); // writes to the file what was grabbed from the previouse function
    fclose($fp); // closes
    ob_end_flush(); // finishes and flushes the output buffer
    }
    ?>
    PHP:
    I added $fp = "something.txt" where something.txt is a file on your server in the same directory with this script. I also added fopen as before writing, the file must be opened.
     
    NuLLByTe, Oct 1, 2010 IP
  3. gpo85

    gpo85 Peon

    Messages:
    160
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Ran the modified script that you suggested above using Easy Php. This is the error recieved.


    Notice: Undefined variable: fp in C:\Program Files\EasyPHP-5.3.3\www\Project X\Fixed\nx00.php on line 21

    Notice: Use of undefined constant w - assumed 'w' in C:\Program Files\EasyPHP-5.3.3\www\Project X\Fixed\nx00.php on line 21

    Warning: fopen() [function.fopen]: Filename cannot be empty in C:\Program Files\EasyPHP-5.3.3\www\Project X\Fixed\nx00.php on line 21

    Notice: Undefined variable: fp in C:\Program Files\EasyPHP-5.3.3\www\Project X\Fixed\nx00.php on line 22

    Fatal error: Call to undefined function curl_init() in C:\Program Files\EasyPHP-5.3.3\www\Project X\Fixed\nx00.php on line 7
     
    gpo85, Oct 2, 2010 IP
  4. guardian999

    guardian999 Well-Known Member

    Messages:
    376
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #4
    Should fopen($cachefile,"w")
     
    guardian999, Oct 2, 2010 IP