R:1
<?php
$uri = 'http://' . $_SERVER['HTTP_HOST'];
$path = '/dev/source/class.ControlEntry.php';
$string = $uri . $path;
header('Location: '. $string );
Am I actually hitting my server and then redirecting back to the client which then calls the new location. Is this 2 round trips to access my site located at the uri and path above?
Per php.net header() sends a raw http header.
Xampp uses code similar to this to specify the directory the source code is in.
However, I’m thinking about just using an include, as was determined best practice in this related SO post.
Yes, sending a “Location” header causes the browser to make second request to that location.
There are many ways to avoid this including use an include as you mentioned. However the advantage of the redirect is that the browser shows the desired URL in the address bar vs. hiding the fact that they browsed to the “wrong” place by sending them data anyway.
The typical round trip time for a home internet connection is well below 1 second, so if you only do this once, users are unlikely to notice. That said, every millisecond counts when people have short attention spans and access to 20 millions videos of cats just a few clicks away.