Jump to content
Larry Ullman's Book Forums

Script 11.2 - Login_Functions.Inc.Php


Recommended Posts

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

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.

  • Upvote 1
Link to comment
Share on other sites

 Share

×
×
  • Create New...