0

I am trying to start a session using session_start() function. I am using xampp's server. But whenever I include this code, the page doesn't load. If I remove this code, the page loads perfectly. Is it a problem with xampp? This is the code placed at the very beginning of the file without any whitespaces before php tag.

<?php
// Start the session
session_start();
?>

Can somebody help me with this?

This is what Apache log says :

[Fri Mar 04 19:13:09.822907 2016] [mpm_winnt:notice] [pid 5444:tid 508] AH00428: Parent: child process 7200 exited with status 3221225477 -- Restarting.
[Fri Mar 04 19:13:10.738482 2016] [ssl:warn] [pid 5444:tid 508] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Fri Mar 04 19:13:10.800485 2016] [mpm_winnt:notice] [pid 5444:tid 508] AH00455: Apache/2.4.18 (Win32) OpenSSL/1.0.2e PHP/7.0.0 configured -- resuming normal operations
[Fri Mar 04 19:13:10.800485 2016] [mpm_winnt:notice] [pid 5444:tid 508] AH00456: Apache Lounge VC14 Server built: Dec  9 2015 10:17:39
[Fri Mar 04 19:13:10.800485 2016] [core:notice] [pid 5444:tid 508] AH00094: Command line: 'c:\\xampp\\apache\\bin\\httpd.exe -d C:/xampp/apache'
[Fri Mar 04 19:13:10.805024 2016] [mpm_winnt:notice] [pid 5444:tid 508] AH00418: Parent: Created child process 5404
[Fri Mar 04 19:13:12.067176 2016] [ssl:warn] [pid 5404:tid 532] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Fri Mar 04 19:13:12.337492 2016] [ssl:warn] [pid 5404:tid 532] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Fri Mar 04 19:13:12.400429 2016] [mpm_winnt:notice] [pid 5404:tid 532] AH00354: Child: Starting 150 worker threads.
Sachin Parashar
  • 1,067
  • 2
  • 18
  • 28
  • 3
    whats the error? Use `error_reporting(E_ALL)` and post the error – Ashish Choudhary Mar 03 '16 at 12:39
  • Possible duplicate of [Setting $\_SESSION doesn't work on localhost using XAMPP](http://stackoverflow.com/questions/19644624/setting-session-doesnt-work-on-localhost-using-xampp) – Phiter Mar 03 '16 at 12:43
  • add session.autostart = On in your php.ini file – Vigikaran Mar 03 '16 at 12:50
  • also check session.use_cookies=1 – Vigikaran Mar 03 '16 at 12:51
  • 1
    A "500 Internal Server Error" status code (or a blank page) means that your script is throwing an error but you haven't configured PHP to display error messages. That's something you need to fix before you go further; it's impossible to code properly without the aid of error messages. Here's a [brief explanation](http://stackoverflow.com/a/5680885/13508). The error reporting thumb rule is: show in development, log in production. – Álvaro González Mar 03 '16 at 13:07
  • I would say he has no write permission in C:\xampp\tmp, I am using xampp and saving session works without any problem. –  Mar 03 '16 at 14:17
  • It says "This webpage is not available" and "ERR_CONNECTION_RESET" – Sachin Parashar Mar 04 '16 at 13:08

6 Answers6

1

The most probable cause of your problem is you save session to default folder with xampp installed in default folder and session.save_path in your config file probably points to session.save_path="C:\xampp\tmp"

It's not a good idea to install xampp on C:\ reinstall it or edit config changing the session.save_path to a different location.

Session_start failing because lack of permissions

EDIT.

Your session is working. Create new .php file to make it sure. Put inside only the following code and nothing more than that:

<?php
session_start();
$_SESSION["qwerty"] = "123456" ;
echo $_SESSION["qwerty"];
?>

Does the echo return 123456?

Community
  • 1
  • 1
  • I replaced default path to "C:\xampp\tmp" in the php.ini file but it still didn't help me. – Sachin Parashar Mar 04 '16 at 13:09
  • The best would be to reinstall xampp and install it outside of C:\ the best would be different partition like D:\. That would solve it if you have problems with permissions but at the moment you don't even know what your problem is. What does the apache error log say? –  Mar 04 '16 at 13:33
  • I have added the apache error log in the question please check it. – Sachin Parashar Mar 04 '16 at 13:41
  • Do you have any files in tmp folder at all? How about php error log? –  Mar 04 '16 at 13:58
  • Yes, I have some files in there. – Sachin Parashar Mar 04 '16 at 14:00
  • Any starting with "sess_"? –  Mar 04 '16 at 14:04
  • Yes yes there are two files starting with sess_ – Sachin Parashar Mar 04 '16 at 14:08
  • One with size of around 35KB (theme manager) and the other one is empty (session you created). Your session works, there is problem somewhere else. Create a new .php file with nothing else in it than `session_start();` and `echo session_id();` and check if it echos the id or page is blank. –  Mar 04 '16 at 14:14
  • Changing session.save_path to C:\xampp\tmp worked for me --- Did you restart Apache??? – Chad Reitsma Jun 10 '23 at 01:58
0

It is a problem of xampp.

Try to change version of xampp and it will work.

Actually there is a bug in xampp try to install older version of xampp or use wampp.

or try this

Check that in php.ini file (xampp/php/php.ini)

session.save_path 

exists and is writeable by the user under which PHP is running.

Jatin Raikwar
  • 406
  • 5
  • 17
  • It's not a problem with xampp, it's problem with its configuration. I am almost sure he doesn't have permission to save the session in default location but that's just matter of getting familiar with config files and manual. –  Mar 03 '16 at 14:15
0

Try remove the commented section and don't put any space :

<?php
  session_start();
?>
Newton Sheesha
  • 1,245
  • 1
  • 8
  • 13
0

I had same problem. In php.imi option "session.use_only_cookies" was set to 0, when I changed it to 1 everything worked fine

0

I had the same problem and I solved it in the following way. In Apache Config in the php.ini file I changed session.use_only_cookies from 0 to 1.

I would like to mention that previously because of a problem with phpmyadmin I had to replace $cfg['Servers'][$i]['auth_type'] = 'config' with $cfg['Servers'][$i]['auth_type'] = 'cookie' in config.inc.php

0

First: Make sure you have enable the session modules depending on which you need in apache.

LoadModule session_module modules/mod_session.so
LoadModule session_cookie_module modules/mod_session_cookie.so
LoadModule session_crypto_module modules/mod_session_crypto.so
LoadModule session_dbd_module modules/mod_session_dbd.so

In php.ini your values should look somewhat similar to this and also make sure this directory exists -> (c:\xampp\tmp):

session.save_handler=files
session.save_path="c:\xampp\tmp"
session.use_strict_mode=0 (This is not encouraged, but will help with testing)
session.use_cookies=1
session.use_only_cookies=1
session.name=PHPSESSID
session.auto_start=0
session.cookie_lifetime=0
session.cookie_path=/ (<- important setting)
session.serialize_handler=php
session.gc_probability=1
session.gc_divisor=1000
session.gc_maxlifetime=1440
session.cache_limiter=nocache
session.cache_expire=180
session.use_trans_sid=0
session.sid_length=26
session.trans_sid_tags="a=href,area=href,frame=src,form="
session.sid_bits_per_character=5

And for this error ->

www.example.com:443:0 server certificate does NOT include an ID which matches the server name

This usually means that a vhost was configured incorrectly either in httpd-ssl.conf or httpd-vhosts.conf would you mind posting those two file contents to have a look?

demo7up
  • 530
  • 5
  • 27