Advertisement
lwis

Untitled

Jun 29th, 2011
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.97 KB | None | 0 0
  1. <?PHP
  2. if(!isset($_COOKIE['oauth_token'])){
  3. session_start();
  4. if (empty($_SESSION['access_token']) || empty($_SESSION['access_token']['oauth_token']) || empty($_SESSION['access_token']['oauth_token_secret'])) {header('Location: ./clearsessions.php');}
  5.  
  6. $access_token = $_SESSION['access_token'];
  7. $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']);
  8.  
  9. setcookie('oauth_token', $access_token['oauth_token'], time()+60*60*24*30);
  10. setcookie('oauth_token_secret', $access_token['oauth_token_secret'], time()+60*60*24*30);
  11. }
  12. //else use the cookies
  13. else{
  14. $oauth_token = $_COOKIE['oauth_token'];
  15. $oauth_token_secret = $_COOKIE['oauth_token_secret'];
  16. $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $oauth_token, $oauth_token_secret);
  17. }
  18. ?>
  19.  
  20. Does not work with the rest of my code, yet this does;
  21.  
  22. <?PHP
  23. session_start();
  24. if (empty($_SESSION['access_token']) || empty($_SESSION['access_token']['oauth_token']) || empty($_SESSION['access_token']['oauth_token_secret'])) {header('Location: ./clearsessions.php');}
  25.  
  26. $access_token = $_SESSION['access_token'];
  27. $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']);
  28. ?>
  29.  
  30. Which is just a direct snippet from the larger cookie piece of code.
  31.  
  32. From what I can tell it's not using the stored cookies either (but that could be for other reasons) which means there must be a problem with this snippet and the larger piece of code, which I have included below.
  33.  
  34. <?php
  35. require_once('twitteroauth/twitteroauth.php');require_once('config.php');
  36.  
  37. //database connection.
  38.  
  39. if(!isset($_COOKIE['oauth_token'])){
  40. session_start();
  41. if (empty($_SESSION['access_token']) || empty($_SESSION['access_token']['oauth_token']) || empty($_SESSION['access_token']['oauth_token_secret'])) {header('Location: ./clearsessions.php');}
  42.  
  43. $access_token = $_SESSION['access_token'];
  44. $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']);
  45.  
  46. setcookie('oauth_token', $access_token['oauth_token'], time()+60*60*24*30);
  47. setcookie('oauth_token_secret', $access_token['oauth_token_secret'], time()+60*60*24*30);
  48. }
  49. //else use the cookies
  50. else{
  51. $oauth_token = $_COOKIE['oauth_token'];
  52. $oauth_token_secret = $_COOKIE['oauth_token_secret'];
  53. $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $oauth_token, $oauth_token_secret);
  54. }
  55.  
  56. $apistatus = $connection->get('account/rate_limit_status');
  57. $remaininghits = $apistatus->remaining_hits;
  58. if($remaininghits >= 50){
  59.  
  60. $param = array('count' => 1);
  61. $mostrecenttweet = $connection->get('statuses/user_timeline', $param);
  62. $userinfo = $connection->get('account/verify_credentials');
  63.  
  64. $uid = $userinfo->id;
  65. $uname = $userinfo->screen_name;
  66. $tweetcount = $userinfo->statuses_count;
  67. $resettime = $apistatus->reset_time;
  68. $mostrecentid = $mostrecenttweet[0]->id_str;
  69.  
  70. $SQL = "SELECT uid FROM users WHERE uid = '$uid'";
  71. $result = mysql_query($SQL);
  72.  
  73. if(mysql_num_rows($result) == false){
  74. $debug = 'first entry';
  75.  
  76. $store = "INSERT INTO users (uid, uname, tweetcount, mostrecentid, count, debug) VALUES ('$uid', '$uname', '$tweetcount', '$mostrecentid', 1, '$debug')";
  77. mysql_query($store);
  78. $id = md5('=a!-nd'.$uid);
  79. $store = "INSERT INTO notes (id, uid, tid, note, hidden) VALUES ('$id', '$uid', '0', 'Your very first note, welcome!', 0)";
  80. mysql_query($store);
  81.  
  82. for($page = 1; $page <= 16; ++$page){
  83. $params = array('page' => $page, 'count' => 200);
  84. $content = $connection->get('statuses/user_timeline', $params);
  85. foreach($content as $post){
  86. $ctid = $post->id_str;
  87. $id = md5('=a!-nd'.$ctid);
  88. if(preg_match('(^(Note to self|NTS)\W*|#NTS$)', $post->text)){
  89. $title = preg_replace('(^(Note to self|NTS)\W*|#NTS$)', '', $post->text);
  90. $store = "INSERT INTO notes (id, uid, tid, note, hidden) VALUES ('$id', '$uid', '$ctid', '$title', 0)";mysql_query($store);}
  91. }}
  92. }
  93.  
  94. else{
  95. $debug = 'already registered';
  96.  
  97. $sql = "SELECT mostrecentid, count, tweetcount FROM users WHERE uid = '$uid'";
  98. $queryresult = mysql_query($sql);
  99. $result = mysql_fetch_array($queryresult);
  100. $currentcount = $result['count'] + 1;
  101. $ltid = $result['mostrecentid'];
  102. $tweetcountold = $result['tweetcount'];
  103. $tweetsbetween = $tweetcount - $tweetcountold;
  104. $pageno = ceil($tweetsbetween / 200);
  105.  
  106. for($page = 1; $page <= $pageno; ++$page){
  107. $params = array('since_id' => $ltid, 'page' => $page);
  108. $content = $connection->get('statuses/user_timeline', $params);
  109. foreach($content as $post){
  110. $ctid = $post->id_str;
  111. $id = md5('=a!-nd'.$ctid);
  112. $SQL = "SELECT uid, tid FROM notes WHERE uid = '$uid' AND tid = '$ctid'";
  113. $result = mysql_query($SQL);
  114. if(mysql_num_rows($result) == false){
  115. if(preg_match('(^(Note to self|NTS)\W*|#NTS$)', $post->text)){
  116.     $title = preg_replace('(^(Note to self|NTS)\W*|#NTS$)', '', $post->text);
  117.     $store = "INSERT INTO notes (id, uid, tid, note, hidden) VALUES ('$id', '$uid', '$ctid', '$title', 0)";
  118.     mysql_query($store);
  119. }}}}
  120.  
  121. $updateuser = "UPDATE users SET tweetcount = '$tweetcount', uname = '$uname', mostrecentid = '$mostrecentid', count = '$currentcount', debug = '$debug' WHERE uid = '$uid'";
  122. mysql_query($updateuser);
  123. }
  124.  
  125. $notes = array();
  126. $SQL = "SELECT id, note FROM notes WHERE uid = '$uid' AND hidden = 0 ORDER BY tid ASC";
  127.     $results = mysql_query($SQL);  
  128.     while($rows = mysql_fetch_array($results)){
  129.     $notes[] = $rows['note'].'<a style="float:right;" href="http://lewisjuggins.co.uk/oauth/delete.php?id='.$rows['id'].'">&#10003;</a><br/><br/>';
  130.     }
  131.  
  132.  
  133. $notesdone = array();
  134. $SQL = "SELECT id, note FROM notes WHERE uid = '$uid' AND hidden = 1 ORDER BY tid DESC LIMIT 0, 5 ";
  135.     $results = mysql_query($SQL);  
  136.     while($rows = mysql_fetch_array($results)){
  137.     $notesdone[] = $rows['note'].'<br/><br/>';
  138.     }
  139. }
  140.  
  141.  
  142.  
  143. else{
  144. $notes = 'You dont have enough API calls to use this, please wait for your reset at '.$resettime;
  145. }
  146.  
  147. mysql_close($db_handle);
  148.  
  149. /* Include HTML to display on the page. */
  150. include('html.inc');
  151. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement