Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?PHP
- if(!isset($_COOKIE['oauth_token'])){
- session_start();
- if (empty($_SESSION['access_token']) || empty($_SESSION['access_token']['oauth_token']) || empty($_SESSION['access_token']['oauth_token_secret'])) {header('Location: ./clearsessions.php');}
- $access_token = $_SESSION['access_token'];
- $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']);
- setcookie('oauth_token', $access_token['oauth_token'], time()+60*60*24*30);
- setcookie('oauth_token_secret', $access_token['oauth_token_secret'], time()+60*60*24*30);
- }
- //else use the cookies
- else{
- $oauth_token = $_COOKIE['oauth_token'];
- $oauth_token_secret = $_COOKIE['oauth_token_secret'];
- $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $oauth_token, $oauth_token_secret);
- }
- ?>
- Does not work with the rest of my code, yet this does;
- <?PHP
- session_start();
- if (empty($_SESSION['access_token']) || empty($_SESSION['access_token']['oauth_token']) || empty($_SESSION['access_token']['oauth_token_secret'])) {header('Location: ./clearsessions.php');}
- $access_token = $_SESSION['access_token'];
- $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']);
- ?>
- Which is just a direct snippet from the larger cookie piece of code.
- 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.
- <?php
- require_once('twitteroauth/twitteroauth.php');require_once('config.php');
- //database connection.
- if(!isset($_COOKIE['oauth_token'])){
- session_start();
- if (empty($_SESSION['access_token']) || empty($_SESSION['access_token']['oauth_token']) || empty($_SESSION['access_token']['oauth_token_secret'])) {header('Location: ./clearsessions.php');}
- $access_token = $_SESSION['access_token'];
- $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']);
- setcookie('oauth_token', $access_token['oauth_token'], time()+60*60*24*30);
- setcookie('oauth_token_secret', $access_token['oauth_token_secret'], time()+60*60*24*30);
- }
- //else use the cookies
- else{
- $oauth_token = $_COOKIE['oauth_token'];
- $oauth_token_secret = $_COOKIE['oauth_token_secret'];
- $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $oauth_token, $oauth_token_secret);
- }
- $apistatus = $connection->get('account/rate_limit_status');
- $remaininghits = $apistatus->remaining_hits;
- if($remaininghits >= 50){
- $param = array('count' => 1);
- $mostrecenttweet = $connection->get('statuses/user_timeline', $param);
- $userinfo = $connection->get('account/verify_credentials');
- $uid = $userinfo->id;
- $uname = $userinfo->screen_name;
- $tweetcount = $userinfo->statuses_count;
- $resettime = $apistatus->reset_time;
- $mostrecentid = $mostrecenttweet[0]->id_str;
- $SQL = "SELECT uid FROM users WHERE uid = '$uid'";
- $result = mysql_query($SQL);
- if(mysql_num_rows($result) == false){
- $debug = 'first entry';
- $store = "INSERT INTO users (uid, uname, tweetcount, mostrecentid, count, debug) VALUES ('$uid', '$uname', '$tweetcount', '$mostrecentid', 1, '$debug')";
- mysql_query($store);
- $id = md5('=a!-nd'.$uid);
- $store = "INSERT INTO notes (id, uid, tid, note, hidden) VALUES ('$id', '$uid', '0', 'Your very first note, welcome!', 0)";
- mysql_query($store);
- for($page = 1; $page <= 16; ++$page){
- $params = array('page' => $page, 'count' => 200);
- $content = $connection->get('statuses/user_timeline', $params);
- foreach($content as $post){
- $ctid = $post->id_str;
- $id = md5('=a!-nd'.$ctid);
- if(preg_match('(^(Note to self|NTS)\W*|#NTS$)', $post->text)){
- $title = preg_replace('(^(Note to self|NTS)\W*|#NTS$)', '', $post->text);
- $store = "INSERT INTO notes (id, uid, tid, note, hidden) VALUES ('$id', '$uid', '$ctid', '$title', 0)";mysql_query($store);}
- }}
- }
- else{
- $debug = 'already registered';
- $sql = "SELECT mostrecentid, count, tweetcount FROM users WHERE uid = '$uid'";
- $queryresult = mysql_query($sql);
- $result = mysql_fetch_array($queryresult);
- $currentcount = $result['count'] + 1;
- $ltid = $result['mostrecentid'];
- $tweetcountold = $result['tweetcount'];
- $tweetsbetween = $tweetcount - $tweetcountold;
- $pageno = ceil($tweetsbetween / 200);
- for($page = 1; $page <= $pageno; ++$page){
- $params = array('since_id' => $ltid, 'page' => $page);
- $content = $connection->get('statuses/user_timeline', $params);
- foreach($content as $post){
- $ctid = $post->id_str;
- $id = md5('=a!-nd'.$ctid);
- $SQL = "SELECT uid, tid FROM notes WHERE uid = '$uid' AND tid = '$ctid'";
- $result = mysql_query($SQL);
- if(mysql_num_rows($result) == false){
- if(preg_match('(^(Note to self|NTS)\W*|#NTS$)', $post->text)){
- $title = preg_replace('(^(Note to self|NTS)\W*|#NTS$)', '', $post->text);
- $store = "INSERT INTO notes (id, uid, tid, note, hidden) VALUES ('$id', '$uid', '$ctid', '$title', 0)";
- mysql_query($store);
- }}}}
- $updateuser = "UPDATE users SET tweetcount = '$tweetcount', uname = '$uname', mostrecentid = '$mostrecentid', count = '$currentcount', debug = '$debug' WHERE uid = '$uid'";
- mysql_query($updateuser);
- }
- $notes = array();
- $SQL = "SELECT id, note FROM notes WHERE uid = '$uid' AND hidden = 0 ORDER BY tid ASC";
- $results = mysql_query($SQL);
- while($rows = mysql_fetch_array($results)){
- $notes[] = $rows['note'].'<a style="float:right;" href="http://lewisjuggins.co.uk/oauth/delete.php?id='.$rows['id'].'">✓</a><br/><br/>';
- }
- $notesdone = array();
- $SQL = "SELECT id, note FROM notes WHERE uid = '$uid' AND hidden = 1 ORDER BY tid DESC LIMIT 0, 5 ";
- $results = mysql_query($SQL);
- while($rows = mysql_fetch_array($results)){
- $notesdone[] = $rows['note'].'<br/><br/>';
- }
- }
- else{
- $notes = 'You dont have enough API calls to use this, please wait for your reset at '.$resettime;
- }
- mysql_close($db_handle);
- /* Include HTML to display on the page. */
- include('html.inc');
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement