My PHP knowledge is extremely limited--so much so that I may not even be phrasing what I want to do coherently. Apologies! But here's the thing: I know this can be done because I've used it before and I know of a few sites that use it still. I just can't for the life of me remember how.

Can you define what you mean by "multiple pages in one PHP file"? Do you mean having different content based on various parameters in the URL (or in cookies, etc.), or something else?

    To continue the reddit post:

    I recall a file looking something like this:

    header

    <PHP coding to display "thispage">
    Content for this page.

    <PHP coding to display "thatpage">
    Content for that page.

    <PHP coding to display "thenextpage">
    Content for the next page.

    footer

    And the URLs would look like:

    index.php?thispage
    
    index.php?thatpage
    
    index.php?thenextpage

    Which looks to me to be completely opposed to any sense of maintainability. Why would you want to do that?

      Makes more sense to actually have the content in separate files, which you could then include/require into the main page, if you want to do something like that. But then I'd want to use some web server config stuff so that I could just request /thispage and have it rewritten to call /index.php?page=thispage or such, then index.php might do:

      $include_path = '/path/to/include/files/';
      if(file_exists($include_path.basename($_GET['page'])) {
        require $include_path.basename($_GET['page']));
      } else {
        // output 404 error and exit
      }
      

      Basically you're then turning index.php into a controller a la the MVC pattern (with the included files being the View part, and no real Models?)

        8 days later

        Copy and paste the following into a text editor. <html>, go to your code and separate the code into 3 areas and save each with a . php extension, and after do 2 'save as' and duplicate your 'page1. php' and call them 'page2, and last create a new page and call it 'index.php'.

          Write a Reply...