Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6085161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:36:28+00:00 2026-05-23T11:36:28+00:00

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

  • 0
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);
}

Here is the snippet of code I am using, basically I want to store a long term cookie for the user so they don’t have to login to Twitter and go through the long process of authorizing my web app every time they connect. So I am attempting to use cookies with this library (twitteroauth) for some reason the page won’t load with this section of code, if I was to take out the if else and just leave the $_SESSION part in the code works without a hitch.

I’m quite confused as I’ve checked and the cookies are successfully getting stored, any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T11:36:28+00:00Added an answer on May 23, 2026 at 11:36 am

    I think your ‘check’ for the cookie is incorrect (not code wise, but logic wise), let me remove all the code exect for the if–else-statement:

    if(isset($_COOKIE['oauth_token'])){
        // Using $_SESSION
    }
    // else use the cookie
    else {
        // Using $_COOKIE
    }
    

    Your logic says ‘if the cookie exists use sessions, else use the cookie’ and I think you meant to say ‘if the cookie does not exist use sessions, else use the cookie’. You have to invert your check in the first if-statement.

    if(!isset($_COOKIE['oauth_token'])) {
        // Use cookie here
    }
    

    Update I’ve re-read the section you posted over and over again and, as you say your script does not have any output with that piece of code, the only thing I can come up with is that your application crashes on new TwitterOAuth(...);. Can you try to run your code without those two lines (temporarily remove them both and see if you have a page output).


    Update #2 I’ve noticed you said that your code-‘snippit’ does work, but the combined code does not. You use header('Location: ./clearsessions.php'); if the session is not set, if you replace that by echo "error";, do you get that in the browser window. Note This is very simplistic debugging as I have little knowledge of what goes on on your system, but it is proven to be effective in times. You can also choose to use the echo-flush() combo, which will force output to the browser everytime you pass a certain line (you can then check how far your code is executing).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I get Session object destruction failed when I use session_destroy(). session_start(); if(isset($_SESSION['user_id'])){ $_SESSION=array(); if(isset($_COOKIE[session_name()])){
<?php $Test = dsdsdad.dsad; if (isset($_COOKIE[$Test])) { echo I GOT A COOKIE WITH A
So i have this php: <?php if (isset($_COOKIE[currentsearchctrl])) { $cookz = $_COOKIE[currentsearchctrl]; $data =
this is my code in logout.php <?php if(isset($_COOKIE['cookie-username']) || isset($_COOKIE['cookie-password'])) { setcookie(cookie-username, NULL, time()-60*60*24*100);
in php i would do if (isset($_COOKIE['user']) && $_COOKIE['user'] == $valueFromDb) echo 'logged'; But
topic.php $id = isset($_GET['id']) ? intval($_GET['id']) : 0; $query = mysql_query(SELECT * FROM topics
I am using this PHP code: if (isset($_GET['c'])) { $pages = array(home, upload, signup);
Is there a benefit of using one over the other ? $lang = isset($_COOKIE['lang'])
from my logout.php : <?php require_once(includes/session.php); ?> <?php require_once(includes/functions.php); ?> <?php if ( isset(
I have set the cookie in header.php like below <?php if($_GET['signup'] == '123' &&

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.