Page 1 of 1

PHP header()

Posted: Wed Sep 03, 2014 7:56 am
by lilzz
1) header("Location: .");
what it means with the . Does it make your page reload and go somewhere else with header("Location: "...) ?

2)header("Location: " . base_path(false) . "offers");
I notice there are 2 dots in the 2nd case. what does that mean?

Re: PHP header()

Posted: Wed Sep 03, 2014 7:58 am
by joan
Isn't dot between strings the string concatenation operator in PHP?

Re: PHP header()

Posted: Wed Sep 03, 2014 10:14 am
by Massi
lilzz wrote:1) header("Location: .");
what it means with the . Does it make your page reload and go somewhere else with header("Location: "...) ?
please note that the dot is INSIDE quotes.
So . is a part of the string passed to header.
2)header("Location: " . base_path(false) . "offers");
I notice there are 2 dots in the 2nd case. what does that mean?
please note that dots are OUTSIDE quotes.
So they are not part of the string passed to header. They are (as joan says) the way you concatenate strings in php.
In this case you are passing header () the string "Location: " concatenated to the output of the function base_path concatenated to the string "offers"

Re: PHP header()

Posted: Wed Sep 03, 2014 3:12 pm
by lilzz
pattagghiu wrote:
please note that the dot is INSIDE quotes.
So . is a part of the string passed to header.


please note that dots are OUTSIDE quotes.
So they are not part of the string passed to header. They are (as joan says) the way you concatenate strings in php.
In this case you are passing header () the string "Location: " concatenated to the output of the function base_path concatenated to the string "offers"
Does the first one indicates going to the root directory?
Also when you send header("location:") the web page would get redirected or reloaded?

Re: PHP header()

Posted: Wed Sep 03, 2014 3:46 pm
by Massi
lilzz wrote:Does the first one indicates going to the root directory?
i think that you can answer these questions just making some tests, just making a guess i can say that the first can redirect the page to the default page in the folder
Or maybe it isn't even working..

Let's say this: if it works, it's not standard compliant.
In fact, "Location" is not something regarding PHP, and since the standars WANTS a ansolute URI (see http://tools.ietf.org/html/rfc2616#section-14.30 ), maybe location: . can work on somw browsers and on some not.
On chrome, it works as i wrote.
Also when you send header("location:") the web page would get redirected or reloaded?
mmm, philosophic question. What's the difference between "redirect to the same page" and "reload"? :) (apart the risk of looping, lol)
btw, afaik Location: is not going anywhere..

Try to execute this

Code: Select all

<?php
header("Location:");
echo "something's wrong";
?>
Yes, something is wrong :)