I
I
i_want_to_know_everything2016-10-12 02:00:07
CMS
i_want_to_know_everything, 2016-10-12 02:00:07

Creating virtual pages?

there is an array there is a function
$array = array('page-1','page-2','page-3');

function page_content(){
  echo 'hellow world';
}

how to make pages available with the content of the page_content function displayed on them at the following addresses:
  • domain.com/page-1.php
  • domain.com/page-2.php
  • domain.com/page-3.php

without their physical creation
Throw off pliz links to explanations of the algorithm how this is done.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
X
xmoonlight, 2016-10-12
@i_want_to_know_everything

1. We register all requests for one file in .htaccess:

RewriteRule .* index.php [L]

2. Then, in php, based on $_SERVER['REQUEST_URI'] we do routing: if the required ending is contained in the query string, we return the content, if not - 404.
(use: preg_match + switch-case-default )

D
dev400, 2016-10-12
@dev400

Break the url by a slash, remove the .php extension, and use in_array() to check if the url and the array element match

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question