FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Path problem in php





fladry
Is there any way to use a unicode directory name? I can't make a unicode named directory . And, is there any way to emulate a directory in php? I mean if the user types "www.mydomain.com/hello/world" my script gets the hello and world as argument and runs and there is no need for me to have those directories. Is there any method for it?
rickylau
fladry wrote:
Is there any way to use a unicode directory name? I can't make a unicode named directory . And, is there any way to emulate a directory in php? I mean if the user types "www.mydomain.com/hello/world" my script gets the hello and world as argument and runs and there is no need for me to have those directories. Is there any method for it?

For Unicode directory name, technically it's possible if the server supports unicode directory name, but the URL of the may be needed to encoded. In my opinion you better not use unicode as directory name since not everyone can input those characters.


For path as arguments as I remembered it is possible via .htaccess configuration, seems to be mod_rewrite module. I remember that you can also check if the path exists so you can still serve those existing page too.
Fire Boar
Try this as a .htaccess file:

Code:
Options -Indexes
Options +FollowSymLinks

# Uncomment these four lines if you want to handle any 404 errors yourself. No ending quote for
# compatibility with Apache 1.3.
#ErrorDocument 404 /index.php
#<Files favicon.ico>
#  ErrorDocument 404 "The requested file favicon.ico was not found.
#</Files>

# Set the default page.
DirectoryIndex index.php

<IfModule mod_rewrite.c>
  RewriteEngine on
  # Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !=/favicon.ico
  RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</IfModule>


Then include the following function in index.php or one of the files include() or require() uses:

Code:
function arg($index) {
  static $args = null;
  if ($args === null) {
    $args = explode('/', $_GET['q']);
  }
  return $args[$index];
}


Now anywhere in your php application, you can use arg(n) to get the nth argument. So for www.mydomain.com/hello/world, arg(0) would return "hello", and arg(1) would return "world". This only applies to paths that don't exist, so if you try to access - say - /images/fun.png, it won't run your PHP script, instead returning the file itself.
Related topics
Cron Jobs and Php
Cron Daemon on server 2 (frih.net) [resolved]
installing apache,mysql and php on windows
PHP and relative/absolute paths
Joomla Installation Problem --> Session Save Path
Java classpath problem
new guy needs help
Moving website - Joomla config - path problem ???
[suggestion] about the language translation forum
Cron jobs on DirectAdmin
Stats problem - php execution problem (MOD Assist Required)
Shortened URL path in php
Has anyone installed Moodle successfully?
Server Configuration Problem
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.