redirect.php maligns redirection URL every time

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • comp.lang.php

    redirect.php maligns redirection URL every time

    [PHP]
    require_once("/users/ppowell/web/php_global_vars .php");

    if ($_GET['id']) {

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

    // XML PARSE
    $parser = xml_parser_crea te();
    @xml_parse_into _struct($parser , $stuff, $redirectArray, $tags);
    @xml_parser_fre e($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($redirect Array[$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><met a 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:



    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="p ath=studies&amp ;name=madonnacr ucifixion.txt"> </redirection><re direction
    id="2" url="http://the-nordic-one.livejournal .com#alchemymem o
    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

    #2
    Re: redirect.php maligns redirection URL every time

    On 26 Oct 2006 10:33:23 -0700, "comp.lang. php"
    <phillip.s.powe ll@gmail.comwro te:
    $url = $redirectArray[$id]['attributes']['URL'];
    if (trim($redirect Array[$id]['attributes']['QUERY_STRING']) !== '?')
    >$url .= '?';
    $url .= preg_replace('/&#061;/i', '=',
    >$redirectArr ay[$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($redirect Array[$id]['attributes']['QUERY_STRING']) !== '?') {
    $url .= '?';
    $url .= preg_replace('/&#061;/i', '=',
    $redirectArray[$id]['attributes']['QUERY_STRING']);
    }
    $url = preg_replace('/\/$/', '', $url); // REMOVE TRAILING /

    hth

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

    Comment

    Working...