Jump to content

little php help with a code that i don't understand quite well


bogdaniel

Recommended Posts

hello i was doing a little google research until i found a website with a tutorial about creating urls without using mod rewrite can someone please explain it to me and give me some example as procedual code and oop? thank you very much for helping me in your spare time.

 

 

<?php

 

// Get the URL relative to the script

$url = $_SERVER['PATH_INFO'];

 

// If for some reason $_SERVER["PATH_INFO"] does not work then

// you could use $_SERVER["REQUEST_URI"] or $_SERVER["PHP_SELF"]

 

// Remove the /index.php/ at the beginning

$url = preg_replace('/^(\/)/','',$url);

 

// Split URL into array

$url = explode('/',$url);

 

// Display array

print_r($url);

 

?>

[/[code=php:0]

Use this:

http://pastebin.com/fc5fee28

 

This allows you to use url's in the format:

http://<domain>/<page>.php[/<module>]/<controller>/<action>/<param1>/<value1>

 

examples:

// module = admin
// controller = users
// action = edit
// id = 1
http://localhost/index.php/admin/users/edit/id/1

// module = default
// controller = register
// action = index
http://localhost/index.php/register

// module = default
// controller = login
// action = index
http://localhost/index.php/login

thank you very much i will have a look on that php file :)

 

Here's an updated version: http://pastebin.com/f12cbc64c

 

Edit: I tested it and I can confirm it works. If you want I can submit you the used code.

 

P.S. This is the correct format:

http://<domain>/<page>.php[/<module>]/<controller>[/<action>[/<param1>/<value1>]]

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.