Home > front end >  PHP Script works on one site but not other, same server
PHP Script works on one site but not other, same server

Time:09-17

I currently have a cPanel server, I have a domain site1.com we created the new website on the server using cPanel. The problem is that our script that was used to create the the site runs on the test site "site2.com" on the same cPanel server but does not run on the new site site1.com

If have narrowed the issue down to this line 18 in EditPage.php:

header("Location: Login.php?Page=$PageToEdit"); 

The only difference I can se on the server is that "site1.com" is running "PHP7.4 PHP-FPM" in the cPanel and "site2.com" "PHP7.4" there is no way to turn "PHP-FPM" on or off in the cPanel so what is deciding to turn it on for some sites and not for the others? And why is it even needed make no sense. I'm a newbie so please be specific thanks!

SERVER:
cPanel Version  98.0 (build 6) - 
Apache Version  2.4.48 - 
PHP Version 7.4.22 - 
MySQL Version   10.3.31-MariaDB - Architecture  x86_64 - 
Operating System    linux - 
Kernel Version  3.10.0-1062.1.1.el7.x86_64

PHP script that fails:

// (A) START SESSION
session_start();
 
// (B) LOGOUT REQUEST
if (isset($_POST['logout'])) { unset($_SESSION['user']); }
 
// (C) REDIRECT TO LOGIN PAGE IF NOT LOGGED IN
if (!isset($_SESSION['user'])) {
  header("Location: Login.php?Page=$PageToEdit");
  die();
}

CodePudding user response:

This is because of session is not destroying. We can unset session with these functions.

session_destroy();
$_SESSION = [];

Now it will work. Your code should like this

// (A) START SESSION
session_start();

 // (B) LOGOUT REQUEST
if (isset($_POST['logout'])) { unset($_SESSION['user']); 
 session_destroy(); $_SESSION = []; }

 // (C) REDIRECT TO LOGIN PAGE IF NOT LOGGED IN
 if (!isset($_SESSION['user'])) {
     header("Location: Login.php?Page=".$PageToEdit);
     die();
 }
  • Related