Rommeo Posted October 12, 2008 Share Posted October 12, 2008 Hi I'm curious about how you build admin panels. I m trying to make an admin panel. I have some pages like "addnews.php editnews.php deletenews.php / addphoto.php editphoto.php deletephoto.php Now i wanna give link to these files. What should i do now ? should i create an panel.php file and use an if statement like if ( $page == 'addnews' ) include['addnews.php'] else if ( $page == 'editnews'] ... then when you want to add page, you should enter www.site.com/panel.php?process = addnews or should i give link to every file from the panel.php file. when you enter www.site.com/addnews.php at this time i should add a small script to every file for anyone not to reach directly. How do you deal with the files that you dont want anyone to reach directly? i will be glad if anyone can help. thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/128086-how-to-make-an-admin-panel/ Share on other sites More sharing options...
wildteen88 Posted October 12, 2008 Share Posted October 12, 2008 Dont create seperate pages like addnews.php editnews.php delnews.php merge them all it on to one file - news.php then use urls like admin.php?module=news&action=add admin.php?module=news&action=edit admin.php?module=news&action=delete to do whatever you want. Here is how you implement it: In admin.php you'd do something like if(isset($_GET['module']) && file_exists('./'.$_GET['module'].'.php') { // include the module eg news.php include $_GET['module'] . '.php'; } Now in your modules you'll use this base code if(isset($_GET['action'])) { switch($_GET['action'])) { /* possible actions for module */ case 'add': /* code to add*/ break; case 'edit': /* code to edit*/ break; case 'del': /* code to delete*/ break; default: die('Invalid Command'); break; } Quote Link to comment https://forums.phpfreaks.com/topic/128086-how-to-make-an-admin-panel/#findComment-663307 Share on other sites More sharing options...
Rommeo Posted October 12, 2008 Author Share Posted October 12, 2008 wildteen88 thank you for the quick reply .. but what makes me think is action "add" for the "news" and the action "add" for the "photo" is different. In your example you just include the module not the action. How can i deal with it at that time ? Would be so glad if you can show me a tutorial about it. Trying to figure it out. Quote Link to comment https://forums.phpfreaks.com/topic/128086-how-to-make-an-admin-panel/#findComment-663309 Share on other sites More sharing options...
wildteen88 Posted October 12, 2008 Share Posted October 12, 2008 No, the action is handled by the module. admin.php just includes the requested module. This first part of the code: if(isset($_GET['module']) && file_exists('./'.$_GET['module'].'.php') { // include the module eg news.php include $_GET['module'] . '.php'; } Goes in admin.php. This just includes the module, eg news.php, photo.php etc The second part: if(isset($_GET['action'])) { switch($_GET['action'])) { /* possible actions for module */ case 'add': /* code to add*/ break; case 'edit': /* code to edit*/ break; case 'del': /* code to delete*/ break; default: die('Invalid Command'); break; } Goes in your module eg news.php, photo.php Example setup now attached [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/128086-how-to-make-an-admin-panel/#findComment-663323 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.