Current location: Hot Scripts Forums » Programming Languages » PHP » define() and include problem


define() and include problem

Reply
  #1 (permalink)  
Old 04-21-07, 11:28 PM
darkcarnival's Avatar
darkcarnival darkcarnival is offline
PHP/MySQL coder
 
Join Date: Jun 2003
Posts: 939
Thanks: 0
Thanked 0 Times in 0 Posts
define() and include problem

hi,

this somewhat relates to an older topic i made last week.

basically i was trying to figure out why the download script i was using kept causing the file to get mess up(kept making random symbols and junk)

after several tests i found the error, the define constants im using for my mysql login details doesnt seem to go well with the download script.

basically i added the define on the download page, this caused no problems at all. but when i included the file that had the exact same define values it caused errors.

so my question is, how can i prevent/fix this?

i've been trying to fix this for a while now, and whoever helps me will really be doing me a fat one
Reply With Quote
  #2 (permalink)  
Old 04-21-07, 11:38 PM
mab's Avatar
mab mab is offline
Community VIP
 
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
You would need to post the relevant code so that someone could examine it for the problem and/or duplicate the problem.

I suspect that you wrote an indexed variable like this - $_POST[someindex] or $_FILES[someindex] (not making the index name a quoted string) and someindex is also a defined constant and PHP used that instead of what you intended.
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???
Reply With Quote
  #3 (permalink)  
Old 04-21-07, 11:45 PM
darkcarnival's Avatar
darkcarnival darkcarnival is offline
PHP/MySQL coder
 
Join Date: Jun 2003
Posts: 939
Thanks: 0
Thanked 0 Times in 0 Posts
well im using define() and thats personal data

as to the download code, here it is:

PHP Code:

#define the values needed.
$id $_GET['id'];

#see if any important ids are left blank.
if(empty($id)){
    
#send that user to the index page.
    
header("Location: index.php"); 
}
// Check to see if the download script was called
if (basename($_SERVER['PHP_SELF']) == 'downloader.php'){
    
#see if attachment is listed, if so proceed.
    
$q mysql_query("select Filename from ebb_attachments where id='$id'");
    
$attach_ct mysql_num_rows($q);
    
$attach_r mysql_fetch_assoc($q);
    
#    $db->run = "select Filename from ebb_attachments where id='$id'";
#    $attach_ct = $db->num_results();
#    $attach_r = $db->result();
#    $db->close();
        
    
if ($attach_ct == 1){
        
#check if the file exists, if it doesn't, fire an error message and kill the script
        
$file str_replace('%20'' '$attach_r['Filename']);
        
$dl_path "uploads/".$file;
        
#see if the user is trying to access another directory.
        
if (substr($file01) == '.' || strpos($file'..') > || substr($file01) == '/' || strpos($file'/') > 0){
            
#Display hack attempt error
            
die("Hack attempt detected!");
        }
        
#see if the file exists.
        
if(!file_exists($dl_path)){
echo 
"404";
        }
        
$ext strtolower(substr(strrchr($file"."), 1));
        
#Determine correct MIME type
        
switch($ext){
            case 
"asf":     $type "video/x-ms-asf";                break;
            case 
"avi":     $type "video/x-msvideo";               break;
            case 
"exe":     $type "application/octet-stream";      break;
            case 
"mov":     $type "video/quicktime";               break;
            case 
"mp3":     $type "audio/mpeg";                    break;
            case 
"mpg":     $type "video/mpeg";                    break;
            case 
"mpeg":    $type "video/mpeg";                    break;
            case 
"rar":     $type "encoding/x-compress";           break;
            case 
"txt":     $type "text/plain";                    break;
            case 
"wav":     $type "audio/wav";                     break;
            case 
"wma":     $type "audio/x-ms-wma";                break;
            case 
"wmv":     $type "video/x-ms-wmv";                break;
            case 
"zip":     $type "application/x-zip-compressed";  break;
            default:        
$type "application/force-download";    break;
        }
        
#Fix IE bug.
        
$header_file = (strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE')) ? preg_replace('/\./''%2e'$filesubstr_count($file'.') - 1) : $file;
        
header("Pragma: public"); #required.

        
header("Expires: 0");

        
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");

        
header("Cache-Control: private",false); #some browsers require this

        
header("Content-Type: $type");
        
#declares file as an attachment.
        
header("Content-Disposition: attachment; filename=\"" $header_file "\";");

        
header("Content-Transfer-Encoding: binary");
        
        
header("Content-Length: ".filesize($dl_path));
    
        
#Send file for download
        
if ($stream fopen($dl_path'rb')){
            while(!
feof($stream) && connection_status() == 0){
                
#reset time limit for big files
                
set_time_limit(0);
                print(
fread($stream,1024*8));
                
flush();
            }
            
fclose($stream);
        }
    }else{
        
#display an error here.
        
echo "ERROR!";
    }
}
ob_end_flush();
?> 
i snipped out the include function since it was what i already ruled out. i have confirmed the download script is not to blame.

basically in a nutshell, if i have to remove the define() functions, i would like to use a method that would be just as secure as thats a top priority for this application.

thanks
Reply With Quote
  #4 (permalink)  
Old 04-22-07, 12:05 AM
mab's Avatar
mab mab is offline
Community VIP
 
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
This is just a guess since you did not post it, but the include file probably contains PHP syntax errors or the include(...) function call was failing due to a path/file name problem. X-out the sensitive information in your code, but post the actual file so that the syntax and defined constant names can be seen.

You did mention errors, what exactly are they???

We cannot help you without "seeing" the same information you have about the problem. The only way we can see what you see is if you post it or describe it accurately.
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???
Reply With Quote
  #5 (permalink)  
Old 04-22-07, 12:10 AM
darkcarnival's Avatar
darkcarnival darkcarnival is offline
PHP/MySQL coder
 
Join Date: Jun 2003
Posts: 939
Thanks: 0
Thanked 0 Times in 0 Posts
by errors i mean the files get messed up to the point that they dont open or if they you just get a bunch of rubbish.

this is what config has in it:

PHP Code:

if (!defined('IN_EBB') ) {
die(
'<b>!!ACCESS DENIED HACKER!!</b>');
}

// Database Connection Settings.

define("DB_HOST""localhost"); //usually this is localhost if it isnt ask your provider
define("DB_NAME""xxxxxxx"); //Name of your Database
define("DB_USER""xxxxxxx"); //Username of Database
define("DB_PASS""xxxxxxx"); //Password of database

//password encryption salt. This was created for you during the install. DO NOT ALTER THE VALUE!!
define("PWDSALT""xxxxxxxxxxxx"); 
but heres the kicker, i add this to the download file directly, no problems at all

now i would just add the connection string to the download file if i was the only one using this, but this is a script that anyone will be able to use so i cant go that route.
Reply With Quote
  #6 (permalink)  
Old 04-22-07, 12:33 AM
mab's Avatar
mab mab is offline
Community VIP
 
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
Any PHP opening and closing tags <?php ... ?> at the beginning and end in that file, or did you just omit them in the post?
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???
Reply With Quote
  #7 (permalink)  
Old 04-22-07, 08:20 AM
darkcarnival's Avatar
darkcarnival darkcarnival is offline
PHP/MySQL coder
 
Join Date: Jun 2003
Posts: 939
Thanks: 0
Thanked 0 Times in 0 Posts
i omitted them in the post, sorry i didnt mention that.

any ideas mab?
Reply With Quote
  #8 (permalink)  
Old 04-23-07, 03:37 AM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
Quote:
Originally Posted by darkcarnival View Post
by errors i mean the files get messed up to the point that they dont open or if they you just get a bunch of rubbish.
What kind of rubbish? maybe there's something wrong with the headers you set, so the file is displayed instead of downloaded?

Is the setting "display_errors" turned on? and what's the level of error_reporting. To debug your script add the following lines on top of your code (if not allready set like that in the ini file):
PHP Code:

ini_set('display_errors''1');

error_reporting(E_ALL); 
UnrealEd
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Reply With Quote
  #9 (permalink)  
Old 04-23-07, 07:53 AM
darkcarnival's Avatar
darkcarnival darkcarnival is offline
PHP/MySQL coder
 
Join Date: Jun 2003
Posts: 939
Thanks: 0
Thanked 0 Times in 0 Posts
i have errors on and error report to e_all already since im on my dev server.

as to what rubbish? alot of random characters.

for example, when i tried a word file, when opening it i got a pop-up to select a encoding setting.

but i already have everything set to binary in the script so thats not causing it.

plus i already seen that when i dont include the config file, i dont get any problems.
Reply With Quote
  #10 (permalink)  
Old 04-23-07, 08:05 AM
darkerstar's Avatar
darkerstar darkerstar is offline
Newbie Coder
 
Join Date: Apr 2007
Location: London
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Have you tried not using the buffered output? Having read your problem, it seems mostly like to be something got messed up when file is being dumped in the output stream.

Also I suggest you check on your server if its not your file that's corrupt, and take out some headers like Content-Transfer-Encoding.
__________________
Read Tiaon Lab blog
PHP + Delphi programming
http://www.tiaon.com/wordpress/
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Include problem in C bkbenson C/C++ 4 02-08-05 04:24 AM
Constants, define(), and HTML Amulet PHP 5 01-10-05 04:55 PM


All times are GMT -5. The time now is 06:01 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.