skip to Main Content

I have this file structure:

  • New

    • frontend

      • index.php
    • backend

    • index.php

If Can can I make frontend and backend folder hide like

localhost/new/frontend/index.php

Will become:

localhost/new/

2

Answers


  1. I’m sure that MVC will resolve your current issue. So, we should implement the website by following the MVC standard.

    Some examples:

    https://medium.com/@noufel.gouirhate/create-your-own-mvc-framework-in-php-af7bd1f0ca19

    https://github.com/DawidYerginyan/simple-php-mvc

    Login or Signup to reply.
  2. If you’re writing it in native PHP then you have to write your own routing system. Something like this:

    $str = "$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
    $sections = explode("/", $str, 3);
    
    $page = (isset($sections[2]) && $sections[2] != '') ? $sections[2] : 'homepage';
    $page = parse_url($page);
    $page = trim($page['path'], '/');
    
    // list of your custom php function
    $functions = array(
        'contact-us-success' => 'contact_us_success',
    );
    
    //check functions first
    if (isset($functions[$page])) 
    {
        call_user_func($functions[$page]);
        return true;
    } 
    
    //else check page
    elseif (is_file("pages/{$page}.php")) 
    {
        include_once("pages/template/header.php");
        include_once("pages/{$page}.php");
        include_once("pages/template/footer.php");
        return true;
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search