2004-06-29, 19:19 | Link #1 |
Junior Member
Fansubber
|
/file.html after .php?
I notice that AnimeSuki uses URLs with slashes and filenames after a PHP filename (ex. http://www.animesuki.com/group.php/00.html). This has me both confused and interested, because I'm used to seeing URLs with standard GET systax (ex. http://www.example.com/group.php?group_id=00). I assume that the pseudo-directory syntax has some advantage over the GET syntax, else AnimeSuki would not use it.
I would like to know what advantage directory syntax has over GET syntax, and also how to implement it in my own pages (example code much appreciated). Apologies in advance if this is in the wrong forum. |
2004-06-30, 00:48 | Link #2 | |
Senior Member
Join Date: Apr 2001
Location: Athens, Greece
Age: 41
|
Quote:
Anyway, what you need is $HTTP_SERVER_VARS["PATH_INFO"]. Create a file called test.php and put this code in[PHP]<? echo $HTTP_SERVER_VARS["PATH_INFO"]; ?>[/PHP] Now call your script with a random syntax http://www.mysite.com/test.php/page.html The result will be a print that says "/page.html", now you can use the content of the $HTTP_SERVER_VARS["PATH_INFO"] variable for anything you want. As for encoding more than one variables in the path... I'm not there yet
__________________
|
|
2004-06-30, 12:42 | Link #3 |
…Nothing More
Administrator
Join Date: Mar 2003
Age: 44
|
As Lefteris_D said, the server variable "path_info" is often used to improve search engine compatibility. Until recently very few search engines supported trawling web documents that could only be accessed via links that passed information in the "query_string"; a notable exception to this being Google.
This meant that pages using information after the "?" in the URL would not be seen and would hence not be indexed by the spider. That or they would be requested without the query information; resulting in a "default" page view regardless of context or possibly just meaningless errors -- all of which would just "poison" the search engines database. Using the path_info you get around this by passing the required information in the already supported "path" component of the URL. It is also considered more esthetically pleasing; "viewdoc/100.html" looks nicer and is often easier to remember than "viewdoc.php?document_id=100". This becomes even more powerful when you have lots of other variables. For example; on this forum a url like: http://forums.animesuki.com/showthread.php?t=12345&page=5Could look much better as: http://forums.animesuki.com/showthread/12345/5.htmIf the software supported it... Once you're aware of it you'll notice it on many more sites; like Amazom for example. They often put session id information in the URL in such a way that all the links on the page "auto-magically" pick up the session id, thus maintaining the session even if you don't have cookies enabled. I believe a lot of JSP applications do the same. P.S. If you are using a version of PHP greater than 4.1.0 (which you really should be by now) you don't want to use the "$HTTP_SERVER_VARS" at all, you want to use the super-global "$_SERVER" instead; as the former is deprecated . Last edited by NightWish; 2004-06-30 at 12:59. Reason: Added PS. |
2004-06-30, 12:57 | Link #4 | |
Senior Member
Join Date: Apr 2001
Location: Athens, Greece
Age: 41
|
Quote:
Note: $HTTP_SERVER_VARS can be used in php5 if enabled much like Register Globals though it is not recommended.
__________________
|
|
2004-06-30, 13:02 | Link #5 |
…Nothing More
Administrator
Join Date: Mar 2003
Age: 44
|
Oh and you can encode as much as you like into the path, so long as you use valid URL characters...
[PHP]<?php $params = explode( '/', $_SERVER['PATH_INFO'] ); print_r( $params ); ?>[/PHP] Spoiler for Output using url example from previous post...:
|
2004-06-30, 13:13 | Link #6 |
Senior Member
Join Date: Apr 2001
Location: Athens, Greece
Age: 41
|
Yeah, I just realized that $_server['PATH_INFO'] can be handled as an array(stupid me!).
Here is a nice article that features a similar example and a nice .htaccess sample to hide the .php extension Last edited by Lefteris_D; 2004-06-30 at 13:15. Reason: replaced a few words |
2004-07-01, 15:23 | Link #7 |
Administrator
Administrator
Join Date: Jan 2001
Location: Netherlands
Age: 45
|
Well, pretty much everything has been said already...
For Apache 2.0, make sure you check this page: http://httpd.apache.org/docs-2.0/mod...acceptpathinfo |
2004-07-02, 23:02 | Link #9 | |
Evangelist of the Kazoo
Join Date: Apr 2003
Location: AnimeSuki Forums
|
Quote:
|
|
|
|