random numbers vs sequential numbers

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

skydivelouie
Forum Newbie
Posts: 23
Joined: Tue Jan 18, 2005 7:07 pm

random numbers vs sequential numbers

Post by skydivelouie »

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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

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.
skydivelouie
Forum Newbie
Posts: 23
Joined: Tue Jan 18, 2005 7:07 pm

Post by skydivelouie »

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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

all right.. here's the basic code:

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
note that this should be done after the form has been processed and validated, so you aren't wasting numbers away.
skydivelouie
Forum Newbie
Posts: 23
Joined: Tue Jan 18, 2005 7:07 pm

Post by skydivelouie »

You're the best. I will try applying this and will post again.

Thank you again.
skydivelouie
Forum Newbie
Posts: 23
Joined: Tue Jan 18, 2005 7:07 pm

Post by skydivelouie »

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...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you can lose that stuff... your fopen call does nothing now.. same with $a junk.. use $num to display the ID#
skydivelouie
Forum Newbie
Posts: 23
Joined: Tue Jan 18, 2005 7:07 pm

Post by skydivelouie »

So it should read:

$num = 10000; $num++;
$ID = $num;

Is this correct?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

no.. do not use $num like that at all.. it's already been incremented and processed.. if anything $ID = $num is fine. The rest will throw invalid numbers.
skydivelouie
Forum Newbie
Posts: 23
Joined: Tue Jan 18, 2005 7:07 pm

Post by skydivelouie »

I used this:

$ID = $num;

in place of:

$a = 10000; $a++;
$ID = $a;

and the flatfile did increase...although the email subject line appeared as Web Order - ...no number appeared afterwards...

Would it be possible for me to paste the whole code and have your professional eyes critique it...???...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

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

Post by skydivelouie »

Here it is:

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&#1111;'Refresh'];
$EMAIL&#1111;0] = $_REQUEST&#1111;'email'];
$EMAIL&#1111;1] = $_REQUEST&#1111;'Email'];
$EMAIL&#1111;2] = $_REQUEST&#1111;'E_mail'];
$EMAIL&#1111;3] = $_REQUEST&#1111;'e_mail'];
$EMAIL&#1111;4] = $_REQUEST&#1111;'email_address'];
$EMAIL&#1111;5] = $_REQUEST&#1111;'Email_Address'];
$EMAIL&#1111;6] = $_REQUEST&#1111;'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&#1111;'REMOTE_ADDR'];
$MkTime = mktime();
$Time = date('M j, Y  @ g:i:s a',mktime(date('H')+$TimeZone));
$Browser = $_SERVER&#1111;'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)
&#123;
 $msg&#1111;'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&#1111;'tplstyle'] = '<div style="padding:10,10,10,10;border:solid '.$BorderColor.' 1px;background-color:'.$BgColor.';font-family:'.$FontFamily.';font-size:'.$FontSize.';color:'.$FontColor.';">';
&#125;
else
&#123;
 $msg&#1111;'style'] = '<div style="margin-left:24px;font-family:'.$FontFamily.';font-size:'.$FontSize.';color:'.$FontColor.';">';
 $msg&#1111;'tplstyle'] = '<div style="font-family:'.$FontFamily.';font-size:'.$FontSize.';color:'.$FontColor.';">';
&#125;
if ($MessageTemplate and file_exists($MessageTemplate))
&#123;
  $handle = @fopen($MessageTemplate,'r');
  $MsgTPL = @fread($handle,filesize($MessageTemplate));
  @fclose($handle);
  
  $MsgTPL = explode("&#1111;MMEX]",$MsgTPL);
  $msg&#1111;'header'] = $MsgTPL&#1111;0].$msg&#1111;'tplstyle'];
  $msg&#1111;'footer'] = "</div>" . $MsgTPL&#1111;1];
&#125;
else
&#123;
  $msg&#1111;'header'] = $msg&#1111;'style'];
  $msg&#1111;'footer'] = "</div><br><br>";
&#125;

#===========================================================
# ERROR MESSAGES
#===========================================================
$msg&#1111;'banned'] = "<b>Your IP address has been blocked.</b>";
$msg&#1111;'nosubmit'] = "<b>Your submission could not be sent. No action has been selected.</b>";
$msg&#1111;'recent'] = "<b>Recent entry. New submissions are allowed every $Interval minute(s).</b>";
$msg&#1111;'norecipient'] = "<b>This email cannot be sent. No specified recipient.</b>";
$msg&#1111;'required'] = "<b>The following field(s) are required to be filled in before submission:</b>";
$msg&#1111;'confirmed'] = "<b>The following fields must be the same before submission:</b>";
$msg&#1111;'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'))
&#123;
  $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++)
  &#123;
  $line = explode("|",$LogData&#1111;$x]);
   if ($IPAddress == $line&#1111;0])
   &#123;
     if (($MkTime - $line&#1111;1]) < $Seconds)
  	  exit ($msg&#1111;'header'] . $msg&#1111;'recent'] . $msg&#1111;'footer']);
   &#125;
  &#125;
  @flock($handle,LOCK_UN);
  @fclose($handle);
&#125;

#===========================================================
# SAVE INFORMATION TO STATS LOG
#===========================================================
if ($UseStats == "1")
&#123;
  $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);
&#125;

#===========================================================
# BANNED IP ADDRESSES
#===========================================================
  if(stristr($Banned,$IPAddress))
    exit ($msg&#1111;'header'] . $msg&#1111;'banned'] . $msg&#1111;'footer']);

#===========================================================
# ADJUST A FEW VARIABLES
#===========================================================

$ID = $num;

for ($x=0;$x<count($EMAIL);$x++)&#123;
 if ($EMAIL&#1111;$x]) $SendFrom = $EMAIL&#1111;$x];&#125;
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)
&#123;
 $ATTACH&#1111;$x]&#1111;0] = $_FILES&#1111;$ThisAttachment]&#1111;'name'];
 $ATTACH&#1111;$x]&#1111;1] = $_FILES&#1111;$ThisAttachment]&#1111;'tmp_name'];
 $x++;
&#125;

if ($SMTPServer)
&#123;
 ini_set('SMTP',$SMTPServer);
 ini_set('sendfrom_mail',$Recipient);
&#125;

#===========================================================
# CHECK REQUIRED FIELDS
#===========================================================
if ($Require)
&#123;
  $Required = explode(",",$Require);
  for($i=0;$i<count($Required);$i++)
  &#123;
	$Field = $Required&#1111;$i];
	if(!$_POST&#1111;$Field])
	&#123;
	 $Field = str_replace("_"," ",$Field);
	 $Field = ucfirst($Field);
	 $EmptyFields .= "<li>$Field</li>";
	 if ($Preview == "1")
	  $RedFields .= "$Field,";
	&#125;
  &#125;
  if ($EmptyFields)
   $Errors = $msg&#1111;'required'] . "<ul type="square">" . $EmptyFields . "</ul><br>";
&#125;

#===========================================================
# CHECK FIELDS FOR CONFIRMATION                             
#===========================================================
if ($Confirm)
&#123;
  $Confirmed = explode(",",$Confirm);
  for($i=0;$i<count($Confirmed);$i+=2)
  &#123;
	$Field1 = $Confirmed&#1111;$i];
	$Field2 = $Confirmed&#1111;$i+1];
	$FieldA = $_POST&#1111;$Field1];
	$FieldB = $_POST&#1111;$Field2];
	if ($FieldA != $FieldB)
	&#123;
	  $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,";
    &#125;
  &#125;
  if ($WrongFields and !$Errors)
   $Errors = $msg&#1111;'confirmed'] . "<ul type="square">" . $WrongFields . "</ul><br>";
  else if ($WrongFields and $Errors)
   $Errors .= "<br>" . $msg&#1111;'confirmed'] . "<ul type="square">" . $WrongFields . "</ul><br>";
&#125;

#===========================================================
# CHECK FORMATTED FIELDS
#===========================================================
if ($Format)
&#123;
  $Formatted = explode(",",$Format);
  for ($x=0;$x<count($Formatted);$x++)
  &#123;
    $Format = substr($Formatted&#1111;$x],-1);
	$Field = substr($Formatted&#1111;$x],0,-1);

	if ($Format == "<") // MINIMUM CHAR FORMAT
	&#123;
	  $Length = substr($Field,-2);
      $Field = substr($Field,0,-2);
	  if (substr($Length,0,1) == "0")
	   $Length = substr($Length,-1);
	  if ($_POST&#1111;$Field])
	  &#123;
        if(strlen($_POST&#1111;$Field]) < $Length)
	    &#123;
	      $Field = str_replace("_"," ",$Field);
		  $Field = ucfirst($Field);
	      $IncorrectFields .= "<li><b>$Field</b>&nbsp;requires a minimum of $Length Characters.</li>";
	      if ($Preview == "1")
	       $RedFields .= "$Field,";
		&#125;
	  &#125;
	&#125;

	if ($Format == ">") // MAXIMUM CHAR FORMAT
	&#123;
	  $Length = substr($Field,-2);
      $Field = substr($Field,0,-2);
	  if (substr($Length,0,1) == "0")
	   $Length = substr($Length,-1);
	  if ($_POST&#1111;$Field])
	  &#123;
        if(strlen($_POST&#1111;$Field]) > $Length)
	    &#123;
	      $Field = str_replace("_"," ",$Field);
		  $Field = ucfirst($Field);
	      $IncorrectFields .= "<li><b>$Field</b>&nbsp;exceeds the maximum of $Length Characters.</li>";
	      if ($Preview == "1")
	       $RedFields .= "$Field,";
		&#125;
	  &#125;
	&#125;

	if ($Format == "@" and $_POST&#1111;$Field]) // EMAIL FORMAT
	&#123;
	  if(!eregi('^(&#1111;_a-z0-9-]+)(\.&#1111;_a-z0-9-]+)*@(&#1111;a-z0-9-]+)(\.&#1111;a-z0-9-]+)*(\.&#1111;a-z]&#123;2,4&#125;)$',$_POST&#1111;$Field]))
	  &#123;
	   $Field = str_replace("_"," ",$Field);
	   $Field = ucfirst($Field);
	   $IncorrectFields .= "<li><b>$Field</b>&nbsp;requires the proper email format.</li>";
	   if ($Preview == "1")
	    $Redfields .= "$Field,";
	  &#125;
	  $Host = explode("@",$_POST&#1111;$Field]);
	  if (!checkdnsrr($Host&#1111;1].'.', 'MX'))
	  &#123;
	   $Field = str_replace("_"," ",$Field);
	   $Field = ucfirst($Field);
	   $IncorrectFields .= "<li><b>$Field</b>&nbsp;requires an existing domain name in the email format.</li>";
	   if ($Preview == "1")
	    $Redfields .= "$Field,";
	  &#125;
	&#125;

	if ($Format == "#" and $_POST&#1111;$Field]) // PHONE NUMBER FORMAT
	&#123;
	  if (!eregi('(&#1111;0-9]&#123;3&#125;)-(&#1111;0-9]&#123;3&#125;)-(&#1111;0-9]&#123;4&#125;)', $_POST&#1111;$Field]) and !eregi('(&#1111;0-9]&#123;3&#125;)\.(&#1111;0-9]&#123;3&#125;)\.(&#1111;0-9]&#123;4&#125;)', $_POST&#1111;$Field]) and !eregi('(&#1111;0-9]&#123;3&#125;) (&#1111;0-9]&#123;3&#125;) (&#1111;0-9]&#123;4&#125;)', $_POST&#1111;$Field]) and !eregi('(\(&#1111;0-9]&#123;3&#125;\))-(&#1111;0-9]&#123;3&#125;)-(&#1111;0-9]&#123;4&#125;)', $_POST&#1111;$Field]) and !eregi('(\(&#1111;0-9]&#123;3&#125;\))\.(&#1111;0-9]&#123;3&#125;)\.(&#1111;0-9]&#123;4&#125;)', $_POST&#1111;$Field]) and !eregi('(\(&#1111;0-9]&#123;3&#125;\)) (&#1111;0-9]&#123;3&#125;) (&#1111;0-9]&#123;4&#125;)', $_POST&#1111;$Field]) and !eregi('(\(&#1111;0-9]&#123;3&#125;\)) (&#1111;0-9]&#123;3&#125;)-(&#1111;0-9]&#123;4&#125;)', $_POST&#1111;$Field]) and !eregi('(\(&#1111;0-9]&#123;3&#125;\)) (&#1111;0-9]&#123;3&#125;)\.(&#1111;0-9]&#123;4&#125;)', $_POST&#1111;$Field]))
	  &#123;
	   $Field = str_replace("_"," ",$Field);
	   $Field = ucfirst($Field);
	   $IncorrectFields .= "<li><b>$Field</b>&nbsp;requires the proper phone format.</li>";
	   if ($Preview == "1")
	    $RedFields .= "$Field,";
	  &#125;
	&#125;

	if ($Format == "Z" and $_POST&#1111;$Field]) // ZIP CODE FORMAT
	&#123;
	  if (!eregi('(&#1111;0-9]&#123;5&#125;)', $_POST&#1111;$Field]))
	  &#123;
	   $Field = str_replace("_"," ",$Field);
	   $Field = ucfirst($Field);
	   $IncorrectFields .= "<li><b>$Field</b>&nbsp;requires the proper zip code format.</li>";
	   if ($Preview == "1")
	    $RedFields .= "$Field,";
	  &#125;
	&#125;

	if ($Format == "S" and $_POST&#1111;$Field]) // STATE FORMAT
	&#123;
	  if (!eregi('(&#1111;a-zA-Z]&#123;2&#125;)', $_POST&#1111;$Field]))
	  &#123;
	   $Field = str_replace("_"," ",$Field);
	   $Field = ucfirst($Field);
	   $IncorrectFields .= "<li><b>$Field</b>&nbsp;requires the proper state format.</li>";
	   if ($Preview == "1")
	    $RedFields .= "$Field,";
	  &#125;
	&#125;

	if ($Format == "N" and $_POST&#1111;$Field] > "") // NUMERIC ONLY FORMAT
	&#123;
	  if (eregi('(&#1111;a-zA-Z_\-])', $_POST&#1111;$Field]))
	  &#123;
	   $Field = str_replace("_"," ",$Field);
	   $Field = ucfirst($Field);
	   $IncorrectFields .= "<li><b>$Field</b>&nbsp;requires numeric-only characters.</li>";
	   if ($Preview == "1")
	    $RedFields .= "$Field,";
	  &#125;
	&#125;

	if ($Format == "A" and $_POST&#1111;$Field]) // ALPHA ONLY FORMAT
	&#123;
	  if (eregi('(&#1111;0-9])', $_POST&#1111;$Field]))
	  &#123;
	   $Field = str_replace("_"," ",$Field);
	   $Field = ucfirst($Field);
	   $IncorrectFields .= "<li><b>$Field</b>&nbsp;requires aplha-only characters.</li>";
	   if ($Preview == "1")
	    $RedFields .= "$Field,";
	  &#125;
	&#125;
  &#125;
  if ($IncorrectFields and !$Errors)
   $Errors = $msg&#1111;'formatted'] . "<ul type="square">" . $IncorrectFields . "</ul><br>";
  else if ($IncorrectFields and $Errors)
   $Errors .= "<br>" . $msg&#1111;'formatted'] . "<ul type="square">" . $IncorrectFields . "</ul><br>";
&#125;

#=======================================
# CHECK ATTACHMENT EXTENSION
#=======================================
if ($AllowedExt and ($ATTACH&#1111;0]&#1111;0] or $ATTACH&#1111;1]&#1111;0] or $ATTACH&#1111;2]&#1111;0]))
&#123;
   for ($x=0;$x<count($ATTACH);$x++)
   &#123;
    $MaxSize = $MaxFileSize * 1000;   
    if (filesize($ATTACH&#1111;$x]&#1111;1]) > $MaxSize)
    &#123;
     $Errors .= "<br><b><i>".$ATTACH&#1111;$x]&#1111;0]."</i> has exceeded the allowed file size of $MaxFileSize KB.</b><br>";
    &#125;
    $i = strrpos($ATTACH&#1111;$x]&#1111;0],".");
    $l = strlen($ATTACH&#1111;$x]&#1111;0]) - $i;
    $Ext = substr($ATTACH&#1111;$x]&#1111;0],$i+1,$l);
    $Ext = strtolower($Ext);
    if ($Ext)
	&#123;
     if (!strstr($AllowedExt,$Ext))
     &#123;
	  $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++)
	  &#123;
	   $Errors .= "<li>.".$Allowed&#1111;$x]."</li>";
	  &#125;
	  $Errors .= "</ul><br>";
	 &#125;
    &#125;
   &#125;
&#125;

#===========================================================
# PREVIEW
#===========================================================
if ($Preview == "1" and !$Refresh)
&#123;
 $HTML&#1111;'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))
&#123;
 if ($key != "Settings" and $key != "Refresh")
 &#123;
  $val = stripslashes($val);
  $val = str_replace('"','"',$val);
  $HTML&#1111;'form'] .= "<input type="hidden" name="".$key."" value="".$val."">";

  $key = ucfirst($key);
  $key = str_replace("_"," ",$key);

  for ($x=0;$x<count($RedFields)-1;$x++)
  &#123;
   if ($key == $RedFields&#1111;$x])
   &#123;
    $HTML&#1111;'form'] .= "<tr><td style="color:red"><b>$key</b>:</td><td>$val</td></tr>";
	$Flag = 1;
   &#125;
  &#125;
  if ($Flag != 1)
    $HTML&#1111;'form'] .= "<tr><td><b>$key</b>:</td><td>$val</td></tr>";
  $Flag = 0;
 &#125;
&#125;
  $HTML&#1111;'form'] .= "<tr><td height=16 colspan=2></td></tr>";
  if (!$Errors)
   $HTML&#1111;'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&#1111;'form'] .= "</form></table>";
&#125;

if ($Errors and $Preview != "1")
 exit ($msg&#1111;'header'].$Errors.$msg&#1111;'footer']);
else if ($Errors and $Preview == "1" and !$Refresh)
 exit ($msg&#1111;'header'].$Errors."<br>".$HTML&#1111;'preview'].$HTML&#1111;'form'].$msg&#1111;'footer']);
else if ($Preview == "1" and !$Refresh)
 exit ($msg&#1111;'header'].$HTML&#1111;'preview'].$HTML&#1111;'form'].$msg&#1111;'footer']);


#===========================================================
# CHOOSE ACTION
#===========================================================
if (!$Action)
 exit($msg&#1111;'header'] . $msg&#1111;'nosubmit'] . $msg&#1111;'footer']);
 
#########################################################################
# EMAIL FUNCTIONS                                                       #
#########################################################################
if ($Action == "E" or $Action == "EC" or $Action == "ED" or $Action == "EF")&#123;

while (list ($key, $val) = each ($_EMAIL))
&#123;
 if ($key != "Settings" and $key != "Refresh")
 &#123;
  $val = stripslashes($val);
  $val = str_replace('"','"',$val);
  $val = strip_tags($val);
  $key = ucfirst($key);
  $key = str_replace("_"," ",$key);
  $EMAIL&#1111;'text'] .= "$key:  $val\r\n";
  $val = nl2br($val);
  $EMAIL&#1111;'form'] .= "<b>$key</b>:&nbsp;&nbsp;$val<br>";
  $EMAIL&#1111;'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>";
 &#125;
&#125;

if (!$Recipient)
  exit ($msg&#1111;'header'] . $msg&#1111;'norecipient'] . $msg&#1111;'footer']);

if (!$Subject)
   $Subject = "Web Order - $ID";

#===========================================================
# Email Templates
#===========================================================
$EMAIL&#1111;'textemail'] = "
***Form Results***\r\n
".$EMAIL&#1111;'text']."
User's Browser: $Browser\r\n
User's IP Address: $IPAddress\r\n\r\n
- Mail Manage EX Notifier -
";

if ($EmailTemplate)
&#123;
 $handle = @fopen($EmailTemplate,'r');
 $EMAIL&#1111;'htmlemail'] = @fread($handle,filesize($EmailTemplate));
 @fclose($handle);
 if (!strstr($EMAIL&#1111;'htmlemail'],'&#1111;ALL]'))
 &#123;
  while(list($key,$val) = each($_HTML))
  &#123;
   $insert = "&#1111;".$key."]";
   $val = stripslashes($val);
   $val = strip_tags($val);
   $val = nl2br($val);
   $EMAIL&#1111;'htmlemail'] = str_replace($insert,$val,$EMAIL&#1111;'htmlemail']);
  &#125;
 &#125;
 else
  $EMAIL&#1111;'htmlemail'] = str_replace('&#1111;ALL]',$EMAIL&#1111;'form'],$EMAIL&#1111;'htmlemail']);
  
 $EMAIL&#1111;'htmlemail'] = str_replace("&#1111;Received]",$Time,$EMAIL&#1111;'htmlemail']);
 $EMAIL&#1111;'htmlemail'] = str_replace("&#1111;IPAddress]",$IPAddress,$EMAIL&#1111;'htmlemail']);
 $EMAIL&#1111;'htmlemail'] = str_replace("&#1111;Browser]",$Browser,$EMAIL&#1111;'htmlemail']);
 $EMAIL&#1111;'htmlemail'] = str_replace("&#1111;ID]",$ID,$EMAIL&#1111;'htmlemail']);
 $EMAIL&#1111;'htmlemail'] = str_replace("&#1111;Attach1]",$ATTACH&#1111;0]&#1111;0],$EMAIL&#1111;'htmlemail']);
 $EMAIL&#1111;'htmlemail'] = str_replace("&#1111;Attach2]",$ATTACH&#1111;1]&#1111;0],$EMAIL&#1111;'htmlemail']);
 $EMAIL&#1111;'htmlemail'] = str_replace("&#1111;Attach3]",$ATTACH&#1111;2]&#1111;0],$EMAIL&#1111;'htmlemail']);
&#125;
else
&#123;
$EMAIL&#1111;'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:&nbsp;'.$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&#1111;'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>';
&#125;
#===========================================================
# 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&#1111;0]&#1111;0] or $ATTACH&#1111;1]&#1111;0] or $ATTACH&#1111;2]&#1111;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")
&#123;
 $Content .= "--$MimeBoundary\n";
 $Content .= "Content-Type: text/plain; charset="iso-8859-1"\n";
 $Content .= "Content-Transfer-Encoding: 8bit\n\n";
 $Content .= $EMAIL&#1111;'textemail']."\n\n";
&#125;
if ($HtmlEmails == "1")
&#123;
 $Content .= "--$MimeBoundary\n";
 $Content .= "Content-Type: text/html; charset="iso-8859-1"\n";
 $Content .= "Content-Transfer-Encoding: 8bit\n\n";
 $Content .= $EMAIL&#1111;'htmlemail']."\n\n";
&#125;
if ($AttachmentFields)
&#123;
   for ($x=0;$x<count($ATTACH);$x++)
   &#123;
        $TmpFile = "data/".$ATTACH&#1111;$x]&#1111;0];
        @copy($ATTACH&#1111;$x]&#1111;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&#1111;$x]&#1111;0].""\n";
        $Content .= "Content-Transfer-Encoding: base64\n";
        $Content .= "Content-Disposition: attachment;\n filename="".$ATTACH&#1111;$x]&#1111;0].""\n\n";
		$Content .= $FileContent."\n";
		@unlink($TmpFile);
   &#125;
&#125;
$Content .= "--$MimeBoundary--\n\n\n";


#===========================================================
# Send It Off
#===========================================================
mail($Recipient, $Subject, $Content, $Headers);


&#125; // END OF ACTION

#########################################################################
# CSV-FILE FUNCTIONS                                                    #
#########################################################################
if ($Action == "C" or $Action == "EC" or $Action == "CD")&#123;

$Time = date('M j Y  @ g:i:s a',mktime(date('H')+$TimeZone));

while (list ($key, $val) = each ($_CSV))
&#123;
 if ($key != "Settings" and $key != "Refresh")
 &#123;
  $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,";
 &#125;
&#125;
$CSVData .= "$Time,$IPAddress,$Browser";

$handle = @fopen($CSVFile,'a');
@flock($handle,LOCK_EX);
@fwrite($handle,$CSVData."\n");
@flock($handle,LOCK_UN);
@fclose($handle);

&#125; // END OF ACTION

#########################################################################
# FLAT-FILE FUNCTIONS                                                   #
#########################################################################
if ($Action == "F" or $Action == "EF" or $Action == "DF")&#123;

$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);

&#125; // END OF ACTION

#########################################################################
# DATABASE FUNCTIONS                                                    #
#########################################################################
if ($Action == "D" or $Action == "ED" or $Action == "CD" or $Action == "DF")&#123;

$Connect = @mysql_connect("localhost", "$SQL_UserName", "$SQL_Password");
@mysql_select_db("$SQL_Database",$Connect);

while (list ($key, $val) = each ($_SQL))
&#123;
 if ($key != "Settings" and $key != "Refresh")
 &#123;
	$val = stripslashes($val);
	$val = str_replace('"','"',$val);
    $val = strip_tags($val);
	$Columns .= $key . ',';
    $Values .= "'" . $val . "',";
 &#125;
&#125;
if ($SQL_ENV == "1")
&#123;
 $Columns .= "Received,IPAddress,Browser";
 $Values .= "'" . $Time . "','" . $IPAddress ."','" . $Browser . "'";
&#125;
else
&#123;
 $Columns = substr($Columns,0,-1);
 $Values = substr($Values,0,-1);
&#125;

@mysql_query("INSERT INTO $SQL_Table ($Columns) VALUES ($Values)");
@mysql_close($Connect);

&#125; // END OF ACTION

#########################################################################
# POST SUBMIT FUNCTIONS                                                 #
#########################################################################

#===========================================================
# SAVE FLOOD CONTROL DATA (POST-SUBMISSION)
#===========================================================
if ($FloodControl == "1")
&#123;
$LogData = $IPAddress . "|" . $MkTime . "#";

  $handle = @fopen('data/flood.log','a');
  @flock($handle,LOCK_EX);
  @fwrite($handle,$LogData);
  @flock($handle,LOCK_UN);
  @fclose($handle);
&#125;

#===========================================================
# Auto Respond Information
#===========================================================
if ($AutoRespond == "1")
&#123;
  if (!$AutoSubject)
    $AutoSubject = 'Thank you for your submission';
  if ($AutoTemplate and file_exists($AutoTemplate))
  &#123;
    $handle = @fopen($AutoTemplate,'r');
    $AutoContent = @fread($handle,filesize($AutoTemplate));
    @fclose($handle);
	while(list($key,$val) = each($_AUTO))
    &#123;
     $insert = "&#1111;".$key."]";
     $val = stripslashes($val);
     $val = strip_tags($val);
     $val = nl2br($val);
     $AutoContent = str_replace($insert,$val,$AutoContent);
	 $AutoContent = str_replace("&#1111;Received]",$Time,$AutoContent);
     $AutoContent = str_replace("&#1111;ID]",$ID,$AutoContent);
     $AutoContent = str_replace("&#1111;Attach1]",$ATTACH&#1111;0]&#1111;0],$AutoContent);
     $AutoContent = str_replace("&#1111;Attach2]",$ATTACH&#1111;1]&#1111;0],$AutoContent);
     $AutoContent = str_replace("&#1111;Attach3]",$ATTACH&#1111;2]&#1111;0],$AutoContent);
    &#125;
  &#125;
  if (!$AutoContent)
	$AutoContent = "Cartwright Signs has received your order. Your Submission ID is : &#1111;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);
&#125;

#===========================================================
# REDIRECT OR THANK YOU
#===========================================================
if (!$Redirect)
&#123;
  if (!$ThankYou)
    $ThankYou = 'Thank you for your submission.';
  exit ($msg&#1111;'header'] . "$ThankYou". $msg&#1111;'footer']);
&#125;
else
  echo "<html><head><META http-equiv="refresh" content="0;URL=$Redirect"></head><body></body></html>";
?>
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

tags! [u]shame![/u][/color]
skydivelouie
Forum Newbie
Posts: 23
Joined: Tue Jan 18, 2005 7:07 pm

Post by skydivelouie »

Sorry...don't understand how to implement

Code: Select all

tags...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

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"

:x
skydivelouie
Forum Newbie
Posts: 23
Joined: Tue Jan 18, 2005 7:07 pm

Post by skydivelouie »

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...
Post Reply