John Smith Posted April 22, 2009 Share Posted April 22, 2009 Hi, how can I make 'a' work with 'b' a= <?php include_once('twitter.php'); $curTwitter = new twitter("username", "password"); if (isset($_POST['submit'])) { $twitter_status = $_POST['twitter_stat']; if (strlen($twitter_status) > 0) { if( $curTwitter->setStatus($twitter_status) == true) echo "<p>Updated Succesfully</p>"; else echo "<p>Twitter is unavailable at this time</p>"; } else echo "<p>Error: I won't send blank messages!</p>"; } ?> <!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>Set your status on Twitter</title> </head> <body> <h2>Set your status on Twitter</h2> <p><strong>What are you doing?</strong></p> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <input name="twitter_stat" type="text" id="twitter_stat" size="40" maxlength="140" /> <input type="submit" name="submit" id="submit" value="Send"/> </form> </body> </html> b= <?php $login = $_POST["username"].":".$_POST["password"]; $tweets = "http://twitter.com/statuses/friends_timeline.xml?count=10"; $tw = curl_init(); curl_setopt($tw, CURLOPT_URL, $tweets); curl_setopt($tw, CURLOPT_USERPWD, $login); curl_setopt($tw, CURLOPT_RETURNTRANSFER, TRUE); $twi = curl_exec($tw); $tweeters = new SimpleXMLElement($twi); $latesttweets = count($tweeters); if ($latesttweets>2) { echo "<h3>".$latesttweets." Latest Tweets </h3>"; } //echo the data foreach ($tweeters->status as $twit1) { //This finds any links in $description $description = $twit1->text; $description = preg_replace("#(^|[\n ])@([^ \"\t\n\r<]*)#ise", "'\\1<a href=\"http://www.twitter.com/\\2\" >@\\2</a>'", $description); $description = preg_replace("#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t<]*)#ise", "'\\1<a href=\"\\2\" >\\2</a>'", $description); $description = preg_replace("#(^|[\n ])((www|ftp)\.[^ \"\t\n\r<]*)#ise", "'\\1<a href=\"http://\\2\" >\\2</a>'", $description); echo "<div class='user'><a href=\"http://www.twitter.com/", $twit1->user->screen_name,"\" target=\"_blank\"><img border=\"0\" class=\"twitter_followers\" src=\"", $twit1->user->profile_image_url, "\" title=\"", $twit1->name, "\" /></a>\n"; echo "<div class='name'>", $twit1->user->name,"</div>"; echo "<div class='text'>".$description."</div></div>";} curl_close($tw); ?> a's include file= <?php class twitter { private $user; private $pass; private $ch; private $twitterHost = "http://twitter.com/"; public function __construct($username, $password) { $this->user = $username; $this->pass = $password; /* Create and setup the curl Session */ $this->ch = curl_init(); curl_setopt($this->ch, CURLOPT_VERBOSE, 1); curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($this->ch, CURLOPT_USERPWD, "$this->user:$this->pass"); curl_setopt($this->ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); curl_setopt($this->ch, CURLOPT_POST, 1); } public function __destruct() { /*clean Up */ curl_close($this->ch); } public function setStatus($stat) { if(strlen($stat) < 1) return false; /*Set the host information for the curl session */ $this->twitterHost .= "statuses/update.xml?status=". urlencode(stripslashes(urldecode($stat))); curl_setopt($this->ch, CURLOPT_URL, $this->twitterHost); /* Execute and get the http code to see if it was succesfull or not*/ $result = curl_exec($this->ch); $resultArray = curl_getinfo($this->ch); if ($resultArray['http_code'] == 200) ; return true; return false; } } ?> Any help is wanted. Thanks. =] Link to comment https://forums.phpfreaks.com/topic/155167-help-with-php-and-curl/ Share on other sites More sharing options...
Yesideez Posted April 22, 2009 Share Posted April 22, 2009 Please edit your post and surround the code with [code] and [/code] tags! Link to comment https://forums.phpfreaks.com/topic/155167-help-with-php-and-curl/#findComment-816251 Share on other sites More sharing options...
John Smith Posted April 22, 2009 Author Share Posted April 22, 2009 Please edit your post and surround the code with [code] and [/code] tags! Sorry, I was looking for them but i didnt find them. ^ Link to comment https://forums.phpfreaks.com/topic/155167-help-with-php-and-curl/#findComment-816258 Share on other sites More sharing options...
John Smith Posted April 22, 2009 Author Share Posted April 22, 2009 Bump. Link to comment https://forums.phpfreaks.com/topic/155167-help-with-php-and-curl/#findComment-816336 Share on other sites More sharing options...
trq Posted April 22, 2009 Share Posted April 22, 2009 You might want to define what you mean by 'work'. Do they not work now? What exactly is the problem? Link to comment https://forums.phpfreaks.com/topic/155167-help-with-php-and-curl/#findComment-816338 Share on other sites More sharing options...
tang Posted April 22, 2009 Share Posted April 22, 2009 You'll get more help if you offer more information. What is a supposed to do? What is b supposed to do? What isn't working? Any error messages? What are you trying to achieve? Link to comment https://forums.phpfreaks.com/topic/155167-help-with-php-and-curl/#findComment-816340 Share on other sites More sharing options...
John Smith Posted April 22, 2009 Author Share Posted April 22, 2009 Ok, sorry about that. 'a' has a script for updating your twitter status. It has an included file, which is the last block of code. 'b' is the page which displays the twitter timeline. I have page 'b' all up and working. I want to include page 'a' so you can update your status. At this moment they use differnet cUrl connections. Is it possible to use the same one? And to have it all nicely in a single <? ?> block? Thanks Link to comment https://forums.phpfreaks.com/topic/155167-help-with-php-and-curl/#findComment-816381 Share on other sites More sharing options...
John Smith Posted April 22, 2009 Author Share Posted April 22, 2009 When I tried to put the codes together I got this error. "Warning: Missing argument 2 for twitter::__construct(), called in /home/xxxx/public_html/xxxx/twitter.php5 on line 67 and defined in /home/xxxx/public_html/xxxx/update.php5 on line 10" Thanks Link to comment https://forums.phpfreaks.com/topic/155167-help-with-php-and-curl/#findComment-816481 Share on other sites More sharing options...
trq Posted April 22, 2009 Share Posted April 22, 2009 When I tried to put the codes together I got this error. "Warning: Missing argument 2 for twitter::__construct(), called in /home/xxxx/public_html/xxxx/twitter.php5 on line 67 and defined in /home/xxxx/public_html/xxxx/update.php5 on line 10" Thanks Why don't you post the problematic code then? Link to comment https://forums.phpfreaks.com/topic/155167-help-with-php-and-curl/#findComment-816886 Share on other sites More sharing options...
John Smith Posted April 23, 2009 Author Share Posted April 23, 2009 Line 67 of twitter.php5 is ?> Line 10 of update.php5 is public function __construct($username, $password) {; Link to comment https://forums.phpfreaks.com/topic/155167-help-with-php-and-curl/#findComment-817059 Share on other sites More sharing options...
trq Posted April 25, 2009 Share Posted April 25, 2009 Remove the ; from the end of... public function __construct($username, $password) {; Link to comment https://forums.phpfreaks.com/topic/155167-help-with-php-and-curl/#findComment-818835 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.