random numbers vs sequential numbers
Moderator: General Moderators
-
skydivelouie
- Forum Newbie
- Posts: 23
- Joined: Tue Jan 18, 2005 7:07 pm
random numbers vs sequential numbers
I need an expert who can help me out with a precise answer...I can't seem to find an answer on the net or in other forums...Please Help...
This is what I'm trying to accomplish...
$Alpha = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
$a = rand(0,25);
$b = rand(0,25);
$c = $Alpha[$a];
$d = $Alpha[$b];
$e = rand(10000,99999);
$f = rand(100,999);
$ID = $c.$e.$d.$f;
This produces a random ID alpha/numeric...
What I'm wanting to do is have it solely numeric and sequential...for example starting from 100 and leading up to 1000 in increments of 1...
I can find all kinds of information about producing random numbers...which I've done successfully by accident and on purpose...
It would seem that something like this would work...but it doesn't...
$a = 100; $a++
$ID = $a;
This only seems to return the ID 101 over and over...it doesn't not increase in increments of 1 with each form submission...I would like the number to be unique and non-repeptitive...
Does anyone know how this can be done?...I am at my wits end...
Any help, advice or a point in the right direction will be extremely helpful...
Here's a copy of the flat file funtion of the scripts:
if ($Action == "F" or $Action == "EF" or $Action == "DF"){
while (list ($key, $val) = each ($_FILE))
{
if ($key != "Settings" and $key != "Refresh")
{
$val = stripslashes($val);
$val = str_replace('"','"',$val);
$val = strip_tags($val);
$key = ucfirst($key);
$key = str_replace("_"," ",$key);
$FileData .= "$key: $val\r\n";
}
}
$FileData .= "Received: " . $Time . "\r\nIP: " . $IPAddress . "\r\n" . $FileData . "\r\n========================================\r\n\r\n";
$handle = @fopen($FlatFile,'a');
@flock($handle,LOCK_EX);
@fwrite($handle,$FileData);
@flock($handle,LOCK_UN);
@fclose($handle);
} // END OF ACTION
There is also a second settings.php file for easy manipulation, although not so easy for me. This is what I've done with that portion.
# FLAT-FILE SETTING
$FlatFile = "/mmex/ID.txt"
Also, I CHMOD to 666 for this file.
I am using this script as a form processor. I am attempting to generate a unique Order ID for each form submission. The form is sent in HTML to a specified email address with the Subject line being: Web Order - 1000. A second form submission would be sent to the same email address, although this time the subject line would be: Web Order - 1001. And so on.
I don't need to do anything with the number sequence, other than be certain that the numbers do not duplicate.
These will be in my inbox and I would access these form submissions from there.
>>>>> I have had marginal success with a flatfile. I have the information being sent to the file, although nothing yet on how to get the code to read that last number it generated and forcing it to generate the next incremental number.
I almost there, please help me get over this hump.
I apologize for my ignorance and appreciate your help.
This is what I'm trying to accomplish...
$Alpha = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
$a = rand(0,25);
$b = rand(0,25);
$c = $Alpha[$a];
$d = $Alpha[$b];
$e = rand(10000,99999);
$f = rand(100,999);
$ID = $c.$e.$d.$f;
This produces a random ID alpha/numeric...
What I'm wanting to do is have it solely numeric and sequential...for example starting from 100 and leading up to 1000 in increments of 1...
I can find all kinds of information about producing random numbers...which I've done successfully by accident and on purpose...
It would seem that something like this would work...but it doesn't...
$a = 100; $a++
$ID = $a;
This only seems to return the ID 101 over and over...it doesn't not increase in increments of 1 with each form submission...I would like the number to be unique and non-repeptitive...
Does anyone know how this can be done?...I am at my wits end...
Any help, advice or a point in the right direction will be extremely helpful...
Here's a copy of the flat file funtion of the scripts:
if ($Action == "F" or $Action == "EF" or $Action == "DF"){
while (list ($key, $val) = each ($_FILE))
{
if ($key != "Settings" and $key != "Refresh")
{
$val = stripslashes($val);
$val = str_replace('"','"',$val);
$val = strip_tags($val);
$key = ucfirst($key);
$key = str_replace("_"," ",$key);
$FileData .= "$key: $val\r\n";
}
}
$FileData .= "Received: " . $Time . "\r\nIP: " . $IPAddress . "\r\n" . $FileData . "\r\n========================================\r\n\r\n";
$handle = @fopen($FlatFile,'a');
@flock($handle,LOCK_EX);
@fwrite($handle,$FileData);
@flock($handle,LOCK_UN);
@fclose($handle);
} // END OF ACTION
There is also a second settings.php file for easy manipulation, although not so easy for me. This is what I've done with that portion.
# FLAT-FILE SETTING
$FlatFile = "/mmex/ID.txt"
Also, I CHMOD to 666 for this file.
I am using this script as a form processor. I am attempting to generate a unique Order ID for each form submission. The form is sent in HTML to a specified email address with the Subject line being: Web Order - 1000. A second form submission would be sent to the same email address, although this time the subject line would be: Web Order - 1001. And so on.
I don't need to do anything with the number sequence, other than be certain that the numbers do not duplicate.
These will be in my inbox and I would access these form submissions from there.
>>>>> I have had marginal success with a flatfile. I have the information being sent to the file, although nothing yet on how to get the code to read that last number it generated and forcing it to generate the next incremental number.
I almost there, please help me get over this hump.
I apologize for my ignorance and appreciate your help.
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
what happened with using a database? haven't tried it yet, I assume..
file_get_contents() can read in an entire file as a single string.. If you store your last number in the file, it can be incremented.. however, concurrency can still be an issue.
I would still suggest using a database, as flatfiles and file handling in general are a lot more complicated in the end, especially when concurrancy can occur.
file_get_contents() can read in an entire file as a single string.. If you store your last number in the file, it can be incremented.. however, concurrency can still be an issue.
I would still suggest using a database, as flatfiles and file handling in general are a lot more complicated in the end, especially when concurrancy can occur.
-
skydivelouie
- Forum Newbie
- Posts: 23
- Joined: Tue Jan 18, 2005 7:07 pm
I tried connecting to a mysql database without success. Nothing happened. I began to receive errors in the code and the form wouldn't process. Errors were appearing where no change had been made.
Although, with the flatfile, I did get some results. The script posted the information. More information than is necessary.
I simply need the script to post the sequential number it just generated, ie 1000, and then at the next form submission, have the script refer to the /ID.txt file, read the last number it posted (1000), and submit the next incremental number which would be 1001.
Etc. etc. 1002,1003,1004. At this point concurrency is not an issue. It may be down the line, at which point I can deal with it as I am now. I simply need the processing asap.
Please help.
Although, with the flatfile, I did get some results. The script posted the information. More information than is necessary.
I simply need the script to post the sequential number it just generated, ie 1000, and then at the next form submission, have the script refer to the /ID.txt file, read the last number it posted (1000), and submit the next incremental number which would be 1001.
Etc. etc. 1002,1003,1004. At this point concurrency is not an issue. It may be down the line, at which point I can deal with it as I am now. I simply need the processing asap.
Please help.
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
all right.. here's the basic code:note that this should be done after the form has been processed and validated, so you aren't wasting numbers away.
Code: Select all
$seqfile = 'ID.txt';
if(!file_exists($seqfile))
$num = 100;
else
$num = intval(file_get_contents($seqfile)) + 1;
$fp = fopen($seqfile, 'w');
fwrite($fp, $num);
fclose($fp);
// send the form's data-
skydivelouie
- Forum Newbie
- Posts: 23
- Joined: Tue Jan 18, 2005 7:07 pm
-
skydivelouie
- Forum Newbie
- Posts: 23
- Joined: Tue Jan 18, 2005 7:07 pm
Alright...there is definite movement...
the /ID.txt file is making the incremental changes I'm looking for...
Although...in the form submission subject line in my email is staying the same...I don't understand why...
This is making the necessary changes in the flatfile...
if ($Action == "F" or $Action == "EF" or $Action == "DF"){
$seqfile = 'ID.txt';
if(!file_exists($seqfile))
$num = 100;
else
$num = intval(file_get_contents($seqfile)) + 1;
$fp = fopen($seqfile, 'w');
fwrite($fp, $num);
fclose($fp);
// send the form's data
$handle = @fopen($FlatFile,'a');
@flock($handle,LOCK_EX);
@fwrite($handle,$FileData);
@flock($handle,LOCK_UN);
@fclose($handle);
} // END OF ACTION
You're a genius...
Although this...I believe...is still the sticking point...
$a = 10000; $a++;
$ID = $a;
I am getting the incremental increase in the flatfile...although...it's not translating to the form submission subject line in my email...
Do I need to delete this althogether...if so...how would I designate what the $ID would be...and have it coincide with the flatfile incremental changes...
the /ID.txt file is making the incremental changes I'm looking for...
Although...in the form submission subject line in my email is staying the same...I don't understand why...
This is making the necessary changes in the flatfile...
if ($Action == "F" or $Action == "EF" or $Action == "DF"){
$seqfile = 'ID.txt';
if(!file_exists($seqfile))
$num = 100;
else
$num = intval(file_get_contents($seqfile)) + 1;
$fp = fopen($seqfile, 'w');
fwrite($fp, $num);
fclose($fp);
// send the form's data
$handle = @fopen($FlatFile,'a');
@flock($handle,LOCK_EX);
@fwrite($handle,$FileData);
@flock($handle,LOCK_UN);
@fclose($handle);
} // END OF ACTION
You're a genius...
Although this...I believe...is still the sticking point...
$a = 10000; $a++;
$ID = $a;
I am getting the incremental increase in the flatfile...although...it's not translating to the form submission subject line in my email...
Do I need to delete this althogether...if so...how would I designate what the $ID would be...and have it coincide with the flatfile incremental changes...
-
skydivelouie
- Forum Newbie
- Posts: 23
- Joined: Tue Jan 18, 2005 7:07 pm
-
skydivelouie
- Forum Newbie
- Posts: 23
- Joined: Tue Jan 18, 2005 7:07 pm
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
sure, just make sure to put it in some
Code: Select all
tags, so it's easier to read.. [size=84]sorta[/size]-
skydivelouie
- Forum Newbie
- Posts: 23
- Joined: Tue Jan 18, 2005 7:07 pm
Here it is:
It's the form submission script MMEX...
I've attempted to make the changes I need...with limited success...
I appreciate this...
feyd v1 | We said put it in
Code: Select all
<?
#################################################################################
# #
# Mail Manage EX, v3.2 #
# Written by Gregg Kenneth Jewell, Copyright © 2003-2004 #
# #
# All settings can be controlled from the settings file. #
# For all features and instructions refer to the readme file #
# #
# Although security features are implemented in this script, that #
# does not guarantee these features will provide 100% security protection. #
# Use at your own risk. Do not use this script to send sensitive #
# data such as credit card information, social security numbers, etc. #
# #
# #
#################################################################################
#################################################################################
# EDIT AT YOUR OWN RISK #
#################################################################################
#===========================================================
# Register Globals
#===========================================================
$Refresh = $_REQUESTї'Refresh'];
$EMAILї0] = $_REQUESTї'email'];
$EMAILї1] = $_REQUESTї'Email'];
$EMAILї2] = $_REQUESTї'E_mail'];
$EMAILї3] = $_REQUESTї'e_mail'];
$EMAILї4] = $_REQUESTї'email_address'];
$EMAILї5] = $_REQUESTї'Email_Address'];
$EMAILї6] = $_REQUESTї'Email_address'];
#===========================================================
# CHECK SETTINGS & FORM RECIPIENT
#===========================================================
/* Enter the filename of the settings below. Refer to the readme for more instructions. */
require('settings.php');
/*if ($FormRecipient) $Recipient = $FormRecipient;*/
#===========================================================
# RETRIEVE ENVIRONMENTAL VARIABLES
#===========================================================
header("Cache-control: public");
$IPAddress = $_SERVERї'REMOTE_ADDR'];
$MkTime = mktime();
$Time = date('M j, Y @ g:i:s a',mktime(date('H')+$TimeZone));
$Browser = $_SERVERї'HTTP_USER_AGENT'];
#===========================================================
# STYLE AND HTML HEADER/FOOTER
#===========================================================
if (!$FontFamily)
$FontFamily = 'arial'; // Default
if (!$FontSize)
$FontSize = '10pt'; // Default
if (!$FontColor)
$FontColor = '#000000'; // Default
if ($BorderColor and $BgColor)
{
$msgї'style'] = '<div style="margin-left:24px;padding:10,10,10,10;border:solid '.$BorderColor.' 1px;background-color:'.$BgColor.';font-family:'.$FontFamily.';font-size:'.$FontSize.';color:'.$FontColor.';">';
$msgї'tplstyle'] = '<div style="padding:10,10,10,10;border:solid '.$BorderColor.' 1px;background-color:'.$BgColor.';font-family:'.$FontFamily.';font-size:'.$FontSize.';color:'.$FontColor.';">';
}
else
{
$msgї'style'] = '<div style="margin-left:24px;font-family:'.$FontFamily.';font-size:'.$FontSize.';color:'.$FontColor.';">';
$msgї'tplstyle'] = '<div style="font-family:'.$FontFamily.';font-size:'.$FontSize.';color:'.$FontColor.';">';
}
if ($MessageTemplate and file_exists($MessageTemplate))
{
$handle = @fopen($MessageTemplate,'r');
$MsgTPL = @fread($handle,filesize($MessageTemplate));
@fclose($handle);
$MsgTPL = explode("їMMEX]",$MsgTPL);
$msgї'header'] = $MsgTPLї0].$msgї'tplstyle'];
$msgї'footer'] = "</div>" . $MsgTPLї1];
}
else
{
$msgї'header'] = $msgї'style'];
$msgї'footer'] = "</div><br><br>";
}
#===========================================================
# ERROR MESSAGES
#===========================================================
$msgї'banned'] = "<b>Your IP address has been blocked.</b>";
$msgї'nosubmit'] = "<b>Your submission could not be sent. No action has been selected.</b>";
$msgї'recent'] = "<b>Recent entry. New submissions are allowed every $Interval minute(s).</b>";
$msgї'norecipient'] = "<b>This email cannot be sent. No specified recipient.</b>";
$msgї'required'] = "<b>The following field(s) are required to be filled in before submission:</b>";
$msgї'confirmed'] = "<b>The following fields must be the same before submission:</b>";
$msgї'formatted'] = "<b>The following field(s) are required to be filled in with valid format before submission:</b>";
#===========================================================
# CHECK FLOOD CONTROL (PRE-SUBMISSION)
#===========================================================
if ($FloodControl == "1" and file_exists('data/flood.log'))
{
$Seconds = $Interval * 60;
$handle = @fopen('data/flood.log','r');
@flock($handle, LOCK_SH);
$LogData = @fread($handle,filesize('flood.dat'));
$LogData = explode("#",$LogData);
for ($x=0;$x<count($LogData);$x++)
{
$line = explode("|",$LogDataї$x]);
if ($IPAddress == $lineї0])
{
if (($MkTime - $lineї1]) < $Seconds)
exit ($msgї'header'] . $msgї'recent'] . $msgї'footer']);
}
}
@flock($handle,LOCK_UN);
@fclose($handle);
}
#===========================================================
# SAVE INFORMATION TO STATS LOG
#===========================================================
if ($UseStats == "1")
{
$StatInfo = "$FormName|$MkTime|$Time|$IPAddress";
$handle = @fopen('data/stats.log','a');
@flock($handle,LOCK_EX);
@fwrite($handle,$StatInfo."\n");
@flock($handle,LOCK_UN);
@fclose($handle);
}
#===========================================================
# BANNED IP ADDRESSES
#===========================================================
if(stristr($Banned,$IPAddress))
exit ($msgї'header'] . $msgї'banned'] . $msgї'footer']);
#===========================================================
# ADJUST A FEW VARIABLES
#===========================================================
$ID = $num;
for ($x=0;$x<count($EMAIL);$x++){
if ($EMAILї$x]) $SendFrom = $EMAILї$x];}
if (!$SendFrom)
$SendFrom = $Recipient;
$_EMAIL = $_POST;
$_HTML = $_POST;
$_SQL = $_POST;
$_CSV = $_POST;
$_FILE = $_POST;
$_AUTO = $_POST;
$AttachmentField = explode(",",$AttachmentFields);
$x=0;
foreach ($AttachmentField as $ThisAttachment)
{
$ATTACHї$x]ї0] = $_FILESї$ThisAttachment]ї'name'];
$ATTACHї$x]ї1] = $_FILESї$ThisAttachment]ї'tmp_name'];
$x++;
}
if ($SMTPServer)
{
ini_set('SMTP',$SMTPServer);
ini_set('sendfrom_mail',$Recipient);
}
#===========================================================
# CHECK REQUIRED FIELDS
#===========================================================
if ($Require)
{
$Required = explode(",",$Require);
for($i=0;$i<count($Required);$i++)
{
$Field = $Requiredї$i];
if(!$_POSTї$Field])
{
$Field = str_replace("_"," ",$Field);
$Field = ucfirst($Field);
$EmptyFields .= "<li>$Field</li>";
if ($Preview == "1")
$RedFields .= "$Field,";
}
}
if ($EmptyFields)
$Errors = $msgї'required'] . "<ul type="square">" . $EmptyFields . "</ul><br>";
}
#===========================================================
# CHECK FIELDS FOR CONFIRMATION
#===========================================================
if ($Confirm)
{
$Confirmed = explode(",",$Confirm);
for($i=0;$i<count($Confirmed);$i+=2)
{
$Field1 = $Confirmedї$i];
$Field2 = $Confirmedї$i+1];
$FieldA = $_POSTї$Field1];
$FieldB = $_POSTї$Field2];
if ($FieldA != $FieldB)
{
$Field1 = str_replace("_"," ",$Field1);
$Field1 = ucfirst($Field1);
$Field2 = str_replace("_"," ",$Field2);
$Field2 = ucfirst($Field2);
$WrongFields .= "<li><b>$Field1</b> does not match <b>$Field2</b></li>";
if ($Preview == "1")
$RedFields .= "$Field1,$Field2,";
}
}
if ($WrongFields and !$Errors)
$Errors = $msgї'confirmed'] . "<ul type="square">" . $WrongFields . "</ul><br>";
else if ($WrongFields and $Errors)
$Errors .= "<br>" . $msgї'confirmed'] . "<ul type="square">" . $WrongFields . "</ul><br>";
}
#===========================================================
# CHECK FORMATTED FIELDS
#===========================================================
if ($Format)
{
$Formatted = explode(",",$Format);
for ($x=0;$x<count($Formatted);$x++)
{
$Format = substr($Formattedї$x],-1);
$Field = substr($Formattedї$x],0,-1);
if ($Format == "<") // MINIMUM CHAR FORMAT
{
$Length = substr($Field,-2);
$Field = substr($Field,0,-2);
if (substr($Length,0,1) == "0")
$Length = substr($Length,-1);
if ($_POSTї$Field])
{
if(strlen($_POSTї$Field]) < $Length)
{
$Field = str_replace("_"," ",$Field);
$Field = ucfirst($Field);
$IncorrectFields .= "<li><b>$Field</b> requires a minimum of $Length Characters.</li>";
if ($Preview == "1")
$RedFields .= "$Field,";
}
}
}
if ($Format == ">") // MAXIMUM CHAR FORMAT
{
$Length = substr($Field,-2);
$Field = substr($Field,0,-2);
if (substr($Length,0,1) == "0")
$Length = substr($Length,-1);
if ($_POSTї$Field])
{
if(strlen($_POSTї$Field]) > $Length)
{
$Field = str_replace("_"," ",$Field);
$Field = ucfirst($Field);
$IncorrectFields .= "<li><b>$Field</b> exceeds the maximum of $Length Characters.</li>";
if ($Preview == "1")
$RedFields .= "$Field,";
}
}
}
if ($Format == "@" and $_POSTї$Field]) // EMAIL FORMAT
{
if(!eregi('^(ї_a-z0-9-]+)(\.ї_a-z0-9-]+)*@(їa-z0-9-]+)(\.їa-z0-9-]+)*(\.їa-z]{2,4})$',$_POSTї$Field]))
{
$Field = str_replace("_"," ",$Field);
$Field = ucfirst($Field);
$IncorrectFields .= "<li><b>$Field</b> requires the proper email format.</li>";
if ($Preview == "1")
$Redfields .= "$Field,";
}
$Host = explode("@",$_POSTї$Field]);
if (!checkdnsrr($Hostї1].'.', 'MX'))
{
$Field = str_replace("_"," ",$Field);
$Field = ucfirst($Field);
$IncorrectFields .= "<li><b>$Field</b> requires an existing domain name in the email format.</li>";
if ($Preview == "1")
$Redfields .= "$Field,";
}
}
if ($Format == "#" and $_POSTї$Field]) // PHONE NUMBER FORMAT
{
if (!eregi('(ї0-9]{3})-(ї0-9]{3})-(ї0-9]{4})', $_POSTї$Field]) and !eregi('(ї0-9]{3})\.(ї0-9]{3})\.(ї0-9]{4})', $_POSTї$Field]) and !eregi('(ї0-9]{3}) (ї0-9]{3}) (ї0-9]{4})', $_POSTї$Field]) and !eregi('(\(ї0-9]{3}\))-(ї0-9]{3})-(ї0-9]{4})', $_POSTї$Field]) and !eregi('(\(ї0-9]{3}\))\.(ї0-9]{3})\.(ї0-9]{4})', $_POSTї$Field]) and !eregi('(\(ї0-9]{3}\)) (ї0-9]{3}) (ї0-9]{4})', $_POSTї$Field]) and !eregi('(\(ї0-9]{3}\)) (ї0-9]{3})-(ї0-9]{4})', $_POSTї$Field]) and !eregi('(\(ї0-9]{3}\)) (ї0-9]{3})\.(ї0-9]{4})', $_POSTї$Field]))
{
$Field = str_replace("_"," ",$Field);
$Field = ucfirst($Field);
$IncorrectFields .= "<li><b>$Field</b> requires the proper phone format.</li>";
if ($Preview == "1")
$RedFields .= "$Field,";
}
}
if ($Format == "Z" and $_POSTї$Field]) // ZIP CODE FORMAT
{
if (!eregi('(ї0-9]{5})', $_POSTї$Field]))
{
$Field = str_replace("_"," ",$Field);
$Field = ucfirst($Field);
$IncorrectFields .= "<li><b>$Field</b> requires the proper zip code format.</li>";
if ($Preview == "1")
$RedFields .= "$Field,";
}
}
if ($Format == "S" and $_POSTї$Field]) // STATE FORMAT
{
if (!eregi('(їa-zA-Z]{2})', $_POSTї$Field]))
{
$Field = str_replace("_"," ",$Field);
$Field = ucfirst($Field);
$IncorrectFields .= "<li><b>$Field</b> requires the proper state format.</li>";
if ($Preview == "1")
$RedFields .= "$Field,";
}
}
if ($Format == "N" and $_POSTї$Field] > "") // NUMERIC ONLY FORMAT
{
if (eregi('(їa-zA-Z_\-])', $_POSTї$Field]))
{
$Field = str_replace("_"," ",$Field);
$Field = ucfirst($Field);
$IncorrectFields .= "<li><b>$Field</b> requires numeric-only characters.</li>";
if ($Preview == "1")
$RedFields .= "$Field,";
}
}
if ($Format == "A" and $_POSTї$Field]) // ALPHA ONLY FORMAT
{
if (eregi('(ї0-9])', $_POSTї$Field]))
{
$Field = str_replace("_"," ",$Field);
$Field = ucfirst($Field);
$IncorrectFields .= "<li><b>$Field</b> requires aplha-only characters.</li>";
if ($Preview == "1")
$RedFields .= "$Field,";
}
}
}
if ($IncorrectFields and !$Errors)
$Errors = $msgї'formatted'] . "<ul type="square">" . $IncorrectFields . "</ul><br>";
else if ($IncorrectFields and $Errors)
$Errors .= "<br>" . $msgї'formatted'] . "<ul type="square">" . $IncorrectFields . "</ul><br>";
}
#=======================================
# CHECK ATTACHMENT EXTENSION
#=======================================
if ($AllowedExt and ($ATTACHї0]ї0] or $ATTACHї1]ї0] or $ATTACHї2]ї0]))
{
for ($x=0;$x<count($ATTACH);$x++)
{
$MaxSize = $MaxFileSize * 1000;
if (filesize($ATTACHї$x]ї1]) > $MaxSize)
{
$Errors .= "<br><b><i>".$ATTACHї$x]ї0]."</i> has exceeded the allowed file size of $MaxFileSize KB.</b><br>";
}
$i = strrpos($ATTACHї$x]ї0],".");
$l = strlen($ATTACHї$x]ї0]) - $i;
$Ext = substr($ATTACHї$x]ї0],$i+1,$l);
$Ext = strtolower($Ext);
if ($Ext)
{
if (!strstr($AllowedExt,$Ext))
{
$Errors .= "<br><b><i>.$Ext</i> is an invalid extension. The following extensions are allowed:</b><ul type="square">";
$Allowed = explode(",",$AllowedExt);
for($x=0;$x<count($Allowed);$x++)
{
$Errors .= "<li>.".$Allowedї$x]."</li>";
}
$Errors .= "</ul><br>";
}
}
}
}
#===========================================================
# PREVIEW
#===========================================================
if ($Preview == "1" and !$Refresh)
{
$HTMLї'preview'] .= "
<b><u>Submission Preview</u></b><br><br>
<form method="post" action="".$PHP_SELF."">
<input type="hidden" name="Refresh" value="Y">
<input type="hidden" name="Settings" value="".$Settings."">
<table style="font-family:$FontFamily;font-size:$FontSize;" cellspacing=1 cellpadding=2>
";
$RedFields = explode(",",$RedFields);
$flag = 0;
while (list ($key, $val) = each ($_POST))
{
if ($key != "Settings" and $key != "Refresh")
{
$val = stripslashes($val);
$val = str_replace('"','"',$val);
$HTMLї'form'] .= "<input type="hidden" name="".$key."" value="".$val."">";
$key = ucfirst($key);
$key = str_replace("_"," ",$key);
for ($x=0;$x<count($RedFields)-1;$x++)
{
if ($key == $RedFieldsї$x])
{
$HTMLї'form'] .= "<tr><td style="color:red"><b>$key</b>:</td><td>$val</td></tr>";
$Flag = 1;
}
}
if ($Flag != 1)
$HTMLї'form'] .= "<tr><td><b>$key</b>:</td><td>$val</td></tr>";
$Flag = 0;
}
}
$HTMLї'form'] .= "<tr><td height=16 colspan=2></td></tr>";
if (!$Errors)
$HTMLї'form'] .= "<tr><td><input type="submit" value="Submit" style="font-family:$font_family;font-size:$font_size;border: solid #AAAAAA 1px; cursor:hand"></td></tr>";
$HTMLї'form'] .= "</form></table>";
}
if ($Errors and $Preview != "1")
exit ($msgї'header'].$Errors.$msgї'footer']);
else if ($Errors and $Preview == "1" and !$Refresh)
exit ($msgї'header'].$Errors."<br>".$HTMLї'preview'].$HTMLї'form'].$msgї'footer']);
else if ($Preview == "1" and !$Refresh)
exit ($msgї'header'].$HTMLї'preview'].$HTMLї'form'].$msgї'footer']);
#===========================================================
# CHOOSE ACTION
#===========================================================
if (!$Action)
exit($msgї'header'] . $msgї'nosubmit'] . $msgї'footer']);
#########################################################################
# EMAIL FUNCTIONS #
#########################################################################
if ($Action == "E" or $Action == "EC" or $Action == "ED" or $Action == "EF"){
while (list ($key, $val) = each ($_EMAIL))
{
if ($key != "Settings" and $key != "Refresh")
{
$val = stripslashes($val);
$val = str_replace('"','"',$val);
$val = strip_tags($val);
$key = ucfirst($key);
$key = str_replace("_"," ",$key);
$EMAILї'text'] .= "$key: $val\r\n";
$val = nl2br($val);
$EMAILї'form'] .= "<b>$key</b>: $val<br>";
$EMAILї'html'] .= "<tr><td width=120 valign=top><font size="2" face="Verdana, Arial, Helvetica, sans-serif">$key</font></td><td width=380 valign=top><font size="2" face="Verdana, Arial, Helvetica, sans-serif">$val</font></td></tr>";
}
}
if (!$Recipient)
exit ($msgї'header'] . $msgї'norecipient'] . $msgї'footer']);
if (!$Subject)
$Subject = "Web Order - $ID";
#===========================================================
# Email Templates
#===========================================================
$EMAILї'textemail'] = "
***Form Results***\r\n
".$EMAILї'text']."
User's Browser: $Browser\r\n
User's IP Address: $IPAddress\r\n\r\n
- Mail Manage EX Notifier -
";
if ($EmailTemplate)
{
$handle = @fopen($EmailTemplate,'r');
$EMAILї'htmlemail'] = @fread($handle,filesize($EmailTemplate));
@fclose($handle);
if (!strstr($EMAILї'htmlemail'],'їALL]'))
{
while(list($key,$val) = each($_HTML))
{
$insert = "ї".$key."]";
$val = stripslashes($val);
$val = strip_tags($val);
$val = nl2br($val);
$EMAILї'htmlemail'] = str_replace($insert,$val,$EMAILї'htmlemail']);
}
}
else
$EMAILї'htmlemail'] = str_replace('їALL]',$EMAILї'form'],$EMAILї'htmlemail']);
$EMAILї'htmlemail'] = str_replace("їReceived]",$Time,$EMAILї'htmlemail']);
$EMAILї'htmlemail'] = str_replace("їIPAddress]",$IPAddress,$EMAILї'htmlemail']);
$EMAILї'htmlemail'] = str_replace("їBrowser]",$Browser,$EMAILї'htmlemail']);
$EMAILї'htmlemail'] = str_replace("їID]",$ID,$EMAILї'htmlemail']);
$EMAILї'htmlemail'] = str_replace("їAttach1]",$ATTACHї0]ї0],$EMAILї'htmlemail']);
$EMAILї'htmlemail'] = str_replace("їAttach2]",$ATTACHї1]ї0],$EMAILї'htmlemail']);
$EMAILї'htmlemail'] = str_replace("їAttach3]",$ATTACHї2]ї0],$EMAILї'htmlemail']);
}
else
{
$EMAILї'htmlemail'] = '
<html>
<head></head>
<xbody>
<table border="0" cellspacing="0" cellpadding="0" width="600">
<tr>
<font color="#30A11E" size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Submission: '.$ID.'</strong></font></td>
</tr>
</table>
<table bgcolor="#F1F1F1" border="0" cellspacing="0" cellpadding="5" width="600">
<tr>
<td align="left" valign="middle">
<strong><font color="#202020" size="1" face="Verdana, Arial, Helvetica, sans-serif">THANK YOU FOR CHOOSING CARTWRIGHT SIGNS - SEEING OUR BUSINESS THROUGH YOUR EYES</font></strong></td>
</tr>
</table><br>
<table bgcolor="#F9F9F9" border="0" cellspacing="0" cellpadding="5" width="600">
<tr>
<td width="380" align="center" valign="middle">
<img src="#" width="250" height="1" border="0"></td>
<td width="220" align="left" valign="top">
<font color="#000000" size="2" face="Verdana, Arial, Helvetica, sans-serif">
<br>
<strong>'.$Time.'<br>
<font color="#30A11E">IP: '.$IPAddress.'</font></font></strong><br>
<font color="#000000" size="1" face="Verdana, Arial, Helvetica, sans-serif">'.$Browser.'</font></td>
</tr>
</table>
<table bgcolor="#F9F9F9" border="0" cellspacing="0" cellpadding="5" width="600">
<tr>
<td>
<font color="#000000" size="2" face="Verdana, Arial, Helvetica, sans-serif">
***Form Results***<br><br>
<table bgcolor="#F9F9F9" border="0" cellspacing="1" cellpadding="0" width="500">
'.$EMAILї'html'].'
</table><br><br>
</table><br>
<table bgcolor="#F1F1F1" border="0" cellspacing="0" cellpadding="5" width="600">
<tr>
<td align="left" valign="middle">
<strong><font color="#202020" size="1" face="Verdana, Arial, Helvetica, sans-serif">Copyright © 2001-2004 - HeadStart Web Designs.
</font></strong></td>
</tr>
</table>
</xbody>
</html>';
}
#===========================================================
# Put Header Information in Email
#===========================================================
$rand = md5(time());
$MimeBoundary = "MMEX". $rand;
$Headers = "From: $SendFrom\n";
$Headers .= "Reply-to: $SendFrom\n";
$Headers .= "Return-Path: $SendFrom\n";
if ($CC)
$Headers .= "cc: $CC\n";
$Headers .= "X-Mailer: My PHP Mailer\n";
$Headers .= "MIME-Version: 1.0\n";
if ($AttachmentFields and ($ATTACHї0]ї0] or $ATTACHї1]ї0] or $ATTACHї2]ї0]))
$Headers .= "Content-Type: multipart/mixed; charset="iso-8859-1"; boundary="$MimeBoundary";\n\n";
else
$Headers .= "Content-Type: multipart/alternative; charset="iso-8859-1"; boundary="$MimeBoundary";\n\n";
$Headers .= "This is a multi-part message in MIME format.\n\n";
if ($TextEmails == "1")
{
$Content .= "--$MimeBoundary\n";
$Content .= "Content-Type: text/plain; charset="iso-8859-1"\n";
$Content .= "Content-Transfer-Encoding: 8bit\n\n";
$Content .= $EMAILї'textemail']."\n\n";
}
if ($HtmlEmails == "1")
{
$Content .= "--$MimeBoundary\n";
$Content .= "Content-Type: text/html; charset="iso-8859-1"\n";
$Content .= "Content-Transfer-Encoding: 8bit\n\n";
$Content .= $EMAILї'htmlemail']."\n\n";
}
if ($AttachmentFields)
{
for ($x=0;$x<count($ATTACH);$x++)
{
$TmpFile = "data/".$ATTACHї$x]ї0];
@copy($ATTACHї$x]ї1],"$TmpFile");
$fa = @fopen ($TmpFile,'r');
$FileContent = @fread($fa,filesize($TmpFile));
@fclose($fa);
$FileContent = chunk_split(base64_encode($FileContent));
$Content .= "--$MimeBoundary\n";
$Content .= "Content-Type: application/octetstream;\n name="".$ATTACHї$x]ї0].""\n";
$Content .= "Content-Transfer-Encoding: base64\n";
$Content .= "Content-Disposition: attachment;\n filename="".$ATTACHї$x]ї0].""\n\n";
$Content .= $FileContent."\n";
@unlink($TmpFile);
}
}
$Content .= "--$MimeBoundary--\n\n\n";
#===========================================================
# Send It Off
#===========================================================
mail($Recipient, $Subject, $Content, $Headers);
} // END OF ACTION
#########################################################################
# CSV-FILE FUNCTIONS #
#########################################################################
if ($Action == "C" or $Action == "EC" or $Action == "CD"){
$Time = date('M j Y @ g:i:s a',mktime(date('H')+$TimeZone));
while (list ($key, $val) = each ($_CSV))
{
if ($key != "Settings" and $key != "Refresh")
{
$val = stripslashes($val);
$val = str_replace('"','"',$val);
$val = strip_tags($val);
$val = str_replace(",","¸",$val);
$val = str_replace("\r\n"," ",$val);
$val = str_replace("\n"," ",$val);
$CSVData .= "$val,";
}
}
$CSVData .= "$Time,$IPAddress,$Browser";
$handle = @fopen($CSVFile,'a');
@flock($handle,LOCK_EX);
@fwrite($handle,$CSVData."\n");
@flock($handle,LOCK_UN);
@fclose($handle);
} // END OF ACTION
#########################################################################
# FLAT-FILE FUNCTIONS #
#########################################################################
if ($Action == "F" or $Action == "EF" or $Action == "DF"){
$seqfile = 'ID.txt';
if(!file_exists($seqfile))
$num = 100;
else
$num = intval(file_get_contents($seqfile)) + 1;
$fp = fopen($seqfile, 'w');
fwrite($fp, $num);
fclose($fp);
// send the form's data
$handle = @fopen($FlatFile,'a');
@flock($handle,LOCK_EX);
@fwrite($handle,$FileData);
@flock($handle,LOCK_UN);
@fclose($handle);
} // END OF ACTION
#########################################################################
# DATABASE FUNCTIONS #
#########################################################################
if ($Action == "D" or $Action == "ED" or $Action == "CD" or $Action == "DF"){
$Connect = @mysql_connect("localhost", "$SQL_UserName", "$SQL_Password");
@mysql_select_db("$SQL_Database",$Connect);
while (list ($key, $val) = each ($_SQL))
{
if ($key != "Settings" and $key != "Refresh")
{
$val = stripslashes($val);
$val = str_replace('"','"',$val);
$val = strip_tags($val);
$Columns .= $key . ',';
$Values .= "'" . $val . "',";
}
}
if ($SQL_ENV == "1")
{
$Columns .= "Received,IPAddress,Browser";
$Values .= "'" . $Time . "','" . $IPAddress ."','" . $Browser . "'";
}
else
{
$Columns = substr($Columns,0,-1);
$Values = substr($Values,0,-1);
}
@mysql_query("INSERT INTO $SQL_Table ($Columns) VALUES ($Values)");
@mysql_close($Connect);
} // END OF ACTION
#########################################################################
# POST SUBMIT FUNCTIONS #
#########################################################################
#===========================================================
# SAVE FLOOD CONTROL DATA (POST-SUBMISSION)
#===========================================================
if ($FloodControl == "1")
{
$LogData = $IPAddress . "|" . $MkTime . "#";
$handle = @fopen('data/flood.log','a');
@flock($handle,LOCK_EX);
@fwrite($handle,$LogData);
@flock($handle,LOCK_UN);
@fclose($handle);
}
#===========================================================
# Auto Respond Information
#===========================================================
if ($AutoRespond == "1")
{
if (!$AutoSubject)
$AutoSubject = 'Thank you for your submission';
if ($AutoTemplate and file_exists($AutoTemplate))
{
$handle = @fopen($AutoTemplate,'r');
$AutoContent = @fread($handle,filesize($AutoTemplate));
@fclose($handle);
while(list($key,$val) = each($_AUTO))
{
$insert = "ї".$key."]";
$val = stripslashes($val);
$val = strip_tags($val);
$val = nl2br($val);
$AutoContent = str_replace($insert,$val,$AutoContent);
$AutoContent = str_replace("їReceived]",$Time,$AutoContent);
$AutoContent = str_replace("їID]",$ID,$AutoContent);
$AutoContent = str_replace("їAttach1]",$ATTACHї0]ї0],$AutoContent);
$AutoContent = str_replace("їAttach2]",$ATTACHї1]ї0],$AutoContent);
$AutoContent = str_replace("їAttach3]",$ATTACHї2]ї0],$AutoContent);
}
}
if (!$AutoContent)
$AutoContent = "Cartwright Signs has received your order. Your Submission ID is : їID]$ID";
if ($AutoFromName)
$AutoHeaders = "From: "$AutoFromName" <$Recipient>\n";
else
$AutoHeaders = "From: $Recipient\n";
$AutoHeaders .= "MIME-Version: 1.0\nContent-Type: text/html; charset=ISO-8859-1\nContent-Transfer-Encoding: 8bit\n\n";
@mail($SendFrom,$AutoSubject,$AutoContent,$AutoHeaders);
}
#===========================================================
# REDIRECT OR THANK YOU
#===========================================================
if (!$Redirect)
{
if (!$ThankYou)
$ThankYou = 'Thank you for your submission.';
exit ($msgї'header'] . "$ThankYou". $msgї'footer']);
}
else
echo "<html><head><META http-equiv="refresh" content="0;URL=$Redirect"></head><body></body></html>";
?>I've attempted to make the changes I need...with limited success...
I appreciate this...
feyd v1 | We said put it in
Code: Select all
tags! [u]shame![/u][/color]-
skydivelouie
- Forum Newbie
- Posts: 23
- Joined: Tue Jan 18, 2005 7:07 pm
Sorry...don't understand how to implement
Code: Select all
tags...- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
there's a button that says "code" when you are posting.. it'll add some text, where you place your code after it, then click the "code" button again to close the block.
As for $ID not showing anything.. that's correct.. $ID is set much earlier than $num actually is, and so will be null. Sadly, the validation happens after $ID is used by your html output... this script is procedural code, and as such may be difficult to "fix"

As for $ID not showing anything.. that's correct.. $ID is set much earlier than $num actually is, and so will be null. Sadly, the validation happens after $ID is used by your html output... this script is procedural code, and as such may be difficult to "fix"
-
skydivelouie
- Forum Newbie
- Posts: 23
- Joined: Tue Jan 18, 2005 7:07 pm
I see the
Code: Select all
button...will remember that next time...
It seemed that the solution was just around the corner...the flatfile is making the necessary changes...surely these changes are dictated by this script...what would prevent the subject line from producing the same result as the flat file...???...
What in the script is causing this to be difficult to "fix"...surely it is within your abilities...
I appreciate your help thusfar...it has been invaluable...kindly let me know what I'm doing wrong...