Skip to content
Advertisement

Why does my PHP file stop executing when I use session_start()?

I am creating a login page for a website using PHP. I added “session_start();” as seen below to start the session. Then I put the rest of the websites code below it (other php, html, etc). Whenever I use session_start, the program stops executing and shows a blank page. Also, the page displays error 500 on some browsers. I’m not sure if this is a permission problem.

How do I properly use session_start()? My code is below. When I run it it shows a blank screen. When I comment out session_start(); it prints “Working…”.

<?php 
session_start();
echo "Working...";
?>

Advertisement

Answer

Ok I figured it out. Thanks for the help everyone. After looking at the logs the error read Fatal error: Uncaught Error: Call to undefined function session_start() in /usr/local/www/apache24/data/test.php:2 Stack trace: #0 {main} thrown in /usr/local/www/apache24/data/test.php on line 2

All I had to do was install some packages (mod_php72 and php72-session) and restart the server.

These posts really helped: Call to undefined function session_start() https://forums.freebsd.org/threads/call-to-undefined-function-session_cache_limiter.69010/

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement