Category Archives: PHP

Anything related to PHP and any Frameworks associated.

Bootstrapping – Relative Path trailing slash / (PHP)

When developing a site with bootstrapping in mind, (by the way bootstrapping is a technique in web development when all request gets directed to one page that is usually index.php for example a request to page, , etc. is handled by index.php with the help of a mod_rewrite script in the root directory. And creates a slug url for SEO.) when this is done an issue will occur relating to relative path and pointing to static files in your site such as images, css and scripts especially . Imagine this scenario:
Examine the file structure


When someone request a url from your site eg. “http://domain/user” and in the page your css points to “css/style.css”, your page will come out alright but when they add a slash at the end “/” “http://domain/user/” like so, your browser will interpret the slash as a folder location to “user/” so if your path to your css is “css/style.css”, your browser will look for the file in “user/css/style.css” which in this case the folder doesnt exist and so your website will come out really messed up.

So remember to fix this when you are developing a site based on bootstrapping. You can fix this either by .mod_rewrite or simply via your PHP script by checking the trailing slash at the end from the REQUEST_URI variable.
Until next time.

PHP Header Function – Redirect – Exit

I was developing my site when something weird happened , mostly sessions get UNSET in the end of my php script, but when developing In the middle script a redirect function like the “header(‘location: http://mydomain/etc’);” I assumed once redirected the any script below it wont run anymore but I was wrong.

Then as soon as the header function has been called, the script below it ,has triggered as well while performing redirect. At first I didnt know what was wrong with it until I just unknowingly added EXIT; after the header function and everything works fine.

So for my reference ALWAYS REMEMBER TO PUT an exit function AFTER the redirect function so that there wont be any weird issues developing your site along the way. Especially when your developing using PHP.