tomliuwhite Posted December 16, 2011 Share Posted December 16, 2011 For below function: function absolute_url ($page = 'index.php') { // Start defining the URL... // URL is http:// plus the host name plus the current directory: $url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']); // Remove any trailing slashes: $url = rtrim($url, '/\\'); // Add the page: $url .= '/' . $page; // Return the URL: return $url; Why not do this way? function absolute_url ($page = 'index.php') { // Start defining the URL... // URL is http:// plus the host name plus the current directory: $url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']; // Return the URL: return $url; Link to comment Share on other sites More sharing options...
rob Posted December 16, 2011 Share Posted December 16, 2011 Because that removes the flexibility of being able to pass in a filename as a function parameter and will only ever point to the script executing it. The login.php script redirects to loggedin.php, on successful validation of submitted user details, by setting: $url = absolute_url('loggedin.php'); header("location: $url"); The HTTP spec requires location headers to be absolute urls. 1 Link to comment Share on other sites More sharing options...
Recommended Posts