PHP Session variables

doctorbill used Ask the Experts™
Session variables:

I have a web page which uses session variables to submit details to my database
The website is running on my localhost (http://loalhost:888/......)
I have forwarded traffic through my router to this site which works
I appreciate this is not in a production environment so it is not an issue at the moment - just a question

If I access the website using the external dns address through the router to the internal address, and if I submit a webpage form which uses session variables to be submitted to the database, these variables are not being entered. All the other form fields are entered as expected
If I use the website on the pc which hosts the website (apache), ie internally, the session variables are entered with no problem

I was just wondering why the session variables are not being entered when the website is accessed externally
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
David FavorFractional CTO
Distinguished Expert 2018

Likely the only way your code will work, is if you're access the machine locally.

Highly unlikely you can get this working as you've described.

If you're going to run this code on a public IP, then go ahead + deploy your code on your public machine now, so you're actually debugging your code in your real runtime environment.

If you can get this working as you describe, likely the entire process will fail again when you move your code to a public machine.

Aside: Also be sure you run HTTP2 + HTTPS on your public server, so you're actually working with most recent HTTP protocols, as this will have a subtle effect on code you write.

Tip: KISS - Keep things super simple.
Scott FellDeveloper & EE Moderator
Fellow 2018
Most Valuable Expert 2013

It may be something as simple as running localhost vs using your computer as a webserver is running under a different user and you just need to set permissions for php.

Check which user is running for each way you are accessing the pages.
Developer & EE Moderator
Fellow 2018
Most Valuable Expert 2013
Check and make sure that has the proper permissions. Also check your php errors/logs.
Dave BaldwinFixer of Problems
Most Valuable Expert 2014

The session_id is based on a cookie.  Cookies are unique to each user which means session variables are not shared between users.


Thanks all

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial