Fatal error: Cannot redeclare als_version() (previously declared in H:\xampp\htdocs\www\todo\1uwafc\stats\functions.php:19) in H:\xampp\htdocs\www\todo\1uwafc\stats\functions.php on line 20
Does this mean that I am using it more then once and because of the way this is coded, it cannot be reused???
I will post functions.php in another in another post as its too large for this one.
solidariti
01-03-2006, 06:53 PM
functions.php
17 function ALS_version(){
18 // this function is used by install.php, it returns the version of a.l.s.
19 return "1.0";
20 }
Which is called vai manual.php, by include ("../config.php"): which then includes functions.php with the above code in.
config.php : I have removed some values for security purposes.
17 function ALS_version(){
<?PHP
$server = "localhost"; // often localhost
$username = "root"; // Your MySQL server username
$password = ""; // Your MySQL server password
$database = "stats"; // If you fill in nothing database 'members' will be used. If 'members' doesn't exist it will be created.
$DBprefix = ""; // the prefix for the tables in the database (can be left blank)
// The ranks for the members. The first in the list is userlevel is 1, every item after (seperate with comma's) increases with one.
// so the example below is: 1 = newbie, 2=new member, 3=member, 4=high member, 5=very high member, ect
$ranks = array(
1=>"anonymous",
2=>"supporter",
3=>"player",
4=>"committee",
5=>"captain",
6=>"moderator",
7=>"administrator"
);
// ErrorStrings:
$couldNotConnectMysql = "Could not connect MySQL<BR>\n please check your settings in config.php<br>error returned:";
$couldNotOpenDatabase = "Could not open database<BR>\n please check your settings in config.php<br>error returned:";
// ------------------------- //
// start of the functions :) //
// ------------------------- //
function ALS_version(){
// this function is used by install.php, it returns the version of a.l.s.
return "1.0";
}
function als_mail($mail_to='', $subject='', $message='', $headers=''){
if(trim($mail_to) == ""){die("ALS Mail error: No email address entered");}
if(trim($subject) == ""){die("ALS Mail error: No email Subject entered");}
if(trim($message) == ""){die("ALS Mail error: No Email message entered");}
// SMTP doesn't really work well yet :(
function getSetting($setting="", $module="ALS"){
global $DBprefix, $settingArray;
if (count($settingArray) == 0){
$query = "select setting, value, module from ".$DBprefix."settings where module='$module'";
$result = mysql_query($query);
echo mysql_error();
while($row=mysql_fetch_array($result)){
$settingArray[$row["module"]][$row["setting"]] = $row["value"];
}
}
return $settingArray[$module][$setting];
}
function addSetting($setting, $value, $module="ALS"){
global $DBprefix, $settingArray;
$query = "INSERT INTO `".$DBprefix."settings` (`setting`, `value`, `module`) VALUES ('$setting', '$value', '$module')";
$result = mysql_query($query);
$settingArray[$module][$setting] = $value;
}
function changeSetting($setting, $value, $module="ALS"){
global $DBprefix, $settingArray;
$query = "UPDATE `".$DBprefix."settings` SET `value`=\"". addslashes($value) ."\" WHERE `setting`=\"". addslashes($setting) ."\" AND module='$module'";
$result = mysql_query($query);
$settingArray[$module][$setting] = $value;
}
//This function prints the menu from the table
function showMenu(){
$result = @mysql_query("SELECT name, location, reqlevel FROM ".$DBprefix."menu");
if (!$result) {
die('<p>Error: ' . mysql_error() . '</p>');
}
while ( $row = mysql_fetch_array($result) ) {
if($user_current_level < $row['reqlevel']) {
echo('<a href="'.$row['location'].'" target="mainFrame">'.$row['name'].'</a><br>');
}
}
}
solidariti
01-03-2006, 06:55 PM
// supporting functions, don't call these directly.
function ALS_SUPPORT_smtpmail($mail_to, $subject, $message, $headers = ""){
// first we check if al the requerd fields are filled in.
// if not stop the script execution now.
if(trim($mail_to) == ""){die("SMTP error: No email address entered");}
if(trim($subject) == ""){die("SMTP error: No email Subject entered");}
if(trim($message) == ""){die("SMTP error: No Email message entered");}
// first we replace al newlines with the correct form (\r\n)
$message = preg_replace("/(?<!\r)\n/si", "\r\n", $message);
// check if there is header info
if ($headers != ""){
// if there is check if it is an array
if(is_array($headers)){
// then we check how long (how many items) it is
if(sizeof($headers) > 1){
// if there are more than 1 item, we join them into 1 string separated by \r\n
$headers = join("\r\n", $headers);
}else{
// if it is only 1 item we just set the string to that item.
$headers = $headers[0];
}
}
// remove 'useless' whitespaces
$headers = rtrim($headers);
// we replace al newlines with the correct form (\r\n)
$headers = preg_replace("/(?<!\r)\n/si", "\r\n", $headers);
// we put the CC and BCC in the header, and put them in 2 array's
// to do that, we first make an array out of the header.
$header_array = explode("\r\n", $headers);
// we put the arraypointer back to the first item, even if it is already there
@reset($header_array);
// we empty the original header variable
$headers = "";
// we check if the content of an array item cotains a bcc or cc.
while(@list(, $header)=each($header_array)){
if( preg_match("/^cc:/si", $header)){
// check for cc
$cc = preg_replace("/^cc:(.*)/si", "\\1", $header);
}else if( preg_match("/^bcc:/si", $header )){
// and check for the bcc
$bcc = preg_replace("/^bcc:(.*)/si", "\\1", $header);
$header = "";
}
// add a newline on the end of the header.
$headers .= $header . "\r\n";
}
// we remove 'useless' linefeedbacks again
$headers = chop($headers);
// we make an array out of the $cc variable
$cc = explode(",", $cc);
// same for the $bcc variable
$bcc = explode(",", $bcc);
}
// put the to-adres in an array.
$mail_to_array = explode(",", $mail_to);
// we are now done with the headers, so lets open the connection the the smtp server
$socket = fsockopen(getSetting('smtphost'), getSetting('smtphostport'), $errno, $errstr, 20);
// check if we actually connected
if (!$socket){die("SMTP error: Could not connect to smtp host: $errno : $errstr");}
// if the connection is succesfull we wait for the server to respond... it should respond with a code 220
wait4anwser($socket, "220", "init connection");
// we check if there is an username / password, to see how we should login to the server
if(getSetting('smtpuser') != "" && getSetting('smtphostpass') != ""){
// if ther is a password we use the EHLO 'method'
fputs($socket, "EHLO " . getSetting('smtphost') . "\r\n");
wait4anwser($socket, "250","EHLO");
// we tell the server we want to login using username / password
fputs($socket, "AUTH LOGIN\r\n");
wait4anwser($socket, "334","AUTH LOGIN");
// send the username
fputs($socket, base64_encode(getSetting('smtpuser')) . "\r\n");
wait4anwser($socket, "334","Username");
// send the password
fputs($socket, base64_encode(getSetting('smtphostpass')) . "\r\n");
wait4anwser($socket, "235","password");
}else{
// we just use the HELO 'method'
fputs($socket, "HELO " . getSetting('smtphost') . "\r\n");
wait4anwser($socket, "250","login");
}
// now that we are connected al server responds should be 250
// who the mail is from....
fputs($socket, "MAIL FROM: " . getSetting('email_message_header') . "\r\n");
wait4anwser($socket, "250","MAIL FROM");
// build the header with al the adresses to who should be send an e-mail
$to_header = "To: ";
@reset( $mail_to_array );
while( @list( , $mail_to_address ) = each( $mail_to_array ))
{
// Add an additional bit of error checking to the To field.
$mail_to_address = trim($mail_to_address);
if (preg_match('/[^ ]+\@[^ ]+/', $mail_to_address)){
fputs($socket, "RCPT TO: <$mail_to_address>\r\n");
wait4anwser($socket, "250", "RCPT TO");
}
$to_header .= ( ( $mail_to_address != '' ) ? ', ' : '' ) . "<$mail_to_address>";
}
// now we do the same for the CC and BCC fields...
// set the array pointer to the first item
@reset( $bcc );
while( @list( , $bcc_address ) = each( $bcc ))
{
// remove the useless spaces...
$bcc_address = trim( $bcc_address );
if ( preg_match('/[^ ]+\@[^ ]+/', $bcc_address) )
{
fputs( $socket, "RCPT TO: <$bcc_address>\r\n" );
wait4anwser( $socket, "250", "bcc");
}
}
// again for the CC
@reset( $cc );
while( @list( , $cc_address ) = each( $cc ))
{
// Add an additional bit of error checking to cc header
$cc_address = trim( $cc_address );
if ( preg_match('/[^ ]+\@[^ ]+/', $cc_address) )
{
fputs($socket, "RCPT TO: <$cc_address>\r\n");
wait4anwser($socket, "250", "cc");
}
}
// Tell the server we are ready to start sending data
fputs($socket, "DATA\r\n");
wait4anwser($socket, "354", "data");
// Send the Subject Line...
if (!eregi ('Subject:',$subject)) fputs($socket, "Subject: $subject\r\n");
// Send the To Header.
if (!eregi ('To:',$headers)) fputs($socket, "$to_header\r\n");
// Send al other headers
fputs($socket, "$headers\r\n\r\n");
// we send the message to the server
fputs($socket, "$message\r\n");
fputs($socket, ".\r\n");
// wait for the server to respond.
wait4anwser($socket, "250", "done");
// Now tell the server we are done and close the connection...
fputs($socket, "QUIT\r\n");
fclose($socket);
// we return true so the script using the ALS_mail function can continue.
return TRUE;
}
// Finally the database connection
// If the prefix is not empty add an _ (underscore)
if ($DBprefix != ""){$DBprefix = $DBprefix . "_";}
// Code to make sure that the $database field was filled and code to connect to the database
if ($database == ""){$database= "members";}
// connect or show an error.
$conn = mysql_connect($server,$username,$password) or die ($couldNotConnectMysql.mysql_error());
if ($installer!="nodbsel"){
mysql_select_db($database,$conn) or die ($couldNotOpenDatabase.mysql_error());
}
balloonbuffoon
01-04-2006, 12:04 AM
Well I didn't go through your code but that error is just saying that you are trying to define a function twice. To avoid trying to declare the same function twice, just do something like this:
if (!function_exists("function_name")) {
function function_name() {
//code
} //end function
} //end if
You can do that for every one of your functions and you shouldn't get that error anymore.
--Steve
solidariti
01-12-2006, 12:28 PM
Thank you for balloonbuffon, its works,
balloonbuffoon
01-12-2006, 03:00 PM
No problem!
webdeveloper.com
Copyright Internet.com Inc., All Rights Reserved.