lilzz
Posts: 411
Joined: Sat Nov 30, 2013 5:27 pm

PHP header()

Wed Sep 03, 2014 7:56 am

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?

User avatar
joan
Posts: 14936
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: PHP header()

Wed Sep 03, 2014 7:58 am

Isn't dot between strings the string concatenation operator in PHP?

Massi
Posts: 1691
Joined: Fri May 02, 2014 1:52 pm
Location: Italy

Re: PHP header()

Wed Sep 03, 2014 10:14 am

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"

lilzz
Posts: 411
Joined: Sat Nov 30, 2013 5:27 pm

Re: PHP header()

Wed Sep 03, 2014 3:12 pm

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?

Massi
Posts: 1691
Joined: Fri May 02, 2014 1:52 pm
Location: Italy

Re: PHP header()

Wed Sep 03, 2014 3:46 pm

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 :)

Return to “General programming discussion”