PHP session seemingly not working
You know that you've got to write session_start()
before you use the $_SESSION
variable in any request, right? It looks like you haven't put it in index.php anywhere.
PHP $_SESSION not working
You need session_start()
at first.
PHP Sessions Troubleshooting
Okay, I've figured it out! Thanks everyone for your suggestions, turns out I need to learn to read error logs ...
I use vestacp and apparently it defaults the PHP sessions to /home/admin/tmp
, and I'm not sure how but you're not able to change that (which I did). There was another problem though, the ownership and permissions weren't correct for that folder. Turns out all I needed was a chmod -R 700 /home/admin/tmp
and chown -R root /home/admin/tmp
- which I already tried on the other folder but it didn't allow that.
Btw, here's the error line that triggered the 'oh what the hell I can't change the session directory':
Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/home/admin/tmp) in Unknown on line 0
$_SESSION not seeming to work
You HAVE to start the session every time you intend to use it. (preferably at the beginning of the page)
<?php session_start();?>
PHP $_SESSION variable not working first time
I was using AWS Elastic Beanstalk to run this web app. I didn't think this matter but apparently it did. It turns out that sessions don't work the same as they do on localhost since you are dividing your servers. I needed to enable sticky session within the load balancer.
Sessions not showing but are definitely there as shown from next page
Okay... Sorted it out... Please read...
Even though this is a new page, the code is sort of coming off layers of other files...
I didn't think this should have been an issue...
(I had thought that each page needed it's own session_start()
but for some reason they don't and all of them apparently are based off one page... bit complicated to explain - suffice it to say that I am trying to sort out someone else's code :-P)
Anyway, I went through all the files that are connected to this one, deleted all the session_start()
s from them besides for the primary one. Now it's working fine.
The data now displays perfectly!
Question:
Does anyone have an explanation for this?
Why does having too many session_starts()
cause problems?
PHP Session data not being saved
Thanks for all the helpful info. It turns out that my host changed servers and started using a different session save path other than /var/php_sessions which didn't exist anymore. A solution would have been to declare ini_set(' session.save_path','SOME WRITABLE PATH');
in all my script files but that would have been a pain. I talked with the host and they explicitly set the session path to a real path that did exist. Hope this helps anyone having session path troubles.
Related Topics
Multiple Http Get Parameters with the Same Identifier
Need Response Body of Http 500 with File_Get_Contents (Php)
Utf-8 Not Working in HTML Forms
Fatal Error: Call to Undefined Function Openssl_Random_Pseudo_Bytes()
PHP Session-Based Flash Message
Pdo: Call to a Member Function Fetch() on a Non-Object
Trying to Pass Todataurl with Over 524288 Bytes Using Input Type Text
Remove First 4 Characters of a String with PHP
PHP - How to Send an Array to Another Page
What Does Bind_Param Accomplish
How to Fix 'Creating Default Object from Empty Value' Warning in PHP
Mysql_Fetch_Array Returns Duplicate Data
Detect If Cookies Are Enabled in PHP
How to Rename a Tag in Simplexml Through a Dom Object
Simple Xml Add Namespaced Child
Html5 Audio Says "Live Broadcast" in iOS When It's a Static File