• (nodebb)

    Oops, no, we don't split, we take a substring, which means we couldn't have a route upload_image or showitems, since they'd collide with upload and showitem.

    Frist of all, some pendantry : you can do it, but you have to put the if()s in the right order (i.e. check for showitems before you check for showitem, and so on).

    Of course, that's a horrible maintenance load, because every new "page" has to be checked against every existing page to make sure that every if() chain is constructed correctly.

  • (nodebb)

    TRWTF is not splitting once and doing a switch, in which case this isn't really that bad. Fortunately you don't need to worry about scaling . . .

  • (nodebb)

    I particularly like how it just creates a form that does nothing if the URL isn't one that it handles.

  • Sauron (unregistered)

    All the routes in that application lead to the same place: they're a highway to (maintenance) hell.

  • (nodebb)

    TCDR (Too confusing, didn't read.)

  • (nodebb)

    Imagine you're building a PHP web application

    Oh no, this is already a nightmare

  • (nodebb)

    I don't see a collission with longer strings. It's doing an equality check with the rest of the URL, not a string search.

    However, it means you can't have any additional parameters after =XXX because they'll be included in REQUEST_URI.

  • Weretaco (unregistered)

    It's doing a substrnof a specific length (e.g., 0-6 for upload), at least for all but the first two items, so that would return the same thing for upload and upload_image

  • Duston (unregistered)
    Comment held for moderation.
  • (nodebb)

    I cleaned it up a bit for you guys:

    $requestUri = $_SERVER['REQUEST_URI'];
    $requestReverse = substr($requestUri, strrpos($requestUri, '=') + 1);
    $requestForward = substr($requestUri, stripos($requestUri, '=') + 1);
    
    if($requestReverse == 'request') 
    {
    	echo "<form name=\"request\" action=\"\" method=\"post\" enctype=\"multipart/form-data\" onsubmit=\"return validrequest();\">\n";
    }
    else if($requestReverse == 'response') 
    {
    	echo "<form action=\"\" method=\"post\" onsubmit=\"return validresponse()\">\n";
    }
    else if(substr($requestForward, 0, 7) == 'respond') 
    {
    	echo "<form name=\"respond\" action=\"\" method=\"post\" enctype=\"multipart/form-data\" onsubmit=\"return validresponse();\">\n";
    }
    else if(substr($requestForward, 0, 6) == 'upload')
    {
    	echo "<form name=\"upload\" method=\"post\" action=\"\" enctype=\"multipart/form-data\">\n";
    }
    else if(substr($requestForward, 0, 8) == 'showitem') 
    {
    	echo "<form name=\"showitem\" action=\"\" method=\"post\" enctype=\"multipart/form-data\">\n";
    }
    else if(substr($requestForward, 0, 7) == 'adduser') 
    {
    	echo "<form name=\"adduser\" action=\"\" method=\"post\" onsubmit=\"return validadduser();\">\n";
    }
    else if(substr($requestForward, 0, 8) == 'edituser') 
    {
    	echo "<form name=\"adduser\" action=\"\" method=\"post\" onsubmit=\"return validedituser();\">\n";
    }
    else
    {
    	echo "<form action=\"\" method=\"post\">\n";
    }
    

    I have to apologize for the names of the variables; I really couldn't came up with anything better haha

    Addendum 2024-02-21 14:50: I just noticed: For both "routes" adduser and edituser the form name is adduser. Looks like someone failed with their copy&pasting&rewriting.

  • (nodebb)

    You know what, if we already go the super wacko route of routingness, why not embrace it with a glorious switch:

    $requestUri = $_SERVER['REQUEST_URI'];
    $requestReverse = substr($requestUri, strrpos($requestUri, '=') + 1);
    
    switch($requestReverse)
    {
    	case 'request': echo '<form name="request" method="post" action="" enctype="multipart/form-data" onsubmit="return validrequest();">'. PHP_EOL; break;
    	case 'response': echo '<form action="" method="post" onsubmit="return validresponse()">'. PHP_EOL; break;
    		
    	default:
    		$requestForward = substr($requestUri, stripos($requestUri, '=') + 1);
    		if(substr($requestForward, 0, 7) == 'respond') 
    			echo '<form name="respond" method="post" action="" enctype="multipart/form-data" onsubmit="return validresponse();">'. PHP_EOL;
    		else if(substr($requestForward, 0, 6) == 'upload')
    			echo '<form name="upload" method="post" action="" enctype="multipart/form-data">'. PHP_EOL;
    		else if(substr($requestForward, 0, 8) == 'showitem') 
    			echo '<form name="showitem" method="post" action="" enctype="multipart/form-data">'. PHP_EOL;
    		else if(substr($requestForward, 0, 7) == 'adduser') 
    			echo '<form name="adduser" method="post" action="" onsubmit="return validadduser();">'. PHP_EOL;
    		else if(substr($requestForward, 0, 8) == 'edituser') 
    			echo '<form name="adduser" method="post" action="" onsubmit="return validedituser();">'. PHP_EOL;
    		else
    			echo '<form action="" method="post">' .PHP_EOL;
    		break;
    }
    

    Yeah, there's no way to make this thing even look pretty; guess the only proper way to do this is to either go .htaccess or use Klein or something similar.

  • (nodebb)
    Comment held for moderation.
  • retsep (unregistered)
    Comment held for moderation.
  • Nick (unregistered)
    Comment held for moderation.

Leave a comment on “Route to Success”

Log In or post as a guest

Replying to comment #:

« Return to Article