Advanced page handling. Need a little help.

Discussion in 'PHP' started by CHA0S, Apr 13, 2010.

  1. #1
    
    <?php 
    $cmd = $_GET["cmd"];
    
    if ($cmd=='home') {
        include("cms/index.php");
    } elseif ($cmd=='images') {
    	include("cms/imagemanager.php");
    } elseif ($cmd=='seo') {
    	include("cms/seo.php");
    } elseif ($cmd=='mail') {
    	include("cms/mail.php");
    } elseif ($cmd=='logout') {
        include("cms/logout.php");
    } else {
    	include("cms/index.php");
    }
    ?>
    
    Code (markup):
    Basically, this script should handle which page is displayed. For instance, if the user chooses to navigate to the images page, the href will be "admin.php?cmd=images". The admin.php page obviously contains the PHP code above, and is located in the root directory. Lets say the user is now viewing the images page and they try to upload an image. After the image uploads and the page refreshes, they are taken back to the index page...but they should still be on the images page, and they should get a message saying the upload was successful. I was expecting this error to arise when I made my page handling code, but I can't figure a way around it...so I'm in need of some fresh ideas. All the pages have to be in the cms directory, so please don't suggest I move them. The admin.php file must also stay in the root directory. Cheers.
     
    CHA0S, Apr 13, 2010 IP
  2. capt_nemo777

    capt_nemo777 Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    why are they being taken to the index page after uploading an image ? you must have placed a redirect script that redirects them after uploading an image ?
    why not try to put a success message on the image page itself and remove any redirection after upload ?
    ( not sure but i think that's what's happening in your web app ? )
     
    capt_nemo777, Apr 13, 2010 IP
  3. CHA0S

    CHA0S Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Let me clarify the problem a little: imagemanager.php manages the upload and the success message...and it isn't just uploading images that causes problems...any time the page needs to reload and send a cmd value not known by my page handling code, it will go back to the index page and I don't want this. I guess what I need is a way of getting the last cmd value so I can know if they were on the images page, or any other page that causes a problem...then I can include that page as normal and it will handle any requests, such as an image upload, properly.

    The user could end with http:website.com/admin.php?select=1 in their address bar. But they will only get the normal index page because the admin.php code doesn't have a way of handling it....and there are a lot of different things that do this, so I don't want to add code for each separate function, I need to know where I came from if you get me. Thanks.
     
    CHA0S, Apr 13, 2010 IP
  4. CHA0S

    CHA0S Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    OK, I figured it out on my own, here's how I solved the problem if anyone was wondering:
    
    <?php 
    $cmd = $_GET["cmd"];
    
    if ($cmd=='home') {
        include("cms/index.php");
    } elseif ($cmd=='images') {
    	include("cms/imagemanager.php");
    } elseif ($cmd=='seo') {
    	include("cms/seo.php");
    } elseif ($cmd=='mail') {
    	include("cms/mail.php");
    } elseif ($cmd=='logout') {
        include("cms/logout.php");
    } else {
    	if (ereg('images', ($_SERVER['HTTP_REFERER']))) {
    		include("cms/imagemanager.php");						   
    	} elseif (ereg('seo', ($_SERVER['HTTP_REFERER']))) {
    		include("cms/seo.php");	
    	} elseif (ereg('mail', ($_SERVER['HTTP_REFERER']))) {
    		include("cms/mail.php");								
    	} elseif (ereg('logout', ($_SERVER['HTTP_REFERER']))) {
    	    include("cms/logout.php");			
        } else {
    	    include("cms/index.php");
        }	
    }
    ?>
    
    Code (markup):
    Thanks anyway guys,

    EDIT: Obviously, this does have rare chance of working incorrectly if that last url contains a another one of those words. A better way of doing it would be to add code in the admin.php file which somehow detects when the page is about to change, and it adds a variable to the end of the url to which the browser is about to navigate. If anyone knows how to do that, it would be great, however, this will have to suffice for now.
     
    Last edited: Apr 13, 2010
    CHA0S, Apr 13, 2010 IP