0

I have a very simple code that works fine under a Strato server but when running in my own Apache2 server the code doesn't works.

I have one file called "checklogin.php" with this code

<?php
session_start();
$_SESSION['username'] = 'alex';
echo "Bienvenido! " . $_SESSION['username'];
echo "<br><br><a href=panel-control.php>Panel de Control</a>";
?>

And second file called "panel-control.php" with this code:

<?php
session_start();

$username = $_SESSION['username'];
echo "Hola $username";
?>

The problem is that I can't get the _SESSION data because the server starts a new session every time I call the session_start()

When I see at the server side the sessions folder is ok and I can see the files of every session "sess_...." with the data "username|s:4:"alex";" this means the folder is writable and the php is sending the data ok, but, when the second page is loaded a new session is created and can see an error in the Apache2 log file telling the undefined index because the session is new and _SESSION not contains the variable "username", obvious bacause is a new session without data.

Well, I spent some hours with this and can't see the problem. I tried runing Apache2 with php5.6 and 7.0 with the same results and the php.ini file is well configured (same configuration as the file in the Strato server where the code runs ok).

Any ideas?

Thanks for reading.

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • 3
    The session cookie is probably not set correctly or not sent by the browser for some other reason. Check the HTTP-Headers send by your browser in the network tab. – tkausl Aug 23 '17 at 19:58
  • This has been asked and answered many times. Please search and find the answer. – random_user_name Aug 23 '17 at 20:01
  • https://stackoverflow.com/questions/15911817/session-start-creates-new-session-every-refresh?rq=1 – random_user_name Aug 23 '17 at 20:01
  • https://stackoverflow.com/questions/26218081/session-start-creates-new-session-every-reload?rq=1 – random_user_name Aug 23 '17 at 20:01
  • https://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php – random_user_name Aug 23 '17 at 20:01
  • Hi tkausl thanks for your comment, the problem is solved. checked the headers and you are right, I was sending a cookie called XDEBUG instead of the cookie needed to start session, but, for any reason this only happened in my server and not in the strato server. I cleaned the cache and cookies and averything works fine now. –  Aug 24 '17 at 10:21

0 Answers0