Includes.. they hate me

Show off new creations, get help, or just chat about all aspects of web development and design.

Includes.. they hate me

Postby theblahman on Tue Sep 23, 2008 7:05 am

Okay so over the past few days I've been working on some PHP scripts that have includes in them. Now, it was working 100% on my localhost xampp server but when I uploaded them to my web server they died. I traced it down to the includes.. if I have includes in the script it dies.

Now I know for a fact it wasn't a path error because I tried so many alternatives. Now the wierd thing is, normally an error message appears but nothing comes up. Even when I put some stuff to be echo'd before it and after it nothing comes up, it's like it's exiting. Here's where it gets even stranger... I have a central file that brings together a function file, a db function file and a constants file, including the central file, the script dies. Including the function file by itself it doesn't exit, but it doesn't work 100%.

I checked my httpd error logs and there's nothing. Emailed my host and they have no idea what the hell is going on.

how I'm doing my include:
Code: Select all
include('examplefile.php');


Basically my scripts are structured like phpBB 3, but all done by myself. Why it works on the localhost server but not at all online confuses me.

Any ideas? Or am I stuck with some random bug.

Cheers.
I design (v4.1 released 23/2) and Tweet.
User avatar
theblahman
May Contain Skills
May Contain Skills
 
Joined: Sun Jan 15, 2006 3:55 am
Location: Australien

Re: Includes.. they hate me

Postby Blink on Tue Sep 23, 2008 10:35 am

This may be a stupid question but you are using <?php ?> tags round it yes?
User avatar
Blink
Cool 'n that
Cool 'n that
 
Joined: Fri Oct 08, 2004 4:16 pm
Location: UK

Re: Includes.. they hate me

Postby theblahman on Tue Sep 23, 2008 10:48 am

Yeah. Sorry, just put in the code blocks the include part. There's actually heaps more to the script, just didn't add it.

I'll chuck it in now.

(removed sensitive info)
Code: Select all
<?php

    include
('common.php');
    
    include
('includes/secure.inc.php');
    
    $mode 
= get_var('mode');
    $action = get_var('action');
    
    switch 
($mode)
        {
            // creates a new folder
            case 'new' :
                
                include
('includes/folders/new.php');
            
            break
;
            
            
// confirm deletion of folder
            case 'confdelete' :
            
                include
('includes/folders/folder_confdelete.php');
            
            break
;
            
            
// deletes folder
            case 'delete' :
            
                include
('includes/folders/folder_delete.php');
            
            break
;
            
            
// files section
            case 'files' :
            
                $name 
= get_var('name');
                $id = get_var('id');
                
                switch 
($action)
                    {
                        case 'upload' :
                            
                            include
('includes/folders/upload.php');
                        
                        break
;
                        
                        case 
'view' :
                        
                            if 
(preg_match('*&name*', $_SERVER['argv'][0]))
                                {
                                    include('includes/folders/view_folder.php');
                                }
                            elseif (preg_match('*&id*', $_SERVER['argv'][0]))
                                {
                                    include('includes/folders/view_image.php');
                                }
                        
                        break
;
                        
                        case 
'delete' :
                        
                            include
('includes/folders/file_delete.php');
                        
                        break
;
                        
                        case 
'confdelete' :
                        
                            include
('includes/folders/file_confdelete.php');
                        
                        break
;
                        
                        default 
:
                        
                            header
('Location: ' . $phps );
                        
                        break
;
                    }
                
            break
;
            
            
// logout
            case 'logout' :
            
                
// logout stuff
            
            break
;
            
            
// list folders 
            default :
            
                include
('includes/folders/default.php');
            
            break
;
        }

?>
I design (v4.1 released 23/2) and Tweet.
User avatar
theblahman
May Contain Skills
May Contain Skills
 
Joined: Sun Jan 15, 2006 3:55 am
Location: Australien

Re: Includes.. they hate me

Postby zombie@computer on Tue Sep 23, 2008 5:46 pm

try adding
Code: Select all
error_reporting(E_ALL);

at the top of your php, see if theres errors coming out. Also, you can try require() instead of include(), as require() throws a fatal error, while include() does not. If your scripts uses headers or redirection, you may need to use an php errorlog instead, as any output will be lost into a sea of white and browsers heading away

i assume you already looked at the included files not exit()ing at some point?
When you are up to your neck in shit, keep your head up high
zombie@computer
Forum Goer Elite™
Forum Goer Elite™
 
Joined: Fri Dec 31, 2004 5:58 pm
Location: Lent, Netherlands

Re: Includes.. they hate me

Postby theblahman on Tue Sep 23, 2008 9:21 pm

zombie@computer wrote:try adding
Code: Select all
error_reporting(E_ALL);

at the top of your php, see if theres errors coming out. Also, you can try require() instead of include(), as require() throws a fatal error, while include() does not. If your scripts uses headers or redirection, you may need to use an php errorlog instead, as any output will be lost into a sea of white and browsers heading away

i assume you already looked at the included files not exit()ing at some point?


Ironically there was a error_reporting(E_ALL) in the common.php file :P

Just then I tried putting in the error_reporting then changing them to requires and it's still exiting.

I put a joke function called get_lulz into my functions page which is included in the common page which is then included in the main page. Bad news, the function does work, but the page still exits! My error log is totally empty too.

However, there is not one exit in the entire script, it worked fine on my localhost server too! I'm thinking it's my hosts php config, but I just can't seem to find why it's happening.

Maybe I'll try rebuilding the whole script from the bottom up to try and locate what the fuck is going wrong.
I design (v4.1 released 23/2) and Tweet.
User avatar
theblahman
May Contain Skills
May Contain Skills
 
Joined: Sun Jan 15, 2006 3:55 am
Location: Australien

Re: Includes.. they hate me

Postby zombie@computer on Wed Sep 24, 2008 9:02 am

theblahman wrote:
zombie@computer wrote:try adding
Code: Select all
error_reporting(E_ALL);

at the top of your php, see if theres errors coming out. Also, you can try require() instead of include(), as require() throws a fatal error, while include() does not. If your scripts uses headers or redirection, you may need to use an php errorlog instead, as any output will be lost into a sea of white and browsers heading away

i assume you already looked at the included files not exit()ing at some point?


Ironically there was a error_reporting(E_ALL) in the common.php file :P

Just then I tried putting in the error_reporting then changing them to requires and it's still exiting.

I put a joke function called get_lulz into my functions page which is included in the common page which is then included in the main page. Bad news, the function does work, but the page still exits! My error log is totally empty too.

However, there is not one exit in the entire script, it worked fine on my localhost server too! I'm thinking it's my hosts php config, but I just can't seem to find why it's happening.

Maybe I'll try rebuilding the whole script from the bottom up to try and locate what the fuck is going wrong.
there are multiple ways to exit a php script, like exit(), die(), using headers() return; in included php scripts, etc. PHP has a whole bunch of roads leading to rome...
When you are up to your neck in shit, keep your head up high
zombie@computer
Forum Goer Elite™
Forum Goer Elite™
 
Joined: Fri Dec 31, 2004 5:58 pm
Location: Lent, Netherlands

Re: Includes.. they hate me

Postby theblahman on Wed Sep 24, 2008 9:24 am

ahk, well. I have a shitload of returns and 2 headers. I just don't understand why it would work 100% fine on xampp but is totally dead on a live server. That's whats killing me slowly.
I design (v4.1 released 23/2) and Tweet.
User avatar
theblahman
May Contain Skills
May Contain Skills
 
Joined: Sun Jan 15, 2006 3:55 am
Location: Australien

Re: Includes.. they hate me

Postby theblahman on Mon Oct 13, 2008 5:39 am

Okay, so it turns out it wasn't an include problem. It's a problem with the SQL connection function.

Code: Select all

<?php
    
    echo 1
;
    
    $dbhost 
= 'localhost';
    // $dbuser = 'root'; // LOCAL VARIABLE
    $dbuser = ''; // LIVE VARIABLE <--- removed for this post
    // $dbpass = ''; // LOCAL VARIABLE
    $dbpass = ''; // LIVE VARIABLE <--- for this post i removed the password
    // $dbname = 'storage';
    $dbname = ''; // LIVE VARIABLE <!--- removed the table name too just in case ;)
    
    echo 2
;
    
    class db
        
{
            
            function sql_connect
($dbhost, $dbuser, $dbpass, $dbname)
                {
                    $this->host = $dbhost;
                    $this->user = $dbuser;
                    $this->pass = $dbpass;
                    $this->name = $dbname;
                    
                    if 
(!$this->db_connect_id = @mysqli_connect($this->host, $this->user, $this->pass, $this->name))
                        {
                            $this->sql_error($this->db_connect_id);
                        }
                    else
                        
{
                            return $this->db_connect_id;
                        }                
                
}
        }
        
    echo 3
;
    
    $db 
= new db($dbhost, $dbuser, $dbpass, $dbname);
    
    echo 4
;
    
    $db
->sql_connect($dbhost, $dbuser, $dbpass, $dbname);
    
    echo 5
;
?>


After uploading the script and viewing the page I get:

1234

echo'd out which is not quite what I want. The actual connection function is fine, but when it's called it doesn't work. I've checked the error log on my server but it has nothing. I can't work out why! I'm aware that if it can't connect it won't be able to find the error handler, because I've stripped it down so I can find out wtf is going on. Besides, the unfound error handler would come up as an error in the error log, which it doesn't.

It works fine on xampp but not at all on my webserver. It's pretty much the same as phpBB's connection script but theirs works on my server!

*tears out hair*

EDIT:
okay turns out i'm a moron. My web server didn't have the MySQLi extension enabled so that's why it was fucking up. I'm interested as to why it wasn't recorded to the error log though. Hmmmm...
I design (v4.1 released 23/2) and Tweet.
User avatar
theblahman
May Contain Skills
May Contain Skills
 
Joined: Sun Jan 15, 2006 3:55 am
Location: Australien

Return to Web Design & Development

Who is online

Users browsing this forum: No registered users

cron