PSYCHONAUT Posted April 13, 2010 Share Posted April 13, 2010 <?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"); } ?> 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...I'm just getting started with PHP...so I'm in need of some fresh ideas from more experienced coders. 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. Quote Link to comment https://forums.phpfreaks.com/topic/198351-advanced-page-handling-need-a-little-help/ Share on other sites More sharing options...
oni-kun Posted April 13, 2010 Share Posted April 13, 2010 What is the problem with this? Either add the "Successful" message along with the information of the image uploaded in session, or add a &done=true key for example at the end of the url to show it is done, whilst still on the admin.php?cmd=images. Quote Link to comment https://forums.phpfreaks.com/topic/198351-advanced-page-handling-need-a-little-help/#findComment-1040763 Share on other sites More sharing options...
PSYCHONAUT Posted April 13, 2010 Author Share Posted April 13, 2010 Well, the problem is, 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. Quote Link to comment https://forums.phpfreaks.com/topic/198351-advanced-page-handling-need-a-little-help/#findComment-1040771 Share on other sites More sharing options...
PSYCHONAUT Posted April 13, 2010 Author Share Posted April 13, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/198351-advanced-page-handling-need-a-little-help/#findComment-1040777 Share on other sites More sharing options...
PSYCHONAUT Posted April 13, 2010 Author Share Posted April 13, 2010 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"); } } ?> Thanks anyway guys, Quote Link to comment https://forums.phpfreaks.com/topic/198351-advanced-page-handling-need-a-little-help/#findComment-1040782 Share on other sites More sharing options...
PSYCHONAUT Posted April 13, 2010 Author Share Posted April 13, 2010 Obviously, that 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. Quote Link to comment https://forums.phpfreaks.com/topic/198351-advanced-page-handling-need-a-little-help/#findComment-1040787 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.