Jump to content

Recommended Posts

<?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.

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.

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.

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.

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,

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.