Trouble with PHP coding

Joined
Aug 21, 2023
Messages
40
Reaction score
0
Hello,
I've already posted earlier my treat troubleshooting Lesson 29 from the book Learn PHP, MySQL and JavaScript. This time I'm using ServBay and when I open the site I got the error :
Notice: session_start(): Ignoring session_start() because a session is already active (started from /Applications/ServBay/www/lesson29/index.php on line 2) in /Applications/ServBay/www/lesson29/header.php on line 2

Fatal error
: Uncaught PDOException: SQLSTATE[HY000] [2002] No such file or directory in /Applications/ServBay/www/lesson29/functions.php:21 Stack trace: #0 /Applications/ServBay/www/lesson29/header.php(18): require_once() #1 /Applications/ServBay/www/lesson29/index.php(3): require_once('...') #2 {main} thrown in /Applications/ServBay/www/lesson29/functions.php on line 21

If anybody knows how to fix this it would be helpful?
I used AMPPS and XAMPP but they refuse to show me even the index of the site folder.

Thanks.
 
Joined
Jul 4, 2023
Messages
510
Reaction score
63
Notice: session_start(): Ignoring session_start() because a session is already active (started from /Applications/ServBay/www/lesson29/index.php on line 2) in /Applications/ServBay/www/lesson29/header.php on line 2
The error message you're seeing indicates that session_start() is being called more than once during the execution of your script, which PHP doesn't allow.

1. Check index.php: Open your index.php file and locate where session_start() is called. Ensure that it is called only once.
PHP:
<?php
session_start(); // Ensure this is only called once
// other code
?>
2. Check header.php: Similarly, open your header.php file and locate session_start(). Make sure it's not called again if it’s already being handled by index.php or another file included before it. Ideally, session_start() should be called at the very beginning of your script, before any HTML or output.

or use conditional checks. If you have multiple files that might include header.php, you can use a conditional check to avoid calling session_start() multiple times:
PHP:
<?php
if (session_status() === PHP_SESSION_NONE) { // if session status is none then start the session
    session_start();
}
// other code
?>
 
Joined
Aug 21, 2023
Messages
40
Reaction score
0
The error message you're seeing indicates that session_start() is being called more than once during the execution of your script, which PHP doesn't allow.

1. Check index.php: Open your index.php file and locate where session_start() is called. Ensure that it is called only once.
PHP:
<?php
session_start(); // Ensure this is only called once
// other code
?>
2. Check header.php: Similarly, open your header.php file and locate session_start(). Make sure it's not called again if it’s already being handled by index.php or another file included before it. Ideally, session_start() should be called at the very beginning of your script, before any HTML or output.

or use conditional checks. If you have multiple files that might include header.php, you can use a conditional check to avoid calling session_start() multiple times:
PHP:
<?php
if (session_status() === PHP_SESSION_NONE) { // if session status is none then start the session
    session_start();
}
// other code
?>
Thanks for advice.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,057
Messages
2,570,443
Members
47,114
Latest member
LewisBobad

Latest Threads

Top