Page 1 of 1

PHP URL

Posted: Sun Jun 21, 2009 5:49 pm
by aminiasitk
Ok I have the following code snippet:

Code: Select all

    
    if(isset($_SERVER['PHP_SELF']))
    {
        // Pop the last elememt of array $_SERVER[]
        $content_id = array_pop(explode("/", $_SERVER['PHP_SELF']));
        
        // The following lines of code helps determines if current request is a page or section 
        $check_type = explode(".", $content_id);
        
        // Check if it has an html extension
        if($check_type[1] != 'html')
        $request->setSectionContent($content_id);   
        else
        $request->setPageContent($check_type[0]);
    }
 
Say the value returned by $_SERVER['PHP_SELF'] is http://localhost/pages.php/about-us.
After this line of code:
$content_id = array_pop(explode("/", $_SERVER['PHP_SELF']));
the value of $content_id will be "about-us". Ok the code works fine but the problem is external javascript files and stylesheets are not loading properly so the contents of the page are messed up. But I don't see any php error messges.

Is it because from PHP perspective http://localhost/pages.php/about-us is not a valid url. When I use http://localhost/pages.php?sectionid=about-us all the external stylesheets and js files are loaded successfully so the page looks fine....

Re: PHP URL

Posted: Sun Jun 21, 2009 6:24 pm
by requinix
It's because the browser thinks that all URLs are relative to pages.php/about-us. If you tell it to go looking for "js/example.js" it'll look for pages.php/js/example.js.

Use absolute locations: /js/example.js - with the leading slash.

Re: PHP URL

Posted: Mon Jun 22, 2009 4:37 pm
by aminiasitk
Thanx dude it works fine now!!!