Connecting Tech Pros Worldwide Forums | Help | Site Map

redirect.php maligns redirection URL every time

comp.lang.php
Guest
 
Posts: n/a
#1: Oct 26 '06
[PHP]
require_once("/users/ppowell/web/php_global_vars.php");

if ($_GET['id']) {

// INITIALIZE VARS
$fileID = @fopen("$userPath/xml/redirect.xml", 'r');
$stuff = @fread($fileID, @filesize("$userPath/xml/redirect.xml"));
@fclose($fileID);

// XML PARSE
$parser = xml_parser_create();
@xml_parse_into_struct($parser, $stuff, $redirectArray, $tags);
@xml_parser_free($parser);


/*------------------------------------------------------------------------------------------
This will assume that the entire 3-dim XML-parsed array will have
as its outer key the
same ID value found in the 'id' attribute in the innermost array.
This means you cannot
ever delete any row from redirect.xml unless you renumber!

-------------------------------------------------------------------------------------------*/

$url = $redirectArray[$id]['attributes']['URL'];
if (trim($redirectArray[$id]['attributes']['QUERY_STRING']) !== '?')
$url .= '?';
$url .= preg_replace('/=/i', '=',
$redirectArray[$id]['attributes']['QUERY_STRING']);
$url = preg_replace('/\/$/', '', $url); // REMOVE TRAILING / TO
ACCOMMODATE QUERY STRING AND/OR ANCHOR

if (preg_match('/^http/i', $url)) {
echo "<script type=\"text/javascript\">\n<!--\n location.href=\"" .
str_replace('"', '&quot;', $url) . "\";\n //-->\n</script>\n" .
"<noscript><meta http-equiv=\"Refresh\" content=\"0:URL=" .
str_replace('"', '&quot;', $url) . "\"></noscript>\n";
}

}

[/PHP]

If the URL happens to be this:

http://the-nordic-one.livejournal.co...memory10242006

Instead it winds up looking like this every single time:

http://the-nordic-one.livejournal.co...emory10242006?

I know for a fact that redirect.xml has the correct information:

<pre>
<?xml version="1.0" encoding="utf-8" ?><redirections><redirection
id="1"
url="http://valsignalandet.com/http://valsignalandet.com/cgi-bin/cgiwrap/ppowell/te
xt.cgi"
query_string="path=studies&amp;name=madonnacrucifi xion.txt"></redirection><redirection
id="2" url="http://the-nordic-one.livejournal.com#alchemymemo
ry10242006" query_string="?"></redirection></redirections>
</pre>

But the URL is maligned every single time upon redirection. Is there a
way to prevent this from happening?

Thanx
Phil


Shaun
Guest
 
Posts: n/a
#2: Oct 28 '06

re: redirect.php maligns redirection URL every time


On 26 Oct 2006 10:33:23 -0700, "comp.lang.php"
<phillip.s.powell@gmail.comwrote:
Quote:
$url = $redirectArray[$id]['attributes']['URL'];
if (trim($redirectArray[$id]['attributes']['QUERY_STRING']) !== '?')
>$url .= '?';
$url .= preg_replace('/=/i', '=',
>$redirectArray[$id]['attributes']['QUERY_STRING']);
$url = preg_replace('/\/$/', '', $url); // REMOVE TRAILING / TO
>ACCOMMODATE QUERY STRING AND/OR ANCHOR
>
>If the URL happens to be this:
>
>http://the-nordic-one.livejournal.co...memory10242006
>
>Instead it winds up looking like this every single time:
>
>http://the-nordic-one.livejournal.co...emory10242006?
It appears that the code is missing a set of curly braces; this is
causing the first call to preg_match() to fire unconditionally, which
means that the query string is always going to be appended to the URL
(even if it's only '?').

Try this:

$url = $redirectArray[$id]['attributes']['URL'];
if (trim($redirectArray[$id]['attributes']['QUERY_STRING']) !== '?') {
$url .= '?';
$url .= preg_replace('/=/i', '=',
$redirectArray[$id]['attributes']['QUERY_STRING']);
}
$url = preg_replace('/\/$/', '', $url); // REMOVE TRAILING /

hth

-
Remove mypants to email.
<http://www.shaunc.com/>
Closed Thread