0
    spl_autoload_register("auto");
    function auto($class_name){
        include_once($class_name.'.php');
    }

$url=new clean_url($_SERVER["REQUEST_URI"]);
    $c=1;
    //echo $url->segment(2);
    if(!$url->segment($c)){
           //include homepage
    }
    else{
        switch($url->segment($c)){
            case 'events':
            include_once($_SERVER['DOCUMENT_ROOT'].'/events.php');
            break;
            default:
            include_once('404.php');
            break;
        }
    }

?>

in the events.php file

<?php
if($url->segment($c+1)){
$e=$url->segment($c+1);
switch ($e) {
    case 'ecstasy':
        include_once($_SERVER['DOCUMENT_ROOT'].'temps/ecstasy.php');
        break;

    default:
        # code...
        break;
}
}

while testing the code on localhost(xampp) the code is working and the req. pages are being included.But when trying on the big rock server the output is coming as

Fatal error: Call to a member function segment() on a non-object in /home/public_html/events.php on line 2

What can be the reason for this difference and how can i make it work on the bigrock servers?

Kumar V
  • 8,810
  • 9
  • 39
  • 58
vishu
  • 41
  • 4
  • did you try `print_r($url);`? – Kumar V Jan 15 '14 at 10:04
  • `spl_autoload_register()` should throw exceptions when the autoload_function cannot be registered. – Krish R Jan 15 '14 at 10:08
  • Are you absolutely positive that you did not include events.php somewhere else before these code blocks are even executed? As @KrishR mentioned, `spl_autoload_register` should have already thrown an error even before the `switch` statements. – Bez Hermoso Jan 15 '14 at 10:09
  • on localhost its giving on using print_r:clean_url Object ( [path:clean_url:private] => /events ) but on server no output is coming – vishu Jan 15 '14 at 10:13
  • @Bez: the above code is in index.php file and the address i used was sitename.com/events/ – vishu Jan 15 '14 at 10:19
  • after i add $url=new clean_url($_SERVER['REQUEST_URI']); in the events.php file at the top the server is giving Fatal error: Class 'clean_url' not found in /home/mechamjc/public_html/events.php on line 2 whereas – vishu Jan 15 '14 at 10:29

1 Answers1

1

I don't know why this code works in XAMPP but the fatal error reported by Bigrock Servers is correct. You have error in your code, as $url shouldn't be accessible from included file because this variable and included file are in different scopes. All include directives are limited to their local scopes. Now some help: you can manually import variables before inclusion in many ways - for example use extract function.

Community
  • 1
  • 1
Grzegorz Adam Kowalski
  • 5,243
  • 3
  • 29
  • 40