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 7716007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:31:46+00:00 2026-06-01T02:31:46+00:00

<?php session_start(); if(isset($_POST[‘sessionNum’])){ //Declare my counter for the first time $_SESSION[‘initial_count’] = $_POST[‘sessionNum’]; $_SESSION[‘sessionNum’]

  • 0
<?php
    session_start();


        if(isset($_POST['sessionNum'])){
            //Declare my counter for the first time

            $_SESSION['initial_count'] = $_POST['sessionNum'];
            $_SESSION['sessionNum'] = $_POST['sessionNum'];

    }

    if(!isset($_SESSION['sessionCount'])){
         $_SESSION['sessionCount'] = 1;
    }
    else
    {
         $_SESSION['sessionCount']++;
    }

$sessionMinus =  $_SESSION['sessionCount'];


?>

How do I get it so that if $_SESSION['sessionCount'] is less than $_SESSION['sessionNum'], then add 1 to $_SESSION['sessionCount'] and if it equals $_SESSION['sessionNum'], then stop adding 1 to $_SESSION['sessionCount']?

Also if I go back on a previous page and I go back onto this page, I want $sessionMinus to go back to ‘1’, and finally if the user refreshes the page, then whatever number $sessionMinus is, keep it on that number when page refreshes.

  • 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-01T02:31:47+00:00Added an answer on June 1, 2026 at 2:31 am

    How do I get it so that if $_SESSION[‘sessionCount’] is less than
    $_SESSION[‘sessionNum’], then add 1 to $_SESSION[‘sessionCount’] and
    if it equals $_SESSION[‘sessionNum’], then stop adding 1 to
    $_SESSION[‘sessionCount’]?

    if (!isset($_SESSION['sessionCount'])) {
        $_SESSION['sessionCount'] = 1;
    }
    else if ($_SESSION['sessionCount'] < $_SESSION['sessionNum']) {
        ++$_SESSION['sessionCount'];
    }
    

    Also if I go back on a previous page and I go back onto this page, I
    want $sessionMinus to go back to ‘1’

    To do that you have to set $_SESSION['sessionMinus'] (or some other variable) in the previous page. Once this page is reached, the only way to know what happened earlier is specifically through $_SESSION variables. You cannot detect it on the spot.

    and finally if the user
    refreshes the page, then whatever number $sessionMinus is, keep it on
    that number when page refreshes.

    This is not possible. You cannot tell if the page was refreshed or loaded from scratch¹. What you could do is use the PRG pattern and count the “P” page as “the user just got here” and the “G” page as “the user has refreshed the page”. You can set a variable (e.g. $_SESSION['redirecting'] = true) from the “P” page and modify it on the “G” page ($_SESSION['redirecting'] = false); just before you do that, check if it was true to begin with. If it was, then the user is here due to your redirect (which will only happen once). If it was already false, they have refreshed the page.


    ¹You can try to do it, again through $_SESSION, but really you are just guessing. There is no way to know for certain.

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

Sidebar

Related Questions

<?php session_start(); include(connection.php); if(isset($_SESSION['uname'])) { header(location:account.php); die(); } ?> <!DOCTYPE html PUBLIC -//W3C//DTD XHTML
I have this code <?php session_start(); if (isset($_GET[cmd])) $cmd = $_GET[cmd]; else die(You should
here is the code <?php session_start(); if(!isset($_SESSION['user_name'])) { header('Location: login.php'); } $conn = mysql_connect(localhost,
I have the following pages: page1.php <?php if (isset($_GET['link'])) { session_start(); $_session['myvariable'] = 'Hello
when I run this code for the first time <?php session_start(); echo SID; ?>
I have the following login script, where i do use sessions. <?php session_start(); if(isset($_SESSION['logged_in'])){
<?php session_start(); include(connect.php); $timeout = 60 * 30; $fingerprint = md5($_SERVER['REMOTE_ADDR'] . $_SERVER['HTTP_USER_AGENT']); if(isset($_POST['userName']))
<?php session_start(); if(isset($_POST['username']) && ($_POST['password'])) { $con=mysql_connect(localhost,root,); if(!$con) { die('Could Not Connect:'.mysql_error()); } mysql_select_db(tcs,$con);
Page1.php: <?php session_start(); if ($_POST['password'] == testpass) $_SESSION['authenticated'] = true; ?> Page2.php <?php session_start();
I have a very simple test page for PHP session. <?php session_start(); if (isset($_SESSIONS['views']))

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.