Super simple method to implement pseudo URLs in php

Source: Internet
Author: User

Just like the address path in my log, let index. php? Action = one & do = two
Changed :? Index/action/one/do/two
Copy codeThe Code is as follows:
Index. php
--------------
<? Php

// PARSING QUERY STRING
$ QS = explode ("&", $ _ SERVER ['query _ string']);
$ QS = explode ('/', $ QS [0]);

// IF Modul is Undefined set it to index
If (! $ QS [0]) $ MODUL = 'index ';
Else $ MODUL = strtolower ($ QS [0]);

// WE can make a Variable $ _ QUERY
// For alternative _ GET
For ($ I = 1; $ I <count ($ QS); $ I + = 2)
{
$ _ QUERY [$ NVAR] = $ NVAR = $ QS [$ I];
$ NVAR = $ QS [$ I + 1];
}

// Check the Modul is exists?
If (! File_exists ("modul_directory/{$ MODUL}. php "))
$ MODUL = "index ";

#### THIS IS EXAMPLE TO IMPLEMENTATION THE SCRIPT
// Load The Template
Include ("template. php ");
// Load The Module
Include ("modul_directory/{$ MODUL}. php ");
// Load The Footer
Include ("footer. php ");

?>

We can access the modul in URL like this:
======================================

Www.example.com /? Forum/topic/20
-It mean load the modul forum. php, and set the _ QUERY ['topic '] = 20

Www.foo.com /? Voting/id/54/type/piechart & choice = 2
-It mean load the modul voting. php, and set the _ QUERY ['id'] = 54 and _ QUERY ['type'] = 'piechar' and set _ GET ['choice'] = 2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.