Using header in php

is it ok to use header(“location: {html document here}”); it seems to cause issues in general anyone know why?

Try this code:

header("Location: index.php");
// Remember to replace the "index.php" with your custom location

it seems to cause issues in general

What is “general”? Could you be more specific? Thanks!

1 Like

like if i just use it for normal general purposes like redirecting to other pages

Well, I use it in my code (a lot), so I think it’s OK to use…

no none of these are the errors it seems to be freezing the web page and then redirecting to suspended domain i checked infintyfree it still says active

Make sure you’re redirecting to the correct link

it works sometimes but after two or three times it does not i replaced the header with echo “some javascript to redirect”; and it works fine now idk what happened

What exactly were you putting as the header? I know from experience that it works perfectly fine.

Well I was making a login page using files and the code looked something like this
if (usernameexists() === true)
header(“Location: usernameused.html”);

sorry for no code boxes I currently don’t know how

Using JavaScript instead of PHP header isn’t really the wisest idea…

Make sure you have no whitespace, or code before or after the header statement

The forum supports Markdown, BBCode, pure HTML and possibly more. So any method you can think of to format code probably works.

1 Like

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.