Little help please with one php script.

GinoCorad

Newbie
Joined
Apr 6, 2012
Messages
8
Reaction score
0
Here is my php script , i want to know if is possible to post my result from : wesite/folder/script.php?id=$i to Twitter , Facebook or other site like this two .

Result are like : name , description and link


thanks and sorry for my bad English

Code:
<?
$con = mysql_connect("localhost","base","base");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
  mysql_select_db("base", $con);
  
  $result = mysql_query("SELECT * FROM cronjob");
  while ($row = mysql_fetch_array($result)) 
    {
      $lastcheck = $row['lastcheck'];
      $addvideo  = $row['addvideo']; 
    }
  $i = $lastcheck;
  $end = $lastcheck+$addvideo;
  $result = mysql_query("UPDATE cronjob SET lastcheck='$end'") or die(mysql_error());
  do {  
        echo "<font color=green> $i > $end </font>";
        $ch   = curl_init();
        curl_setopt($ch, CURLOPT_URL, "wesite/folder/script.php?id=$i");
        curl_setopt($ch, CURLOPT_USERPWD, "admin:admin");  
        curl_setopt($ch, CURLOPT_HEADER, false);
        curl_exec($ch);
        curl_close($ch);
     ++$i;
     } 
while ($i <= $end);
?>
 
Your code is seriously strange. You need to comment your code and give a more detailed instruction. However, I took the time to figure it out. For Twitter use:

Code:
<?
$con = mysql_connect("localhost","base","base") OR die('Could not connect: ' . mysql_error());
mysql_select_db("base", $con);
  
$result = mysql_query("SELECT * FROM cronjob");
while ($row = mysql_fetch_array($result)) {
      $lastcheck = $row['lastcheck'];
      $addvideo  = $row['addvideo'];
}

$i = $lastcheck;
$end = $lastcheck+$addvideo;

$result = mysql_query("UPDATE cronjob SET lastcheck='$end'") or die(mysql_error());
do {  
    echo "<font color=green> $i > $end </font>";

    //Here goes the twitter url. can't post urls thats why the string looks so messed up
    $url = 'http:" . "//" . "twitter" . "." . "com/statuses/update.xml';
    $curl_handle = curl_init();
    curl_setopt($curl_handle, CURLOPT_URL, "$url");
    curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
    curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl_handle, CURLOPT_POST, 1);
    curl_setopt($curl_handle, CURLOPT_POSTFIELDS, "status=$TWITTERMESSAGE");
    curl_setopt($curl_handle, CURLOPT_USERPWD, "$TWITTERUSERNAME:$TWITTERPASSWORD");
    //Post to twitter
    $buffer = curl_exec($curl_handle);
    curl_close($curl_handle);
    if (empty($buffer)) {
        echo "Error!";
    } else {
        echo "Done!";
    }

     ++$i;
}while ($i <= $end);
?>

Replace $TWITTERMESSAGE, $TWITTERUSERNAME, $TWITTERPASSWORD with your variables.
 
thanks for you help i will try right now :P


on : wesite/folder/script.php?id=$i , website to run , folder is protec by password via httacces to prevent acces from other and script.php is a video grabber that i want to run via cronjob every 10 minutes . now you seee why i so strange ? :)

Ps. and vairables : $lastcheck = last id saved in db and $addvideo = how many times to run the script ex : 100
 
Last edited:
Back
Top