Jump to content

san2629

New Members
  • Posts

    2
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

san2629's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. this is my code look like this is my first page when user request for twitter// sucess.php <?php session_start(); $token=$_SESSION['logintoken']; //login token contain email of the user include("config.php"); require('twitteroauth/twitteroauth.php'); if($token) { $sql=mysql_query("SELECT id from f_login where email='$token'"); $rowloginfetch=mysql_fetch_array($sql); $id1=$rowloginfetch['id']; $_SESSION['id']=$id1; $currentuserid=$_SESSION['id']; $decodecurrent=base64_encode($currentuserid); $packet=base64_encode($id1); $sql1=mysql_query("SELECT * from f_general where gid='$id10'"); //to get name $row1=mysql_num_rows($sql1); while($row = mysql_fetch_array($sql1)) { $fname=$row['fname1']; $lname=$row['lname1']; $_SESSION['name']=$fname." ".$lname; } if($_POST['submit']) { header("Location:tweet.php"); } ?> <form method="post" action="<?php echo $PHP_SELF; ?>" name="add"> <input type="submit" id="Mybutton" style="background-color:#E2E1E0; " value="Add Application" name="submit" onmouseover="fun();" onmouseout="fun1();"/> </form> //-----------------------------this is my page after redirect <?php session_start(); require('twitteroauth/twitteroauth.php'); include('config.php'); $registered=$_SESSION['id']; $consumer_key="--XXXXXXXXXXXXXXXXXXXXX----"; $consumer_secret="--XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; //creating a object and define consumer key and consumer token $twitteroauth=new TwitterOAuth($consumer_key,$consumer_secret); $request_token = $twitteroauth->getRequestToken('http://abc.com/tweetback.php'); // Saving them into the session $token=$request_token['oauth_token']; $token1=$request_token['oauth_token_secret']; //now we are calling the url and send above data in it if($twitteroauth->http_code==200) { // Let's generate the URL and redirect $url = $twitteroauth->getAuthorizeURL($request_token['oauth_token']); if($url) { $query=mysql_query("select * from f_twitter where loginiduser='$registered'"); $result=mysql_fetch_array($query); if(empty($result)) {//first time when user does not have any record in database $query=mysql_query("insert into f_twitter(token,token_secret,url,loginiduser)values('$token','$token1','$url','$registered')"); header('Location: '. $url); }else {//if record exist then update the staus in database $query=mysql_query("update f_twitter set token='$token',token_secret='$token1',url='$url' where loginiduser='$registered'"); session_write_close(); header('Location:'.$url); } }else{ // It's a bad idea to kill the script, but we've got to know when there's an error. die('Something wrong happened.'); } } ?> //this is my page after returning from twitter <?php session_start(); include('config.php'); require('twitteroauth/twitteroauth.php'); if($_SESSION['id']) { $idloginuser=$_SESSION['id']; $sqlquery1=mysql_query("select token,token_secret,url from f_twitter where loginiduser='$idloginuser'"); $rowquery1=mysql_fetch_array($sqlquery1); $token=$rowquery1['token']; $token_secret=$rowquery1['token_secret']; $url=$rowquery1['url']; if(!empty($_GET['oauth_verifier']) && !empty($token) && !empty($token_secret)) { $consumer_key="--XXXXXXXXXXXXXXXXXXXXXxxxx--"; $consumer_secret="--XXXXXXXXXXXXXXXXXXXX----"; $newobject=new TwitterOAuth($consumer_key,$consumer_secret,$token,$token_secret); $tokencall=$newobject->getAccessToken($_GET['oauth_verifier']); $_SESSION['access_token'] = $tokencall; $user_info = $newobject->get("account/verify_credentials"); //you get userid if(isset($user_info->error)) //if generate error send to authorise url of twitter { header("Location:$url"); }else { $query12=mysql_query("select * from users where oauth_provider = 'twitter' AND oauth_uid = ". $user_info->id); $result=mysql_fetch_array($query12); if(empty($result)) { $verifier=$_GET['oauth_verifier']; $query = mysql_query("INSERT INTO users (oauth_provider, oauth_uid, username, oauth_token, oauth_secret,loginid,oauth_verifier) VALUES ('twitter', {$user_info->id}, '{$user_info->screen_name}', '$token', '$token_secret','$idloginuser','$verifier')"); $query1 = mysql_query("SELECT * FROM users WHERE id = " . mysql_insert_id()); $result = mysql_fetch_array($query1); }else { // Update the tokens $query = mysql_query("UPDATE users SET oauth_token = '$token', oauth_secret = '$token_secret', oauth_verifier='$verifier' WHERE oauth_provider = 'twitter' AND oauth_uid = {$user_info->id}"); } $_SESSION['primarykey']=$result['id']; $_SESSION['username'] =$result['username']; $_SESSION['oauth_uid'] = $result['oauth_uid']; $_SESSION['oauth_provider'] =$result['oauth_provider']; $_SESSION['oauth_token1'] =$result['oauth_token']; $_SESSION['oauth_secret'] =$result['oauth_secret']; $home_timeline = $newobject->get('http://api.twitter.com/1/statuses/home_timeline.json?count=30'); $_SESSION['timeline']=$home_timeline; if($texttopost) { $newobject->post('statuses/update', array('status' => $texttopost)); if($newobject) { $_SESSION['sucess']="Your tweet has been posted successfully"; unset($_SESSION['datatosend']); header("Location:tweet.php"); }else { $_SESSION['failure']="There is some problem occur when connecting to twitter.Please try again"; } }elseif(!$texttopost && $_SESSION['oauth_token1'] && $_SESSION['oauth_secret']) { header("Location:success.php?data=true"); } }//end of else-------------------------------------------- } //end of if }else { header("Location:index.php?data"); } ?> MOD Edit: . . . tags added . . .
  2. hello everyone....i need your help i face session lost problem so many times and every times i just find out other logic to implement the code in different ways. but i don't get a perfect solution.Please help me to resolve this............why it was happened..... i searched google for it.........this is the common problem but i dont get any proper solution.............. recently i write a code to fetch tweets from twitter..but when returning back from .i lost my session value......... supp this is my page page.php when user click on button........i just check the form submitted like this session_start(); $_SESSION['id']=$id; //supp $id=10 if($_POST['submit']) { header("Location:tweet.php "); } i already included session_start() at the top of every page. in tweet.php i just generate a token and send user to twitter for authorization. in tweet.php i checked session started i check it with Print_r($_SESSION); in this page i used session like this session_start(); if($_SESSION['id']) { header("Location:$url") //$url will be authoritarian url generated by twitter oauth.. }else { header("Location:index.php") } after returning from twitter some times session variable are not lost.but sometimes i lost my session.this really irritates me....if logic is wrong then every time session destroyed............... i check my php.ini file configuration.. session_save.path=/tmp; //by default register global are off................. any help is appreciated................
×
×
  • 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.