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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:35:37+00:00 2026-06-16T02:35:37+00:00

I would like to know how I can change a value in a session

  • 0

I would like to know how I can change a value in a session key.

I have two pages:

Page 1 to change the settings:

<?php       
session_start();

if (isset($_POST['one']) ){
    $_SESSION['pref_lang'] = 'one';
}
if (isset($_POST['two']) ){
    $_SESSION['pref_lang'] = 'two';
}
?>

The HTML:

<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">     
    <input type="submit" id='one' name='one' value="one"/>
    <input type="submit" id='two' name='two' value="two"/>
</form>

Page 2 will be just to display the session:

<?php
session_start();
print_r($_SESSION);
?>

and even a third to destroy the session.

The problem is when I call the first page to change the session value it will not change it. If there is someone who could tell what’s wrong with this I really would appreciate.

UPDATE:

okay, it seems like i do something wrong on page 2. when echo out print_r Session on page 1, that page where i have placed the forms- everything works fine. but when calling page 2, which should usually tell me whats in the session, it just will display the content of the session. strange about that is, that i when calling page 3 for destroying the session, on page 1 it will be displayed that the session is empty but on page 2 it wont change anything. even when i will change the values on page 1, it wont change it on page 2, but it will display the change on page1????

  • 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-16T02:35:38+00:00Added an answer on June 16, 2026 at 2:35 am

    Forms will post all fields they contain. So basically your overriding the session. If you were to try something like this:

    <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">     
        <input type="submit" id='one' name='one' value="one"/>
    </form>
    
    <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">     
        <input type="submit" id='two' name='two' value="two"/>
    </form>
    

    You will see how your second form will override the session variable.

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

Sidebar

Related Questions

I would like to know, how can we change the SRC url for IFRAME
I would like to know how can i read a value of input text
I would like to know how can we validate the Credit Card. We have
I just would like to know how can I dynamically change a label's values
I would like to know where to enter custom code to change the value
I would like to know the Set Automatically value programmatically so I can validate
I have a sortable list on my page. I would like to know just
i would like know some reference. I know i can googling it. but prefer
I would like to know how can I create a regexp to match the
I would like to know how can I write a pointer array: short* myArray

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.