Jump to content

.php extension change in browser


David Nelson

Recommended Posts

Hey guys,

 

For a special project I'm doing I need a .php page to show up as either a different extension in the address bar or no extension at all (i.e., right now it is search.php?action=XXXXX, I want it to be simply search?action=XXXXX) or something to that extent.

 

Do I need to do something with my server mime types or what?

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/101792-php-extension-change-in-browser/
Share on other sites

PHP on Windows sucks....because of Windows. And especially in CGI mode.

 

Also....

 

http://youdomain.com/?pid=2&search=12

 

Simplified example..

"index.php"

<?php

function getContent() {

  $pageID = $_GET['pid'];

  switch($pageID) {
    case 2:
      Search($_GET['search']);
    break;
    
    default:
      mainContent();
  }

}

function mainContent() {
  //Whatever dude. Load a template file or add your HTML here.
}

  getContent();


?>

 

Instead of using/linking to a million diferent PHP files...just use functions or even include files and add some kind of conditional statement that determines what content to load. Technically, you don't need to have the extension in the url. Apache mod_rewrite would be much nicer than this though.

Post to any given page (i.e. post.php).  Then when finished processing redirect back to the folder page with a get var so that page knows if the processing was successful.  You'd redirect with the command:

 

header("Location: ../dir/?command=success"); // if successful, or command=fail if failed.

 

Really simple example but the idea should work.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.