PHP session for user authentication


I'm going to use cookies and sessions to indentify the user. So, sessions will be used only when user chose the 'Don't remeber me' option. I include the identification file in the top of every page of website. User's session looks like $_SESSION['user']

<strong>And than is my question:</strong>

Must I place to the authentication file session_start() instruction? I asked it because new session creates every time I use this instruction.

<strong>Update</strong> <a href="http://pastebin.com/Nh3zj6mR" rel="nofollow">http://pastebin.com/Nh3zj6mR</a> user identification script


Yes, you have to place <strong>session_start()</strong> at top of every <strong>php</strong> page (before any output was generated, no headers must have sent before) to tell php to accept / start session, expect your <strong>php.ini</strong> is setup, that <strong>sessions</strong> start automatic.

<blockquote> <blockquote>

I asked it because new session creates every time I use this instruction.<<

</blockquote> </blockquote>

That is a hint, that your <strong>browser</strong> ignore (disallow) session cookies


Unless you execute session_start(), PHP's session mechanism will <strong>NOT</strong> activate. The $_SESSION will be present, you'll be able to read/modify it, but its values will NOT be persisted - e.g... the contents will be lost when the script exits.

If you are running session_start() in every script that uses session data, but the session data is not showing up, then there's probably a misconfiguration causing the session cookie to be lost, and PHP is creating a new session each time.


  • SQL backup job script windows schedule task
  • python pexpect & pxssh with sudo and EOF
  • search and replace file names - bug fix
  • Is it possible to link to a 360 YouTube video with ReactVR?
  • $_session variable
  • Confused by PHP session problem (Rackspace)
  • Is there a downside to session.auto_start in PHP?
  • Pages with session_start() don't load when server-sent event is running
  • How to prevent a value from being moved?
  • How to stop flickering in datagridview
  • Assembly Language Absolute addresses and segment registers
  • Why calculations of eigenvectors of a 2 by 2 matrix with numpy crashes my Python session?
  • When i use auto bi = 123456789, in C++, is it always assigned as an int?
  • Can you look sample a texture in a vertex shader?
  • What does the lower left pane in OllyDbg displays?
  • How to browse android SDK sources in Android studio 2.0
  • Is it possible to ask GIT, don't show a file?
  • How to generate an asynchronous reset verilog always blocks with chisel
  • array_search() in Session Array
  • Granting permissions to Azure Active Directory Web Application automatically
  • How to create two column output from a single column
  • What Makes These Two Array Adds Different?
  • Bigquery event streaming and table creation
  • Suppressing passwd when calling sqlplus from shell script
  • Cannot upload to OneDrive using the new SDK
  • Authentication in Play! and RestEasy
  • What does 'Language neutral' mean with regard to MAKELANGID?
  • Excel's Macro-Recorder usage
  • How to use carriage return with multiple line?
  • Abort upload large uploads after reading headers
  • Content-Length header not returned from Pylons response
  • Change Inet root folder for iis 7
  • Ajax Loaded meta Tags
  • Xamarin Forms - UWP Fonts
  • Fetching methods from BroadcastReceiver to update UI
  • Apache 2.4 and php-fpm does not trigger apache http basic auth for php pages
  • How to recover from a Spring Social ExpiredAuthorizationException
  • Does CUDA 5 support STL or THRUST inside the device code?
  • Javascript Callbacks with Object constructor
  • Arrow is showed instead of the material design version hamburger icon. Why doesn't syncState in
  • Weird JavaScript statement, what does it mean?
  • Arrays break string types in Julia
  • Can Visual Studio XAML designer handle font family names with spaces as a resource?
  • need help with bizarre java.net.HttpURLConnection behavior
  • How can I remove ASP.NET Designer.cs files?
  • Are Kotlin's Float, Int etc optimised to built-in types in the JVM? [duplicate]