Skip to content
Advertisement

why does an empty header location path/filename in php worky differently in mobile browsers?

i don’t need an explanation of how header location works, what i noticed is when i use this with an empty path and no filename given if the calling file is index.php and i do

header("Location: ");

the redirection works on a pc and redirect me to the index.php | / directory root

when i do the same on a smartphone or tablet(test with android) browser it redirect to index.php | / directory root sometimes it works, but sometimes i got an empty page and i have to refresh once and than i see the content, there is nothing special in the code only set and unset of cookies with php

so i have to do

header("Location: index.php");

Is this a bug or shouldn’t you use an empty path, this example?

Advertisement

Answer

You shouldn’t use an empty path. Different browser implementations will handle that differently. In fact, the location header value should contain an absolute URL including the domain, but most, if not all, browsers will handle relative location header values.

Don’t rely on it working!

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement