PHP Classes

Redirect function improvement

Recommend this page to a friend!

      PHP HTTP protocol client  >  All threads  >  Redirect function improvement  >  (Un) Subscribe thread alerts  
Subject:Redirect function improvement
Summary:The Redirect function doesn't construct the URL properly
Messages:2
Author:Kepler Gelotte
Date:2008-04-09 05:05:12
Update:2008-04-17 05:44:46
 

  1. Redirect function improvement   Reply   Report abuse  
Picture of Kepler Gelotte Kepler Gelotte - 2008-04-09 05:05:12
It seems that the Redirect function does not remove the Query string before appending the relative path to the current path. My issue arose because I had a path in the query string:

$this->request_uri = "http://www.example.com/path/?SITEPATH=/somepath/"

So the code took up to the last '/' from the query string.

A simple fix would be to use this block instead:

if(strncmp($location,"/",1) !== 0)
{
$request_parts = explode('?', $this->request_uri);
$location_arguments=@parse_url($location);
if(!IsSet($location_arguments["scheme"]))
{
$end = strrpos($request_parts[0],"/");
if ($end !== false && $end > 0)
{
$request_parts[0] = substr($request_parts[0],0,$end)."/".$location;
}
else
{
$request_parts[0] = $request_parts[0]."/".$location;
}
$location = implode('?', $request_parts);
}
}



Best Regards,
Kepler Gelotte
neighborwebmaster.com

  2. Re: Redirect function improvement   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2008-04-17 05:44:46 - In reply to message 1 from Kepler Gelotte
Can you provide an example script that accesses a real site so I can analyze to reproduce the problem?