0

This error occured when i am trying to access my admin panel of website on localhost server here is the code of my admin panel index.php

 <?php 
error_reporting(E_ALL);
ini_set('display_errors', 1);


$http_header = 'http://';
if (!empty($_SERVER['HTTPS'])) {
    $http_header = 'https://';
}
$this_url   = $http_header . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];

$this_url = str_replace('admin-panel', 'admin-cp', $this_url);
header("Location: $this_url");
exit();
?>
You can access the admin panel, from <a href="<?php echo $this_url ?>"><?php echo $this_url ?></a>
RiggsFolly
  • 83,545
  • 20
  • 96
  • 136
  • Don't post [images of code](https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-errors-when-asking-a-question)! Did you take a look at the logs to figure out what went wrong? – brombeer May 21 '21 at 11:53
  • Please always post code, not an image of code. From your screenshot I cannot tell if there is a space on line 12 after the first `$` – Chris Haas May 21 '21 at 11:53
  • Yes i have check the logs but there is no error – Awais Choudry May 21 '21 at 11:56
  • there is now space after $ – Awais Choudry May 21 '21 at 11:57
  • To get errors out of PHP even in a LIVE environment add these 4 lines to the top of any `MYSQLI_` based script you want to debug `ini_set('display_errors', 1); ini_set('log_errors',1); error_reporting(E_ALL); mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);`. This will force any `MYSQLI_` errors to generate an Exception that you can see on the browser as well as normal PHP errors. – RiggsFolly May 21 '21 at 12:03
  • still not showing me any error – Awais Choudry May 21 '21 at 12:38
  • Does this answer your question? [How do I get PHP errors to display?](https://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display) – Progman May 24 '21 at 09:02

1 Answers1

-1

Try testing for admin-panel in the URL before redirecting, like this:

if (strpos($this_url, 'admin-panel') !== false)
{
    $this_url = str_replace('admin-panel', 'admin-cp', $this_url);
    header("Location: $this_url");
    exit();
}

If str_replace('admin-panel', 'admin-cp', $this_url) fails, $this_url remains unchanged. If header redirects to the same page you will get an error like "unable to handle request 500 clear your cookies", or something similar.

robinCTS
  • 5,458
  • 14
  • 27
  • 37
user27976
  • 129
  • 6