url conversion and validation

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rjwebgraphix
Forum Newbie
Posts: 11
Joined: Fri Mar 11, 2005 8:10 am

url conversion and validation

Post by rjwebgraphix »

Code Below: Problem - Always follows the 404 path after first non-match. Only need to Error 404 if what is in the address bar or $PATH_INFO doesn't match. Code is documented, so should be able to spot where I'm a goof at relatively easy.

Any help fixing is appreciated.

RJ

Code: Select all

<?
// $PATH_INFO comes from address bar
// Address example: http://www.mysite.com/start/lc0/survey/ ... c0/welcome
//                  http://www.mysite.com/ file/var/ file /var/file /var/ file
// Is  same as:     http://www.mysite.com/start.php?lc0=sur ... c0=welcome
$fakeurl = explode("/",$PATH_INFO); 

for ($i=1, $j=count($fakeurl); $i<$j; $i++)
{
    $name =  $fakeurl[$i]; //
    $i++;
    $value = $fakeurl[$i];
    
    // if template has been set handle it
    if ($name == 'te')
    {
        $tpage = $value; // sets $tpage to template name
        $$name = $value; // sets $te to template name
        echo "it did set the template file info";
    }
    
    // sets up only valid vars LC0 thru LC9, RC0 thru RC9, etc.
    // and lpage00 thru lpage09 just like LC, RC & MC
    $goodvars = array('l','r','m');
        $goodnums = array(0,1,2,3,4,5,6,7,8,9);
    	
        foreach ($goodvars as $goodvar)
        {
	        foreach ($goodnums as $goodnum)
            {
                $greatvar = $goodvar. 'c' .$goodnum;
                $setvar = $goodvar. 'page0' .$goodnum;
		    	
		    	// Compare $name to $greatvar, should match to be good or match TE
		    	// TE handled previously as TE its constant
		        if($name == $greatvar)
                {
                    if ($value == '0')
                    {
                        $$setvar = ''; // sets $lpage00 thru 09 to nothing
                        $$name = $value;  //sets $lc0 thru $lc9
                        echo "it did equal one time with zero";
                    }
                    else
                    {
                    $$setvar = $value; // Sets variable $lpage00 thru $lpage09
                    $$name = $value; // sets $lc0 thru $lc9
                    echo "it did equal one time with value";
                    }
                }
                // busted in this area.....
                //
                // Only what is on the address bar would need to bust if it 
                // doesn't match.  This will send to ERROR 404 page
                elseif (($name != $greatvar) or ($name != 'te'))
                {
                    echo "ERROR 404";
                    echo $name. '<P>';
                    echo $greatvar. '<P>';
                    print_r ($PATH_INFO);
                    //gohome($whereto);  // sends to error 404 function
                    die();
                }
            }
        }
}
echo $lc0.' == LC0<P>';
echo $lc1.' == LC1<P>';
echo $lc2.' == LC2<P>';
echo $lc3.' == LC3<P>';
echo $lc4.' == LC4<P>';
echo $lc5.' == LC5<P>';
echo $lc6.' == LC6<P>';
echo $lc7.' == LC7<P>';
echo $lc8.' == LC8<P>';
echo $lc9.' == LC9<P>';
echo $rc0.' == rc0<P>';
echo $rc1.' == rc1<P>';
echo $rc2.' == rc2<P>';
echo $rc3.' == rc3<P>';
echo $rc4.' == rc4<P>';
echo $rc5.' == rc5<P>';
echo $rc6.' == rc6<P>';
echo $rc7.' == rc7<P>';
echo $rc8.' == rc8<P>';
echo $rc9.' == rc9<P>';
echo $mc0.' == mc0<P>';
echo $mc1.' == mc1<P>';
echo $mc2.' == mc2<P>';
echo $mc3.' == mc3<P>';
echo $mc4.' == mc4<P>';
echo $mc5.' == mc5<P>';
echo $mc6.' == mc6<P>';
echo $mc7.' == mc7<P>';
echo $mc8.' == mc8<P>';
echo $mc9.' == mc9<P>';
echo $te.' == te<P>';
?>
Post Reply