stockton Posted August 4, 2008 Share Posted August 4, 2008 If I issue the following from my logon.php the mail get sent correctly $mailstring = date('Y-m-d H:i:s') . " ".$erroruser." Logged on from ". $client; $headers = 'From: es-master@stockton.co.za' . "\r\n" . 'Reply-To: alf.stockton@telkomsa.net' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail("alf@stockton.co.za","Dinner Event",$mailstring,$headers); but if I include it as require_once('includes/error-handler.inc'); from the logon.php it does not work. All variables are populated in both cases. Please explain why this is happening. Link to comment https://forums.phpfreaks.com/topic/118058-command-in-php-works-but-not-if-in-a-inc-file/ Share on other sites More sharing options...
JasonLewis Posted August 4, 2008 Share Posted August 4, 2008 Usually if I want to make it a .inc I'd make it a .inc.php Same with most extensions. For classes I use .class.php Link to comment https://forums.phpfreaks.com/topic/118058-command-in-php-works-but-not-if-in-a-inc-file/#findComment-607318 Share on other sites More sharing options...
rlelek Posted August 4, 2008 Share Posted August 4, 2008 Quote Usually if I want to make it a .inc I'd make it a .inc.php Same with most extensions. For classes I use .class.php Absolutely! Also, it may be worth mentioning that you MUST enclose the PHP portions of your .inc fine with PHP tags. Just because you require/include it, does not mean it is included in PHP. Actually, I believe the default for requiring/including a file acts like it is importing (X)HTML. Just be sure to include those tags! Those simple things happen to the best of us sometimes... Ryan Link to comment https://forums.phpfreaks.com/topic/118058-command-in-php-works-but-not-if-in-a-inc-file/#findComment-607319 Share on other sites More sharing options...
stockton Posted August 4, 2008 Author Share Posted August 4, 2008 I do have <?php and ?> at the beginning and end of my error-handler.inc ? Link to comment https://forums.phpfreaks.com/topic/118058-command-in-php-works-but-not-if-in-a-inc-file/#findComment-607325 Share on other sites More sharing options...
MadTechie Posted August 4, 2008 Share Posted August 4, 2008 .inc files will NOT be parsed unless you add the .inc as a php handler on the apache server. if you have access to the system files on the server or using cPanel you can fix this. if i have lost you then just rename the file to "error-handler.inc.php" (infact i would do that in anycase) Link to comment https://forums.phpfreaks.com/topic/118058-command-in-php-works-but-not-if-in-a-inc-file/#findComment-607328 Share on other sites More sharing options...
PFMaBiSmAd Posted August 4, 2008 Share Posted August 4, 2008 When including/requiring a file through the file system, the file name does not matter for the include/require to function (it does matter if you put sensitive information into the file, such as a database username/password, because if it does not end in .php, someone can browse to it and see the php code in the file.) If this was being done through a URL/http request, the file extension would matter and control if the file was parsed or not by php before being included into the current script. Link to comment https://forums.phpfreaks.com/topic/118058-command-in-php-works-but-not-if-in-a-inc-file/#findComment-607332 Share on other sites More sharing options...
PFMaBiSmAd Posted August 4, 2008 Share Posted August 4, 2008 Quote it does not work. Define: "it does not work". That could mean anything, such as a blank page because the require_once() failed because the path/file is incorrect and caused a fatal runtime error to your login no longer works because some white-space is preventing headers... What do you see in front of you when you do this? Link to comment https://forums.phpfreaks.com/topic/118058-command-in-php-works-but-not-if-in-a-inc-file/#findComment-607334 Share on other sites More sharing options...
stockton Posted August 4, 2008 Author Share Posted August 4, 2008 I do not understand the ".inc files will NOT be parsed unless you add the .inc as a php handler on the apache server" as all other commands in the included file work fine. The included file contains a function which accepts a string as a parameter, builds a HTML page and also writes the string to a text file and then attempts to send an email, so saying it will not be parsed is going over my head and I do not understand. It is just the mail() command that fails but if I include the same mail() call directly in the parent php it works fine. BTW The "it does not work" means that the email is not sent. Link to comment https://forums.phpfreaks.com/topic/118058-command-in-php-works-but-not-if-in-a-inc-file/#findComment-607335 Share on other sites More sharing options...
PFMaBiSmAd Posted August 4, 2008 Share Posted August 4, 2008 Quote The included file contains a function... That is not what the code you posted shows. You must post actual code to get specific help with what it is or is not doing. Link to comment https://forums.phpfreaks.com/topic/118058-command-in-php-works-but-not-if-in-a-inc-file/#findComment-607341 Share on other sites More sharing options...
stockton Posted August 4, 2008 Author Share Posted August 4, 2008 <?php // Thanks to http://www.tonymarston.net/php-mysql/errorhandler.html // set_error_handler('errorHandler'); function get_sql_error($sQuery, $hDb_conn, $sError, $bDebug) { if(!$rQuery = @mysql_query($sQuery, $hDb_conn)) { $sMssql_get_last_message = mysql_get_last_message(); $sQuery_added = "BEGIN TRY\n"; $sQuery_added .= "\t".$sQuery."\n"; $sQuery_added .= "END TRY\n"; $sQuery_added .= "BEGIN CATCH\n"; $sQuery_added .= "\tSELECT 'Error: ' + ERROR_MESSAGE()\n"; $sQuery_added .= "END CATCH"; $rRun2= @mysql_query($sQuery_added, $hDb_conn); $aReturn = @mysql_fetch_assoc($rRun2); if(empty($aReturn)) { echo $sError.'. MYSQL returned: '.$sMysql_get_last_message.'.<br>Executed query: '.nl2br($sQuery); } elseif(isset($aReturn['computed'])) { echo $sError.'. MYSQL returned: '.$aReturn['computed'].'.<br>Executed query: '.nl2br($sQuery); } return FALSE; } else { return $rQuery; } } function errorHandler ($errno, $errstr) { // echo "<br>Entered errorHandler()<br>"; // echo $errno." ".$errstr; switch ($errno) { case E_USER_WARNING: case E_USER_NOTICE: case E_WARNING: case E_NOTICE: case E_CORE_WARNING: case E_COMPILE_WARNING: break; case E_USER_ERROR: case E_ERROR: case E_PARSE: case E_CORE_ERROR: case E_COMPILE_ERROR: global $query; echo '<html xmlns="http://www.w3.org/1999/xhtml">'; echo '<head>'; echo '<title>Message</title>'; echo '<style>'; echo '<!--'; echo '.normalcopy { font-family: Verdana, Arial; font-size: 11px; color: Black; }'; echo '.bottomlinks { color: #666666; font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: normal; text-decoration: none; }'; echo '-->'; echo '</style>'; echo '</head>'; echo '<body bgcolor="#ffffff">'; $errorstring = "<align=center>" .date('Y-m-d H:i:s') .""; // $errstr .= " " . $erroruser; echo '<center>'; echo '<table border="0" cellpadding="0" cellspacing="0" width="748">'; echo '<tr>'; echo '<td align left = "" valign="top" height="73" class="normalcopy">'; echo '<p align="center"><strong>'.$errstr.'</p>'; echo '</td></align></tr>'; echo '</table>'; echo '</center>'; $logfile = "errorlog.html"; $client = $_SERVER['REMOTE_ADDR']; $errorstring .= " "; $errorstring .= $errstr; $errorstring .= " on "; $errorstring .= $client; $errorstring .= " by "; $errorstring .= $erroruser; $errorstring .= "<br>"; $Boodskap = "<br><align=left>" . date('Y-m-d H:i:s') . " " . $errstr; error_log($Boodskap, 3, $logfile); $headers = 'From: es-master@stockton.co.za' . "\r\n" . 'Reply-To: alf.stockton@telkomsa.net' . "\r\n"; mail("alf@stockton.co.za","Error log",$Boodskap,$headers); default: break; } // switch // get_sql_error($insert, $link, NULL, NULL); // echo "<a href=index.php><img src=images/Back.png>"; echo "</BODY>"; echo "</HTML>"; } // errorHandler ?> Link to comment https://forums.phpfreaks.com/topic/118058-command-in-php-works-but-not-if-in-a-inc-file/#findComment-607345 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.