1

Ill be using parameter of URL like this http://localhost/biyahero/user/mark instead of this http://localhost/biyahero/user.php?name=mark

I already tried

 $test=explode( '/', $_SERVER['REQUEST_URI'] );
echo $test[3]; 

And it works fine, but when im accessing the actual page, both css and js is not working properly. what am I missing ?

1
  • just use absolute URLs for css and js.. instead of ../../path/to/cssFile.css use /path/to/cssFile.css Commented Aug 4, 2016 at 6:02

2 Answers 2

1

You must use absolute URLs to load the css and js files.

Instead of relative URLs like:

../../path/to/cssFile.css

use absolute URLs:

/path/to/cssFile.css
Sign up to request clarification or add additional context in comments.

Comments

1

You need the server's PATH_INFO variable for this to work correctly. But be aware that you need to configure your server accordingly as well.

Then in PHP you can call pathinfo() like this:

<?php
$path_parts = pathinfo('/www/htdocs/inc/lib.inc.php');

echo $path_parts['dirname'], "\n";
echo $path_parts['basename'], "\n";
echo $path_parts['extension'], "\n";
echo $path_parts['filename'], "\n"; // since PHP 5.2.0
?>

Server configuration for Apache

# Set document root to be "webroot"
DocumentRoot "path/to/webroot"
<Directory "path/to/webroot">
    # use mod_rewrite for pretty URL support
    RewriteEngine on
    # If a directory or a file exists, use the request directly
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    # Otherwise forward the request to index.php
    RewriteRule . index.php

    # ...other settings...
</Directory>

and Nginx:

server {
    # ...

    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass 127.0.0.1:9000;
        #fastcgi_pass unix:/var/run/php5-fpm.sock;
        try_files $uri =404;
    }

    # ...
}

WARNING: this can pose several security issues if not configured properly, make sure that:

  1. User upload files can never be accessed when this rule is applied
  2. set ["cgi.fix_pathinfo = 0;" in php.ini][2]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.