Requirements or conditions to use PHP sessions? - php

I am a bit puzzled on using PHP's session. Are there any specific requirements or conditions to use sessions? From all other forums, I can only see that session_start() should be the first line of the php code and nothing else beyond that.
In my test server (with PHP 7.3) it took me a while to get it to work, the only thing I found out is that when I load my site using http, the session doesn't save across load. And when I load it using https, it works fine.
While at this topic, I am also confuse why this tutorial site: https://www.w3schools.com/php/php_sessions.asp doesn't work despite it loaded using https.

Related

Debug PHP Using WAMP and an IDE

I recently started web development. The course I took was to install WAMP and start developing right away. I used an atom text editor, this -combined with wamp- proved to be a very fast way to write client-side code(HTML, CSS, Javascript).
But when I started to write serverside PHP things got a little messy. I should probably explain my site's structure here.
I keep separate PHP, CSS, javascript files for every page on the client side, for the server side a have 2 different types of PHP files:
Files that only perform a specific operation on the database(For example returning "5 more answers"). These are always called by AJAX requests.
Files that load the page for the first time. These are only used when the user opens the page for the first time, they do necessary database queries and return the page. Later requests always go to the 1st type of PHP files.
Now regarding my problem. I debugged until now by printing variables to the screen with var_dump() or echoing. But this started to become too slow as the data I work with grew. I wonder if there is a way of debugging which will let me but a breakpoint in one of my PHP files. Then, when I open it on the browser, on the localhost I created using WAMP, will let me go through the PHP file step by step.
I have been dealing with this issue for 3 days, I tried to make it work with Eclipse IDE but couldn't find a way. Also, there seems to be no tutorials or Q&A on the internet regarding the issue.
Breakpoint debugging opens a whole new world, and is the natural step after var_dump() debugging. Not only does it speed up development, but it provides much more information about your code, as you can step through each line and see what values have been set at each step, and how they evolve as your program executes its code. This means you can track the entirety of the values at different stages with one run - imagine tracking all variables at each point using var_dump()!
Although choosing an IDE is a personal decision based on personal taste, i strongly recommend you try out PhpStorm. If you can get a student licence go for it.
PhpStorm has extensive documentation & tutorials on all features in the IDE, debugging is no exception:
https://www.jetbrains.com/help/phpstorm/configuring-xdebug.html
https://www.youtube.com/watch?v=GokeXqI93x8
I don't know of a specific solution to your issue. I'm not exactly sure what you're doing but as a quick tip, I find add the following snippet to the top of the file useful as it will highly error more easily rather than browser just say nope.
error_reporting(E_ALL);
ini_set('display_errors', 'On');
Hope this help you a bit.
I tried out what's recommended in comments and answers. I first tried Netbeans. To be fair it disappointed me. Download kept getting stuck at 100%, even for different versions. When I stopped downloading and went ahead to create a php project, there was missing parts I guess. I couldn't even manage to create a php project. But that might just be me not being able to do it.
Then I followed #leuquim's answer and #Alex Howansky's comment and downloaded PHPStorm. And I got it to work in no more than 20 minutes. I downloaded it with a student's licence. For people who want to use PHPStorm with WAMP here's a Youtube tutorial:
https://www.youtube.com/watch?v=CxX4vnZFbZU
One thing to note in the video is that, maker of the video chooses PHP Web Application in the Run Configurations. That has been changed to PHP Web Page.

PHP sesision differences between 5.3 and 5.6

Recently we upgraded a server from PHP 5.3 to 5.6. We tested all code internally before doing so, and all was well.
After the upgrade, everything works fine except for an extremely small portion of the clientele. We have an integration with a LOS called Calyx Pointe. A small portion of Pointe users are losing their sessions after loading a few pages. We cannot determine why.
They login and we see their session data. They choose an option and it redirects them to page #2, which still knows who they are. They choose an option on that page, which calls an AJAX GET call, and suddenly they're forgotten. I have verified that the AJAX called page includes the sessions code, so it should be fine. It's also called via the same domain, so there's no issue w/ multiple domains losing the session. Also, no _ in the domain name.
When we tested w/ the same version of Pointe, it works perfect for us. And we have done this on several different versions, using different underlying versions of Internet Explorer. (Also, a small portion of these users CAN place orders fine.)
So, 2 questions:
Does anyone know of any issue w/ the change in PHP versions that would cause this? We're not using mysql_* functions. The sessions are stored in a DB using a modified version of Zebra_Session. This started immediately after the upgrade (the next day), so I don't feel it's a coincidence. But, b/c we cannot reproduce the issue, it has made it extremely difficult to diagnose, as we cannot test from the client's machines.
Alternatively, would passing PHPSESSID in the URL to each page called w/in allow each page to "remember" the session?
Any ideas would be helpful and appreciated.

Session doesn't start (Symfony 2.7.1, Apache 2.2)

So as title suggests, session doesn't start after submitting a form. $_SESSION is null after submitting. There are no errors, and redirect is to the page after successful login. I am pretty sure that is no related to any configuration problem in symfony, simply because I have exact copy on my local machine, and everything works fine.
That's why I think it's related with Apache 2.2. auto-session is off in php.ini. Any suggestions?
You should use the Session Management of Symfony (http://symfony.com/doc/2.3/components/http_foundation/sessions.html)
As stated elsewhere, Symfony Sessions are designed to replace the use of PHP's native session_*() functions and use of the $_SESSION superglobal. Additionally, it is mandatory for Symfony to start the session.
(http://symfony.com/doc/current/components/http_foundation/session_php_bridge.html)
Actually all of that was because of Varnish. I didn't have Varnish for that project, at least I thought so, because I had configuration done wrong, and Varnish was working for both projects (that which I wanted, and which I don't). So I think the problems was with cached form (generally page). I think all of that, because recently I switched off Varnish, and everything working like it should.

Code Coverage under PHPUnit for admin areas

I'm trying to get PHPUnit and CodeCoverage over a few hundred PHP code repositories. A consistent problem I receive is that CodeCoverage doesn't work over any of my Admin pages that have session_start or any of my bounce-redirect pages that use header('Location...'); Code that otherwise works fine throws up "Warning: Cannot modify header information - headers already sent by (output started at ...)"
I've tried any number of Google searches to find a way around this and my Google-fu is currently weak. Thanks in advance.
EDIT 20120515:
I've ensured my code has all exit() calls replaced with returns. I do have XDebug installed and it is functioning on very simple, non-authenticated applications.
EDIT 20120531:
Reading further into the code, I found a file_get_contents in the SeleniumTestCase.php was failing under my xampp due to the file_get_contents('https://...'). Solved it by creating a http:// virtual host on a different port and pointing my coverageScriptUrl at that instead. All the warnings above were apparently red herrings.

session_start() and curl php

I do not know, but whenever the PHPSESSID cookie is created, all my scripts that use curl are getting slow, someone could tell me why?
even without the session_start(). doesn't matter.
What version of php are you using? because i know there have been very big performance update from php4 to php5.
Sessions write the information to a file, so there might be write issues.
if you are using your own sessions handler that can cause a slow down too. try using only php basic session methods rather than writing your own.
Maybe you have activated the php.ini setting session.auto_start.
http://www.php.net/manual/en/session.configuration.php#ini.session.auto-start
As mentioned before: How is cURL and PHP related in your question? Please provide some code.
Without seeing more info / code all I can suggest is that you call session_write_close() before making any cURL calls and see if that improves anything.
However, the most probable scenario is that your cURL speed is not related to the PHPSESSID cookie.

Categories