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

The Archive Base Latest Questions

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

Obviously one should sanitise sessions when the’re being created, but what are peoples thoughts

  • 0

Obviously one should sanitise sessions when the’re being created, but what are peoples thoughts on sanitising a session before using 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-05-15T11:39:24+00:00Added an answer on May 15, 2026 at 11:39 am

    Some basics about standard sessions (with cookies):
    When a user visits your site for the first time, session_start() will create
    a file using a hash as filename (more or less random (*) (see session_save_path()).
    PHP will store all $_SESSION variables within that file. At the same time the user gets a cookie with that hash (session id).
    Is the user requesting another site (sends the cookie with the session id) PHP will check if the file with that hash exists. If it does, everything within will be read into $_SESSION.

    Everything the user has contact with, is the hash. As long as you sanitize everything you’re writing into $_SESSION (coming from the user), there is no need to check again when reading those values.


    All you need to do is, to make it (from your side) as hard as possible to “steal” the session id (..or use it).

    A good start is to allow cookies only. Session ids in the URL end up being copy/pasted or cached by search engines

    ini_set('session.use_cookies'     ,1);
    ini_set('session.use_only_cookies',1);
    ini_set('session.use_trans_sid'   ,0);
    

    before session_start() should do it, see Session Configuration for more info.

    deleting the current session, creating a new one (new hash) forces a possible attacker to act quickly

    session_regenerate_id(true);
    

    after session_start() does exactly that. (session_regenerate_id())

    Saving the users IP (partly) and destroying the session if it changes is another option

    // first call:    
    $_SESSION['userip'] = $_SERVER['REMOTE_ADDR'];
    
    //following calls:
    if ($_SESSION['userip'] != $_SERVER['REMOTE_ADDR']) { session_destroy(); } 
    

    You could run into trouble with that one, since there might be some users changing IP quite frequently.. other $_SERVER vars could be used as well ($_SERVER[‘HTTP_USER_AGENT’] for example). (Predefined Variables)

    There are a few other things you can do (crypt the SID so people wont know the filename, HTTPS is always nice, ..) but that should get you started. Google will certainly find some nice tutorials on “session security“.

    Edit: fixed Links.

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

Sidebar

Related Questions

I know this is not a really programmic question, but which one should I
This one should be quite simple. But I've been stuck with it for a
This one is quite obviously a function pointer : typedef int (* foobar) (int
Obviously MVC promotes separation of concerns. One thing we are struggling with is proper
Obviously, the typical WebForms approach won't work. How does one track a user in
I have several controls in one of my applications, which all obviously extend the
I might be missing something obvious here, but I'm implementing NSCopying on one of
I have a inefficiently constructed form that is obviously sending one type of data
The Unix philosophy teaches that we should develop small programs that do one thing
I understand the syntax and general semantics of pointers versus references, but how should

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.