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

  • Home
  • SEARCH
  • 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 8330577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:09:54+00:00 2026-06-09T02:09:54+00:00

I am making a simple oauth site. In index.php : <?php session_start(); if (empty($_SESSION[‘authentication’]))

  • 0

I am making a simple oauth site.

In index.php:

<?php
session_start();
if (empty($_SESSION['authentication']))
    $_SESSION['authentication'] = 'pending';
?>
<html>
<form action="oauth.php" method="post">
    <span>
    <?php
        echo $_SESSION['authentication'];
    ?>
    </span>
    <input type="hidden" name="action" value="authenticate">
    <input type="submit" value="authenticate">
</form>
</html>

In oauth.php:

<?php
session_start();
if (isset($_POST['action']) and $_POST['action'] == 'authenticate') {
    $url = $serverAuth ... ;
    header('Location: ' . $url); //google oauth, it will come back to oauth.php
    exit();
}

if (isset($_GET['code'])) {
    $ch = curl_init($serverToken);
    $result = curl_exec($ch);
    $tokens = json_decode($result, true);

    if (isset($tokens['access_token'])) {
        $_SESSION['authentication'] = 'good';
        $_SESSION['access_token'] = $tokens['access_token'];
    } else {
        $_SESSION['authentication'] = 'error';
    }

    header('Location: ./');
    exit();
}

if (isset($_GET['error'])) {
    if ($_GET['error'] == 'access_denied')
        $_SESSION['authentication'] = 'denied';
    else
        $_SESSION['authentication'] = 'error';
    header('Location: ./');
    exit();    
}
?>

I want to make the site like: by default, $_SESSION['authentication'] is “pending”; when I refresh the page, every session variables are gone, and $_SESSION['authentication'] reset to default. But I cannot reset $_SESSION at the beginning of index.php, because functions in oauth.php have header() to redirect to this page.

How to deal with it?

  • 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-06-09T02:09:55+00:00Added an answer on June 9, 2026 at 2:09 am

    You must start the session on every single page that requires access to $_SESSION. Only destroy it when explicitly requested, e.g. on logout.

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

Sidebar

Related Questions

I'm making simple http post request using libcurl to index.php file on my web
making a simple movie review site to practice PHP. on one page ( a
I'm making simple C# Winform application. There is a Form having a textbox. I
Making a simple three question PHP quiz. Each question is displayed on a page
I'm making simple php chat, and i need to refresh messages in one div.I
Making a simple program which will generate a multiple choice form. I have an
I am making simple grid like game ( grid is matrix 128x128) and matrix
I am making simple connection between two table - first one called users has
Making a simple application, so when the user logs out of Windows, it of
Im making a simple alternative to the default linux system monitor. Im looking to

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.