0

I've a strange problem with PHP function header('location:anylink'); and is not a coding issue as the exact same script (is my script) works fine in other installations. Have checked it in at least 10 other websites from my clients, with different server configurations and works fine.

An example: I've in my code a check to see if the article id exists in database. If does not exists, it redirects to homepage. If exists, it shows the article page.

Some tests where the article id does not exists and (correctly) redirects to Blog homepage:

https://www.hostbignet.com/blog.php?do=article&id=400

https://oraclewebhost.org/blog.php?do=article&id=400

and here is the link in my site. As you can see it continue code execution and it shows the page, of course with empty data.

https://www.whmup.com/blog.php?do=article&id=400

Have tried at least a dozen of suggestions that I found here in similar issues but nothing changed. I used ob_start, I wrote Location instead location, I let space before URL, I added exit and exit() below redirection. Nothing solved the issue.

My code is (I tried even with adding the domain name before):

// Redirect Back
header('location:blog.php');

In addition. I even tried with window.location.href and window.location.replace Nothing again.

My server is CentOS 7 with CWP Pro.

Thank you Chris

  • `header('location:'blog.php');` has a basic error with quotes. – Nigel Ren Mar 01 '21 at 08:30
  • My site configuration: Apache: Apache/2.4.39 PHP: 7.4.13 MySQL: 10.2.36-MariaDB Also disabled Mod Security – Christos Teriakis Mar 01 '21 at 08:31
  • @Nigel Ren Do you mean double quotes? This was the original. The single quotes changed afterwards as one more try to find the issue. – Christos Teriakis Mar 01 '21 at 08:34
  • What is the quote in the middle there for? – Nigel Ren Mar 01 '21 at 08:35
  • Ok, got you. You mean the single quote before blog.php. Is not there. It was a mistake whith copy/paste here. I left it by mistake when I removed a variable that I had there $CFG["siteurl"].'/blog.php' – Christos Teriakis Mar 01 '21 at 08:37
  • Once more, to say something very important. Is NOT a coding error. The EXACT SAME code works fine in other websites. I can post a list of around 200 domains using it, and works fine. 99.99% is a server configuration error. – Christos Teriakis Mar 01 '21 at 08:40
  • Just cane in my mind to try external link but again nothing. header('location:https://www.teriakis.com'); – Christos Teriakis Mar 01 '21 at 08:51
  • The format in the answer https://stackoverflow.com/a/768472/1213708 would be something like `Location: http://...` don't know if it makes any difference. – Nigel Ren Mar 01 '21 at 08:53
  • Yes I know and I have wrote the domain with full url before but seems that it removed from the script here. – Christos Teriakis Mar 01 '21 at 08:56
  • Now [code]echo "";[/code] works. Before it was not working as it was adding the full url again before the link. But the problem is that I can't use this as it's a public script, I must find a solution with header('Location:....') – Christos Teriakis Mar 01 '21 at 09:09
  • Finally is a website misconfiguration error. I prepared a one line file with just header('Location: announcements.php'); I tried in my other websites (same server) and works. I tried to a different server and works. Only in my website whmup.com shows error: Warning: Cannot modify header information - headers already sent by (output started at /home/whmup/public_html/red.php:1) in /home/whmup/public_html/red.php on line 2 . Can't understand it. I even checked if there is a space before – Christos Teriakis Mar 01 '21 at 09:42
  • The output MUST be coming from your code, it is not a configuration of the server. – Nigel Ren Mar 01 '21 at 10:26
  • This is the full code of the testing file: `code` – Christos Teriakis Mar 01 '21 at 10:32
  • Try it to https://www.teriakis.com/red.php ...works... https://whmcs.teriakis.com/red.php ... (works with correct redirection). And now check the exact same file at https://www.whmup.com/red.php – Christos Teriakis Mar 01 '21 at 10:34

1 Answers1

0

I was able to fix this issue by saving the file as ANSI. Whatever else encoding that I tried, does works.

  • @Nikel Ren Thank you for your effort to help me. Really appreciated. Finally, I found a php.ini i the site, and when I removed it, everything started working fine. I forgot it there when I was testing some changes to php settings. – Christos Teriakis Mar 02 '21 at 19:05