Jump to content

Help with PHP and cUrl


John Smith

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.