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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:10:06+00:00 2026-05-25T10:10:06+00:00

I have a strange problem in my code that I really can’t explain and

  • 0

I have a strange problem in my code that I really can’t explain and it just doesn’t make any logical sense to me. I am setting a session variable called $_SESSION['user_id'] when a person successfully logs into my website and they are redirected to the index.php page. This works fine and the session works fine, but then once I refresh the page, the value in the session disappears, but I do not see why.

$long_user_id = $_SESSION['user_id'];

$user_id = substr($long_user_id, 0, -3);

Can anyone see what the problem is here? I thought that the Session variable called user_id would remain the same, but for some reason it’s empty after a second page-load.

Thanks in advance

Edit: I didn’t post all my code and I made a mistake by not mentioning that I am using session_start(); on every page. I would also like to confirm that the code works if I comment out the substr part of the code from the page.

  • 1 1 Answer
  • 2 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-25T10:10:07+00:00Added an answer on May 25, 2026 at 10:10 am

    The “solution” to this problem makes very little sense. For some strange reason the $_SESSION[‘user_id’]; was actually being stored as $user_id in the php script. I cannot explain this and I don’t know why it was doing it, but what it meant was that when I adjusted the $user_id variable, it was causing problems with the session and thus making it “disappear” as I stated earlier on.

    This issue has been resolved by simply changing the variable names to make sure they do not conflict with the session name.

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

Sidebar

Related Questions

I'm having a really strange problem. Here is the code I have that should
I've run into a really strange bug, that I'm hoping someone can explain. I
Ive got a really strange problem with some javascript code that ive written. I
I have a strange problem with mod_rewrite, the rules that are relevant here are:
I have a strange problem that is only happening in a single location. I
I have a strange problem that I could not solve. When I try to
I've come across a really strange problem. I have written a simple Deck class
We have some really old code that calls WebServices using behaviours (webservice.htc), and we
I have a strange problem and really dont know where to start debug. I
I have a strange problem which probably has a very simple solution, I just

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.