Jump to content

How to make an admin panel ?


Rommeo

Recommended Posts

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.

 

Link to comment
Share on other sites

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;
}

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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.