Page 1 of 1

Help Please

Posted: Sun Mar 27, 2005 1:52 pm
by Bob Norris
Hello,

New to PHP and I need to get this form to not valadate email, Can anyone help?

Adresse of project: http://www.cyberoperator.com/cbc/comments/index.php

Code: Select all

<? 
//--Change the following variables
//Change "admin" with your own password. It's required when you delete an entry
  $admin_password = "dogfight";
//Enter your email here
  $admin_email = "contest@worldchatterbots.com";
//Your website URL
  $home = "";
//Send you an email when someone adds a comment, YES or NO
  $notify = "YES";
//Your Operating System
//For Windows/NT user : WIN
//For Linux/Unix user : UNIX
  $os = "UNIX";
//Maximum entry per page when you view the comments form
  $max_entry_per_page = "10";
//Name of file used to store your entry, change it if necessary
  $data_file = "gbook.dat";
//Maximum entry stored in data file
  $max_record_in_data_file = "300";
//Color & font setting
  $background = "#EAEAEA";
  $table_top = "#C0C0C0";
  $table_content_1a = "#EDEEE8";
  $table_content_1b = "#E4E4E4";
  $table_content_2a = "#ffffff";
  $table_content_2b = "#ADADAD";
  $table_bottom = "#C0C0C0";
  $table_border = "#000000";
  $title_color = "black";
  $link = "blue";
  $visited_link = "blue";
  $active_link = "red";
  $font_face = "verdana";
  $message_font_face = "arial";
  $message_font_size = "2";

//-- Don't change bellow this line unless you know what you're doing

$do = isset($_REQUEST['do']) ? trim($_REQUEST['do']) : "";
$id = isset($_GET['id']) ? trim($_GET['id']) : "";
$page = isset($_GET['page']) ? $_GET['page'] : 1;
$PHP_SELF = isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : $HTTP_SERVER_VARS['PHP_SELF'];

if (!file_exists($data_file)) {
    echo "<b>Error !!</b> Can't find data file : $data_file.<br>";
	exit;
} else {
  if ($max_record_in_data_file <> "0") {
     $f = file($data_file);
     rsort($f);
     $j = count($f);
     if ($j > $max_record_in_data_file) {
        $rf = fopen($data_file,"w");
            if (strtoupper($os)=="UNIX") {		    		 
	           if (flock($rf,LOCK_EX)) {
                  for ($i=0; $i<$max_record_in_data_file; $i++) {
                      fwrite($rf,$f[$i]);	     
			      }
                  flock($rf,LOCK_UN);
	           }
            } else {
               for ($i=0; $i<$max_record_in_data_file; $i++) {
                  fwrite($rf,$f[$i]);	     
	           }
	        }
	    fclose($rf);
     }
  }
}

switch ($do) {
case "":
   $record = file($data_file);
   rsort($record);
   $jmlrec = count($record);
?>
   <html>
   <head><title><?=$title?></title></head>
   <body bgcolor="<?=$background?>" link="<?=$link?>" vlink="<?=$visited_link?>" alink="<?=$active_link?>" topmargin="0" marginheight="0" style="font-family:<?=$font_face?>">
   <center>
   <font size="6" color="<?=$title_color?>"><b><?=$title?></b></font><br>
   <table width="600" cellpadding="0" cellspacing="1" border="0">
   <tr bgcolor="<?=$table_border?>">
   <td>
      <table width="100%" cellpadding="4" cellspacing="1" border="0">
      <tr>
	    <td bgcolor="<?=$table_top?>" colspan="2" width="585">
           <center><font size="2" color="#0000FF"><b>Click <a href="<?="$PHP_SELF?do=add_form&page=$page"?>">here</a> and enter bots name to join contest</font></b>
        </td>
	    <td bgcolor="<?=$table_top?>" align="center" width="15">
	       <a href="mailto:<?=$admin_email?>"><img src="webmaster.gif" border="0" alt="Contact webmaster" align="center" width="15" height="15"></a>
	    </td>
	  </tr>
<?
      $jml_page = intval($jmlrec/$max_entry_per_page);
      $sisa = $jmlrec%$max_entry_per_page;
      if ($sisa > 0) $jml_page++;
      $no = $page*$max_entry_per_page-$max_entry_per_page;
      if ($jmlrec == 0) echo "<tr><td colspan=\"3\" bgcolor=\"#FFE1E1\" align=\"center\"><font size=\"3\">There are no entries yet.</font></td></tr>";

		$w = 0; //--Color
        for ($i=0; $i<$max_entry_per_page; $i++) {
		    $no++;
		    $recno = $no-1;
		    if (isset($record[$recno])) {
		       $row = explode("|~|",$record[$recno]);
			   if ($w==0) { 
				   $warna = $table_content_1a;
				   $warna2 = $table_content_1b;
				   $w=1;
			   } else { 
				   $warna = $table_content_2a;
				   $warna2 = $table_content_2b;
				   $w=0;
			   }
			   echo "<tr>
			           <td bgcolor=\"$warna2\" align=\"center\" valign=\"top\" width=\"15\">
					     <font size=\"2\">$no</font>
					   </td>
					   <td bgcolor=\"$warna\" width=\"570\">
					   <table border=\"0\" width=\"100%\">
					   <tr>
					    <td>
					     <font size=\"1\">$row[2]</font><br>
						 <font size=\"2\"><b>$row[3]</b></font>
						</td>
					";
               echo "<td align=right valign=top>
						<a href=\"mailto:$row[4]\"><img src=\"email.gif\" border=0 alt=\"$row[3]'s email\"></a>";
			            if (trim($row[6]) <> "" && trim($row[6]) <> "http://") {
                           if (ereg("^http://", trim($row[6]))) echo " <a href=\"$row[6]\" TARGET=\"_blank\"><img src=\"homepage.gif\" border=\"0\" alt=\"$row[3]'s homepage\"></a>";
                           else echo " <a href=\%22http:/$row[6]\%22 TARGET=\"_blank\"><img src=\"homepage.gif\" border=\"0\" alt=\"$row[3]'s homepage\"></a>";
			            }
			   echo "</td></tr></table>";
			   echo "<br><table border=\"0\" width=\"100%\">
			         <tr><td width=\"5\">&nbsp;</td><td>
			         <font size=\"2\" face=\"$message_font_face\" size=\"$message_font_size\">$row[5]</font>
					 </td></tr>
                     </table>
			        ";
			   echo "</td>";
			   echo "<td valign=\"top\" bgcolor=\"$warna2\" align=\"center\" width=\"15\">
			         <a href=\"$PHP_SELF?do=del&id=$row[1]&page=$page\">
					 <img src=\"del.gif\" alt=\"Delete entry # $no\" border=0 align=\"center\"></a>
					 </td>
					 </tr>";
			} //--end if		
        } //--end for
      echo "<tr><td colspan=\"3\" bgcolor=\"$table_bottom\" align=\"center\" width=\"600\"><font size=\"1\">";	  	  
      if ($jml_page > 1) {	   
	   if ($page <> 1) echo "[<a href=\"$PHP_SELF?page=1\">Top</a>] "; else echo "[Top] "; 
	   echo "Page # ";
       if ($jml_page > 10) {
	 	 if ($page < 5) {
		    $start = 1;
			$stop = 10;
		 } elseif ($jml_page - $page < 5) {
		    $start = $jml_page - 9;
			$stop = $jml_page;
		 } else {
		    $start = $page-4;
			$stop = $page+5;
		 }
		 if ($start <> 1) echo "... ";
         for ($p=$start; $p<=$stop; $p++) {
	         if ($p == $page) echo "<font color=\"$active_link\"><b>$p</b></font>&nbsp;&nbsp;";
			 else echo "<a href=\"$PHP_SELF?page=$p\">$p</a>&nbsp;&nbsp;";
         }
		 if ($stop <> $jml_page) echo "... ";		 		 
		 echo "of $jml_page ";
       } else {
         for ($p=1; $p<=$jml_page; $p++) {
	         if ($p == $page) echo "<font color=\"$active_link\"><b>$p</b></font>&nbsp;&nbsp;";
			 else echo "<a href=\"$PHP_SELF?page=$p\">$p</a>&nbsp;&nbsp;";
         }
	   }	   
       if ($page <> $jml_page) echo "[<a href=\"$PHP_SELF?page=$jml_page\">Bottom</a>]"; else echo "[bottom]"; 
      } else echo "Page #1 of 1";        
	  echo "</font></td></tr>";
?>
        </table>        
		</td>
		</tr>
		</table><br><br>

   
   </center>
   </body>
   </html>
<?
break;
case "add_form":
?>
<!-- For advanced user : customize your form here, but don't change both the name and value -->
<html>
<head>
<title><?=$title?></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="<?=$background?>" style="font-family:<?=$font_face?>">
<div align="center"> 
  <font size="5" color="<?=$title_color?>"><b><?=$title?></b></font><br>
  <font size="1"><b><a href="<?=$home?>"><font color="<?=$title_color?>">Home</font></a> :: <a href="<?=$PHP_SELF?>"><font color="<?=$title_color?>">View entry</font></a></b></font>
  <form method="post" action="<?=$PHP_SELF?>">
  <input type="hidden" name="do" value="add">
    <table width="460" border="0" cellspacing="0" cellpadding="0" bgcolor="<?=$table_border?>">
      <tr>
      <td>
        <div align="center">
            <table width="100%" border="0" cellspacing="1" cellpadding="5">
              <tr bgcolor="<?=$table_content_1a?>"> 
                <td width="28%"> 
                  <div align="right"><font size="2">*Bots Name : </font></div>
                </td>
                <td width="72%"> 
                  <input type="text" name="vname" size="30" maxlength="70">
                </td>
              </tr>
              <tr bgcolor="<?=$table_content_1a?>"> 
                <td width="28%"> 
                  <div align="right"><font size="2">*Email : </font></div>
                </td>
                <td width="72%"> 
                  <input type="text" name="vemail" size="30" maxlength="100">
                </td>
              </tr>
              <tr bgcolor="<?=$table_content_1a?>"> 
                <td width="28%"> 
                  <div align="right"><font size="2">Website : </font></div>
                </td>
                <td width="72%"> 
                  <input type="text" name="vurl" size="30" maxlength="150" value="http://">
                </td>
              </tr>
              <tr bgcolor="<?=$table_content_1a?>"> 
                <td valign="top" width="28%"> 
                  <div align="right"><font size="2">*Comment : </font></div>
                </td>
                <td width="72%"> 
                  <textarea name="vcomment" cols="40" rows="7" wrap="virtual"></textarea><br><font size="1">* Required field</font>
                </td>
              </tr>
              <tr bgcolor="<?=$table_content_1b?>"> 
                <td colspan="2"> 
                  <div align="center">
                    <font size="2">
                    <input type="submit" value="Submit">
                    <input type="reset" value="Reset">
					<input type="button" value="Back" onclick="window.location='<?="$PHP_SELF?page=$page"?>'">
                    </font>
				   </div>
                </td>
              </tr>
            </table>
        </div>
      </td>
    </tr>
  </table>
  </form>
</div>
</body>
</html>
<!-- End of entry form -->
<?
break;
case "add":
   $vname = isset($_POST['vname']) ? trim($_POST['vname']) : "";
   $vemail = isset($_POST['vemail']) ? trim($_POST['vemail']) : "";
   $vurl = isset($_POST['vurl']) ? trim($_POST['vurl']) : "";
   $vcomment = isset($_POST['vcomment']) ? trim($_POST['vcomment']) : "";

   if (strlen($vname) > 70) $vname = substr($vname,0,70);
   if (strlen($vemail) > 100) $vemail = substr($vemail,0,100);
   if (strlen($vurl) > 150) $vurl = substr($vurl,0,150);

   if ($vname=="" or $vcomment=="" or $vemail=="") {
      echo "<html><body bgcolor=\"#ffffff\" style=\"font-family:$font_face\"><h3>Error !</h3><font size=\"2\">You may left some fields. Please click <b><a href=\"javascript:history.back()\">here</a></b> and try again.</font></body></html>";
	  exit;
   }

   if (!preg_match("/([\w\.\-]+)(\@[\w\.\-]+)(\.[a-z]{2,4})+/i", $vemail)) {
      echo "<html><body bgcolor=\"#ffffff\" style=\"font-family:$font_face\"><h3>Error !</h3><font size=\"2\">Invalid email address. Please click <b><a href=\"javascript:history.back()\">here</a></b> and try again.</font></body></html>";
	  exit;
   }

   if (trim($vurl) <> "") {
	  if (strtolower(trim($vurl)) <> "http://") {
         if (!preg_match ("#^http://[_a-z0-9-]+\\.[_a-z0-9-]+#i", $vurl)) {
		    echo "<html><body bgcolor=\"#ffffff\" style=\"font-family:$font_face\"><h3>Error !</h3><font size=\"2\">Invalid URL format. Please click <b><a href=\"javascript:history.back()\">here</a></b> and try again.</font></body></html>";
	        exit;
          }
      }
   }

   $test_comment = explode(" ",$vcomment);
   $jmltest = count($test_comment);
   for ($t=0; $t<$jmltest; $t++) {
      if (strlen(trim($test_comment[$t])) > 35) {
        echo "<html><body bgcolor=\"#ffffff\" style=\"font-family:$font_face\"><h3>Error!</h3><font size=\"2\">Please don't abuse the form. Click <b><a href=\"javascript:history.back()\">here</a></b> and try again.</font></body></html>";
	    exit;	     
	  }
   }

   //--only 2000 characters allowed for comment, change this value if necessary
   $maxchar = 2000;
   if (strlen($vcomment) > $maxchar) $vcomment = substr($vcomment,0,$maxchar)."...";

   $idx = date("YmdHis");
   $tgl = date("F d, Y - h:i A");

   $vname = str_replace("<","",$vname);
   $vname = str_replace(">","",$vname);
   $vname = str_replace("~","-",$vname);
   $vname = str_replace("\"",""",$vname);

   $vcomment = str_replace("<","<",$vcomment);
   $vcomment = str_replace(">",">",$vcomment);
   $vcomment = str_replace("~","-",$vcomment);
   $vcomment = str_replace("\"",""",$vcomment);

   $vurl = str_replace("<","",$vurl);
   $vurl = str_replace(">","",$vurl);
   $vurl = str_replace("|","",$vurl);

   if (strtoupper($os) == "WIN") {
	   $vcomment = str_replace("\r\n","<br>",$vcomment);
	   $vcomment = str_replace("\r","",$vcomment);
	   $vcomment = str_replace("\n","",$vcomment);
   } else {
	   $vcomment = str_replace("\n","<br>",$vcomment);
	   $vcomment = str_replace("\r","",$vcomment);
   }

   $ipnum = getenv("REMOTE_ADDR");

   $newdata = "|~|$idx|~|$tgl|~|$vname|~|$vemail|~|$vcomment|~|$vurl|~|$ipnum|~|\n";
   $newdata = stripslashes($newdata);

   $bagus = true;
   $cekdata = file($data_file);
   $jmlcekdata = count($cekdata);
   if ($jmlcekdata > 0) {
      rsort($cekdata);
      if ($jmlcekdata > 2) {
         $newrow = explode("|~|",$newdata);
	     $jmlentry = 0;
         for ($c=0; $c<3; $c++) {
             $cekrow = explode("|~|",$cekdata[$c]);
             if ($cekrow[4] == $newrow[4] || ($cekrow[3] == $newrow[3] && $cekrow[4] == $newrow[4])) {
				 $jmlentry++;
			 }
	     }
         $bagus = ($jmlentry < 3) ? true : false;
      }
   }

   if ($bagus) {
	  $tambah = fopen($data_file,"a");
      if (strtoupper($os)=="UNIX") {
         if (flock($tambah,LOCK_EX)) {
	        fwrite($tambah,$newdata);
	        flock($tambah,LOCK_UN);
         }
      } else {
	     fwrite($tambah,$newdata);
      }
      fclose($tambah);

      //--SEND MAIL
      if (strtoupper($notify) == "YES") {
         $msgtitle = "Someone Entered The Contest";
         $vcomment = str_replace(""","\"",$vcomment);   
         $vcomment = stripslashes($vcomment);
	     $vcomment = str_replace("<br>","\n",$vcomment);
         $msgcontent = "Local time : $tgl\n\nThe addition from $vname :\n----------------------------\n\n$vcomment\n\n-----End Message-----";
         @mail($admin_email,$msgtitle,$msgcontent,"From: $vemail\n");
      }
   }

   echo "<html><meta http-equiv=\"refresh\" content=\"1; url=$PHP_SELF\"><body bgcolor=\"#ffffff\" style=\"font-family:$font_face\"><center><h3>Thank you, your entry has been added.</h3>Please wait...</center></body></html>";
break;

case "del":
   $record = file($data_file);
   $jmlrec = count($record);
   for ($i=0; $i<$jmlrec; $i++) {
       $row = explode("|~|",$record[$i]);
	   if ($id == $row[1]) {
	      echo "
		  <html><head><title>Delete record</title></head>
		  <body bgcolor=\"$background\" style=\"font-family:$font_face\">
		  <center>
		  <font size=\"4\" color=\"$title_color\">Delete Confirmation</font>
		  <br><br>
		  <table border=\"0\" cellpadding=\"5\" cellspacing=\"1\" width=\"450\">
			<tr>
			<td bgcolor=\"$table_top\">
            <font size=\"2\">
			<font size=\"1\"><b>$row[2]</font><br>$row[3]</b> - <a href=\"mailto:$row[4]\">$row[4]</a><br><br>$row[5]
			<br><br><font size=\"1\">IP : $row[7]</font>
			</font> 
			</td>
			</tr>
		  </table>
		  ";
	      break;
	   }
   }   
   echo "<form action=\"$PHP_SELF\" method=\"post\"><font color=\"$title_color\" size=\"2\"><b>Admin password : </b></font><input type=\"password\" name=\"pwd\"><input type=\"hidden\" name=\"do\" value=\"del2\"><br><br><font size=\"2\" color=\"$title_color\"><b>&raquo;</b><input type=\"checkbox\" name=\"byip\" value=\"$row[7]\"> Delete all record that using this IP : $row[7]</font><br><br><input type=\"submit\" value=\"Delete\"> <input type=\"button\" value=\"Cancel\" onclick=\"window.location='$PHP_SELF?page=$page'\"><input type=\"hidden\" name=\"id\" value=\"$id\"><input type=\"hidden\" name=\"page\" value=\"$page\"></FORM></center></body></html>";
break;

case "del2":
   $pwd = isset($_POST['pwd']) ? trim($_POST['pwd']) : "";
   $id = isset($_POST['id']) ? trim($_POST['id']) : "";
   $page = isset($_POST['page']) ? $_POST['page'] : 1;
   $byip = isset($_POST['byip']) ? $_POST['byip'] : "";

   if ($pwd <> $admin_password) {
         echo "<html><head><meta http-equiv=\"refresh\" content=\"1; url=$PHP_SELF?page=$page\"></head><body bgcolor=\"#ffffff\" style=\"font-family:$font_face\"><center><h3>Invalid admin password !</h3>Please wait...</center></body><html>";
         exit;
   }

   $record = file($data_file);
   $jmlrec = count($record);
   for ($i=0; $i<$jmlrec; $i++) {
       $row = explode("|~|",$record[$i]);
	   if ($byip == "") {
		   if ($row[1] == $id) {
			   $record[$i] = "";
		       break;
	       }
	   } else {
		   if ($row[7] == $byip) {
			   $record[$i] = "";
		   }
	   }
   }

   $update_data = fopen($data_file,"w");
   if (strtoupper($os) == "UNIX") {
      if (flock($update_data,LOCK_EX)) {
	     for ($j=0; $j<$jmlrec; $j++) {
             if ($record[$j] <> "") {
				 fputs($update_data,$record[$j]);
			 }
		 }
		 flock($update_data,LOCK_UN);
	  }
   } else {
	     for ($j=0; $j<$jmlrec; $j++) {
             if ($record[$j] <> "") {
				 fputs($update_data,$record[$j]);
			 }
		 }
   }
   fclose($update_data);

   echo "<html><head><meta http-equiv=\"refresh\" content=\"1; url=$PHP_SELF?page=$page\"></head><body bgcolor=\"#EAEAEA\" style=\"font-family:$font_face\"><center><h3>Record has been deleted !</h3>Please wait...</center></body><html>";
break;
} //--end switch
?>

feyd | Please review how to post code using

Code: Select all

and

Code: Select all

tags. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Sun Mar 27, 2005 1:55 pm
by feyd
remove lines 283 through 286. Please work on using better topic titles, thanks.

Same Topic

Posted: Sun Mar 27, 2005 2:09 pm
by Bob Norris
Hello ,

I Removed those lines and it seems to have no effect. Any other suggestions? Sorry about the Topic Description

Code: Select all

<?
//--Change the following variables
//Change "admin" with your own password. It's required when you delete an entry
  $admin_password = "dogfight";
//Enter your email here
  $admin_email = "contest@worldchatterbots.com";
//Your website URL
  $home = "";
//Send you an email when someone adds a comment, YES or NO
  $notify = "YES";
//Your Operating System
//For Windows/NT user : WIN
//For Linux/Unix user : UNIX
  $os = "UNIX";
//Maximum entry per page when you view the comments form
  $max_entry_per_page = "10";
//Name of file used to store your entry, change it if necessary
  $data_file = "gbook.dat";
//Maximum entry stored in data file
  $max_record_in_data_file = "300";
//Color & font setting
  $background = "#EAEAEA";
  $table_top = "#C0C0C0";
  $table_content_1a = "#EDEEE8";
  $table_content_1b = "#E4E4E4";
  $table_content_2a = "#ffffff";
  $table_content_2b = "#ADADAD";
  $table_bottom = "#C0C0C0";
  $table_border = "#000000";
  $title_color = "black";
  $link = "blue";
  $visited_link = "blue";
  $active_link = "red";
  $font_face = "verdana";
  $message_font_face = "arial";
  $message_font_size = "2";

//-- Don't change bellow this line unless you know what you're doing

$do = isset($_REQUEST['do']) ? trim($_REQUEST['do']) : "";
$id = isset($_GET['id']) ? trim($_GET['id']) : "";
$page = isset($_GET['page']) ? $_GET['page'] : 1;
$PHP_SELF = isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : $HTTP_SERVER_VARS['PHP_SELF'];

if (!file_exists($data_file)) {
    echo "<b>Error !!</b> Can't find data file : $data_file.<br>";
	exit;
} else {
  if ($max_record_in_data_file <> "0") {
     $f = file($data_file);
     rsort($f);
     $j = count($f);
     if ($j > $max_record_in_data_file) {
        $rf = fopen($data_file,"w");
            if (strtoupper($os)=="UNIX") {		    		 
	           if (flock($rf,LOCK_EX)) {
                  for ($i=0; $i<$max_record_in_data_file; $i++) {
                      fwrite($rf,$f[$i]);	     
			      }
                  flock($rf,LOCK_UN);
	           }
            } else {
               for ($i=0; $i<$max_record_in_data_file; $i++) {
                  fwrite($rf,$f[$i]);	     
	           }
	        }
	    fclose($rf);
     }
  }
}

switch ($do) {
case "":
   $record = file($data_file);
   rsort($record);
   $jmlrec = count($record);
?>
   <html>
   <head><title><?=$title?></title></head>
   <body bgcolor="<?=$background?>" link="<?=$link?>" vlink="<?=$visited_link?>" alink="<?=$active_link?>" topmargin="0" marginheight="0" style="font-family:<?=$font_face?>">
   <center>
   <font size="6" color="<?=$title_color?>"><b><?=$title?></b></font><br>
   <table width="600" cellpadding="0" cellspacing="1" border="0">
   <tr bgcolor="<?=$table_border?>">
   <td>
      <table width="100%" cellpadding="4" cellspacing="1" border="0">
      <tr>
	    <td bgcolor="<?=$table_top?>" colspan="2" width="585">
           <center><font size="2" color="#0000FF"><b>Click <a href="<?="$PHP_SELF?do=add_form&page=$page"?>">here</a> and enter bots name to join contest</font></b>
        </td>
	    <td bgcolor="<?=$table_top?>" align="center" width="15">
	       <a href="mailto:<?=$admin_email?>"><img src="webmaster.gif" border="0" alt="Contact webmaster" align="center" width="15" height="15"></a>
	    </td>
	  </tr>
<?
      $jml_page = intval($jmlrec/$max_entry_per_page);
      $sisa = $jmlrec%$max_entry_per_page;
      if ($sisa > 0) $jml_page++;
      $no = $page*$max_entry_per_page-$max_entry_per_page;
      if ($jmlrec == 0) echo "<tr><td colspan=\"3\" bgcolor=\"#FFE1E1\" align=\"center\"><font size=\"3\">There are no entries yet.</font></td></tr>";

		$w = 0; //--Color
        for ($i=0; $i<$max_entry_per_page; $i++) {
		    $no++;
		    $recno = $no-1;
		    if (isset($record[$recno])) {
		       $row = explode("|~|",$record[$recno]);
			   if ($w==0) { 
				   $warna = $table_content_1a;
				   $warna2 = $table_content_1b;
				   $w=1;
			   } else { 
				   $warna = $table_content_2a;
				   $warna2 = $table_content_2b;
				   $w=0;
			   }
			   echo "<tr>
			           <td bgcolor=\"$warna2\" align=\"center\" valign=\"top\" width=\"15\">
					     <font size=\"2\">$no</font>
					   </td>
					   <td bgcolor=\"$warna\" width=\"570\">
					   <table border=\"0\" width=\"100%\">
					   <tr>
					    <td>
					     <font size=\"1\">$row[2]</font><br>
						 <font size=\"2\"><b>$row[3]</b></font>
						</td>
					";
               echo "<td align=right valign=top>
						<a href=\"mailto:$row[4]\"><img src=\"email.gif\" border=0 alt=\"$row[3]'s email\"></a>";
			            if (trim($row[6]) <> "" && trim($row[6]) <> "http://") {
                           if (ereg("^http://", trim($row[6]))) echo " <a href=\"$row[6]\" TARGET=\"_blank\"><img src=\"homepage.gif\" border=\"0\" alt=\"$row[3]'s homepage\"></a>";
                           else echo " <a href=\%22http:/$row[6]\%22 TARGET=\"_blank\"><img src=\"homepage.gif\" border=\"0\" alt=\"$row[3]'s homepage\"></a>";
			            }
			   echo "</td></tr></table>";
			   echo "<br><table border=\"0\" width=\"100%\">
			         <tr><td width=\"5\">&nbsp;</td><td>
			         <font size=\"2\" face=\"$message_font_face\" size=\"$message_font_size\">$row[5]</font>
					 </td></tr>
                     </table>
			        ";
			   echo "</td>";
			   echo "<td valign=\"top\" bgcolor=\"$warna2\" align=\"center\" width=\"15\">
			         <a href=\"$PHP_SELF?do=del&id=$row[1]&page=$page\">
					 <img src=\"del.gif\" alt=\"Delete entry # $no\" border=0 align=\"center\"></a>
					 </td>
					 </tr>";
			} //--end if		
        } //--end for
      echo "<tr><td colspan=\"3\" bgcolor=\"$table_bottom\" align=\"center\" width=\"600\"><font size=\"1\">";	  	  
      if ($jml_page > 1) {	   
	   if ($page <> 1) echo "[<a href=\"$PHP_SELF?page=1\">Top</a>] "; else echo "[Top] "; 
	   echo "Page # ";
       if ($jml_page > 10) {
	 	 if ($page < 5) {
		    $start = 1;
			$stop = 10;
		 } elseif ($jml_page - $page < 5) {
		    $start = $jml_page - 9;
			$stop = $jml_page;
		 } else {
		    $start = $page-4;
			$stop = $page+5;
		 }
		 if ($start <> 1) echo "... ";
         for ($p=$start; $p<=$stop; $p++) {
	         if ($p == $page) echo "<font color=\"$active_link\"><b>$p</b></font>&nbsp;&nbsp;";
			 else echo "<a href=\"$PHP_SELF?page=$p\">$p</a>&nbsp;&nbsp;";
         }
		 if ($stop <> $jml_page) echo "... ";		 		 
		 echo "of $jml_page ";
       } else {
         for ($p=1; $p<=$jml_page; $p++) {
	         if ($p == $page) echo "<font color=\"$active_link\"><b>$p</b></font>&nbsp;&nbsp;";
			 else echo "<a href=\"$PHP_SELF?page=$p\">$p</a>&nbsp;&nbsp;";
         }
	   }	   
       if ($page <> $jml_page) echo "[<a href=\"$PHP_SELF?page=$jml_page\">Bottom</a>]"; else echo "[bottom]"; 
      } else echo "Page #1 of 1";        
	  echo "</font></td></tr>";
?>
        </table>        
		</td>
		</tr>
		</table><br><br>

   
   </center>
   </body>
   </html>
<?
break;
case "add_form":
?>
<!-- For advanced user : customize your form here, but don't change both the name and value -->
<html>
<head>
<title><?=$title?></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="<?=$background?>" style="font-family:<?=$font_face?>">
<div align="center"> 
  <font size="5" color="<?=$title_color?>"><b><?=$title?></b></font><br>
  <font size="1"><b><a href="<?=$home?>"><font color="<?=$title_color?>">Home</font></a> :: <a href="<?=$PHP_SELF?>"><font color="<?=$title_color?>">View entry</font></a></b></font>
  <form method="post" action="<?=$PHP_SELF?>">
  <input type="hidden" name="do" value="add">
    <table width="460" border="0" cellspacing="0" cellpadding="0" bgcolor="<?=$table_border?>">
      <tr>
      <td>
        <div align="center">
            <table width="100%" border="0" cellspacing="1" cellpadding="5">
              <tr bgcolor="<?=$table_content_1a?>"> 
                <td width="28%"> 
                  <div align="right"><font size="2">*Bots Name : </font></div>
                </td>
                <td width="72%"> 
                  <input type="text" name="vname" size="30" maxlength="70">
                </td>
              </tr>
              <tr bgcolor="<?=$table_content_1a?>"> 
                <td width="28%"> 
                  <div align="right"><font size="2">*Email : </font></div>
                </td>
                <td width="72%"> 
                  <input type="text" name="vemail" size="30" maxlength="100">
                </td>
              </tr>
              <tr bgcolor="<?=$table_content_1a?>"> 
                <td width="28%"> 
                  <div align="right"><font size="2">Website : </font></div>
                </td>
                <td width="72%"> 
                  <input type="text" name="vurl" size="30" maxlength="150" value="http://">
                </td>
              </tr>
              <tr bgcolor="<?=$table_content_1a?>"> 
                <td valign="top" width="28%"> 
                  <div align="right"><font size="2">*Comment : </font></div>
                </td>
                <td width="72%"> 
                  <textarea name="vcomment" cols="40" rows="7" wrap="virtual"></textarea><br><font size="1">* Required field</font>
                </td>
              </tr>
              <tr bgcolor="<?=$table_content_1b?>"> 
                <td colspan="2"> 
                  <div align="center">
                    <font size="2">
                    <input type="submit" value="Submit">
                    <input type="reset" value="Reset">
					<input type="button" value="Back" onclick="window.location='<?="$PHP_SELF?page=$page"?>'">
                    </font>
				   </div>
                </td>
              </tr>
            </table>
        </div>
      </td>
    </tr>
  </table>
  </form>
</div>
</body>
</html>
<!-- End of entry form -->
<?
break;
case "add":
   $vname = isset($_POST['vname']) ? trim($_POST['vname']) : "";
   $vemail = isset($_POST['vemail']) ? trim($_POST['vemail']) : "";
   $vurl = isset($_POST['vurl']) ? trim($_POST['vurl']) : "";
   $vcomment = isset($_POST['vcomment']) ? trim($_POST['vcomment']) : "";

   if (strlen($vname) > 70) $vname = substr($vname,0,70);
   if (strlen($vemail) > 100) $vemail = substr($vemail,0,100);
   if (strlen($vurl) > 150) $vurl = substr($vurl,0,150);

   if ($vname=="" or $vcomment=="" or $vemail=="") {
      echo "<html><body bgcolor=\"#ffffff\" style=\"font-family:$font_face\"><h3>Error !</h3><font size=\"2\">You may left some fields. Please click <b><a href=\"javascript:history.back()\">here</a></b> and try again.</font></body></html>";
	  exit;
   }

   if (trim($vurl) <> "") {
	  if (strtolower(trim($vurl)) <> "http://") {
         if (!preg_match ("#^http://[_a-z0-9-]+\\.[_a-z0-9-]+#i", $vurl)) {
		    echo "<html><body bgcolor=\"#ffffff\" style=\"font-family:$font_face\"><h3>Error !</h3><font size=\"2\">Invalid URL format. Please click <b><a href=\"javascript:history.back()\">here</a></b> and try again.</font></body></html>";
	        exit;
          }
      }
   }

   $test_comment = explode(" ",$vcomment);
   $jmltest = count($test_comment);
   for ($t=0; $t<$jmltest; $t++) {
      if (strlen(trim($test_comment[$t])) > 35) {
        echo "<html><body bgcolor=\"#ffffff\" style=\"font-family:$font_face\"><h3>Error!</h3><font size=\"2\">Please don't abuse the form. Click <b><a href=\"javascript:history.back()\">here</a></b> and try again.</font></body></html>";
	    exit;	     
	  }
   }

   //--only 2000 characters allowed for comment, change this value if necessary
   $maxchar = 2000;
   if (strlen($vcomment) > $maxchar) $vcomment = substr($vcomment,0,$maxchar)."...";

   $idx = date("YmdHis");
   $tgl = date("F d, Y - h:i A");

   $vname = str_replace("<","",$vname);
   $vname = str_replace(">","",$vname);
   $vname = str_replace("~","-",$vname);
   $vname = str_replace("\"",""",$vname);

   $vcomment = str_replace("<","<",$vcomment);
   $vcomment = str_replace(">",">",$vcomment);
   $vcomment = str_replace("~","-",$vcomment);
   $vcomment = str_replace("\"",""",$vcomment);

   $vurl = str_replace("<","",$vurl);
   $vurl = str_replace(">","",$vurl);
   $vurl = str_replace("|","",$vurl);

   if (strtoupper($os) == "WIN") {
	   $vcomment = str_replace("\r\n","<br>",$vcomment);
	   $vcomment = str_replace("\r","",$vcomment);
	   $vcomment = str_replace("\n","",$vcomment);
   } else {
	   $vcomment = str_replace("\n","<br>",$vcomment);
	   $vcomment = str_replace("\r","",$vcomment);
   }

   $ipnum = getenv("REMOTE_ADDR");

   $newdata = "|~|$idx|~|$tgl|~|$vname|~|$vemail|~|$vcomment|~|$vurl|~|$ipnum|~|\n";
   $newdata = stripslashes($newdata);

   $bagus = true;
   $cekdata = file($data_file);
   $jmlcekdata = count($cekdata);
   if ($jmlcekdata > 0) {
      rsort($cekdata);
      if ($jmlcekdata > 2) {
         $newrow = explode("|~|",$newdata);
	     $jmlentry = 0;
         for ($c=0; $c<3; $c++) {
             $cekrow = explode("|~|",$cekdata[$c]);
             if ($cekrow[4] == $newrow[4] || ($cekrow[3] == $newrow[3] && $cekrow[4] == $newrow[4])) {
				 $jmlentry++;
			 }
	     }
         $bagus = ($jmlentry < 3) ? true : false;
      }
   }

   if ($bagus) {
	  $tambah = fopen($data_file,"a");
      if (strtoupper($os)=="UNIX") {
         if (flock($tambah,LOCK_EX)) {
	        fwrite($tambah,$newdata);
	        flock($tambah,LOCK_UN);
         }
      } else {
	     fwrite($tambah,$newdata);
      }
      fclose($tambah);

      //--SEND MAIL
      if (strtoupper($notify) == "YES") {
         $msgtitle = "Someone Entered The Contest";
         $vcomment = str_replace(""","\"",$vcomment);   
         $vcomment = stripslashes($vcomment);
	     $vcomment = str_replace("<br>","\n",$vcomment);
         $msgcontent = "Local time : $tgl\n\nThe addition from $vname :\n----------------------------\n\n$vcomment\n\n-----End Message-----";
         @mail($admin_email,$msgtitle,$msgcontent,"From: $vemail\n");
      }
   }

   echo "<html><meta http-equiv=\"refresh\" content=\"1; url=$PHP_SELF\"><body bgcolor=\"#ffffff\" style=\"font-family:$font_face\"><center><h3>Thank you, your entry has been added.</h3>Please wait...</center></body></html>";
break;

case "del":
   $record = file($data_file);
   $jmlrec = count($record);
   for ($i=0; $i<$jmlrec; $i++) {
       $row = explode("|~|",$record[$i]);
	   if ($id == $row[1]) {
	      echo "
		  <html><head><title>Delete record</title></head>
		  <body bgcolor=\"$background\" style=\"font-family:$font_face\">
		  <center>
		  <font size=\"4\" color=\"$title_color\">Delete Confirmation</font>
		  <br><br>
		  <table border=\"0\" cellpadding=\"5\" cellspacing=\"1\" width=\"450\">
			<tr>
			<td bgcolor=\"$table_top\">
            <font size=\"2\">
			<font size=\"1\"><b>$row[2]</font><br>$row[3]</b> - <a href=\"mailto:$row[4]\">$row[4]</a><br><br>$row[5]
			<br><br><font size=\"1\">IP : $row[7]</font>
			</font> 
			</td>
			</tr>
		  </table>
		  ";
	      break;
	   }
   }   
   echo "<form action=\"$PHP_SELF\" method=\"post\"><font color=\"$title_color\" size=\"2\"><b>Admin password : </b></font><input type=\"password\" name=\"pwd\"><input type=\"hidden\" name=\"do\" value=\"del2\"><br><br><font size=\"2\" color=\"$title_color\"><b>&raquo;</b><input type=\"checkbox\" name=\"byip\" value=\"$row[7]\"> Delete all record that using this IP : $row[7]</font><br><br><input type=\"submit\" value=\"Delete\"> <input type=\"button\" value=\"Cancel\" onclick=\"window.location='$PHP_SELF?page=$page'\"><input type=\"hidden\" name=\"id\" value=\"$id\"><input type=\"hidden\" name=\"page\" value=\"$page\"></FORM></center></body></html>";
break;

case "del2":
   $pwd = isset($_POST['pwd']) ? trim($_POST['pwd']) : "";
   $id = isset($_POST['id']) ? trim($_POST['id']) : "";
   $page = isset($_POST['page']) ? $_POST['page'] : 1;
   $byip = isset($_POST['byip']) ? $_POST['byip'] : "";

   if ($pwd <> $admin_password) {
         echo "<html><head><meta http-equiv=\"refresh\" content=\"1; url=$PHP_SELF?page=$page\"></head><body bgcolor=\"#ffffff\" style=\"font-family:$font_face\"><center><h3>Invalid admin password !</h3>Please wait...</center></body><html>";
         exit;
   }

   $record = file($data_file);
   $jmlrec = count($record);
   for ($i=0; $i<$jmlrec; $i++) {
       $row = explode("|~|",$record[$i]);
	   if ($byip == "") {
		   if ($row[1] == $id) {
			   $record[$i] = "";
		       break;
	       }
	   } else {
		   if ($row[7] == $byip) {
			   $record[$i] = "";
		   }
	   }
   }

   $update_data = fopen($data_file,"w");
   if (strtoupper($os) == "UNIX") {
      if (flock($update_data,LOCK_EX)) {
	     for ($j=0; $j<$jmlrec; $j++) {
             if ($record[$j] <> "") {
				 fputs($update_data,$record[$j]);
			 }
		 }
		 flock($update_data,LOCK_UN);
	  }
   } else {
	     for ($j=0; $j<$jmlrec; $j++) {
             if ($record[$j] <> "") {
				 fputs($update_data,$record[$j]);
			 }
		 }
   }
   fclose($update_data);

   echo "<html><head><meta http-equiv=\"refresh\" content=\"1; url=$PHP_SELF?page=$page\"></head><body bgcolor=\"#EAEAEA\" style=\"font-family:$font_face\"><center><h3>Record has been deleted !</h3>Please wait...</center></body><html>";
break;
} //--end switch
?>

feyd | Please review how to post code using

Code: Select all

and

Code: Select all

tags. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Sun Mar 27, 2005 2:16 pm
by feyd
Lines 283 through 286 in the original post were the email validation lines. What do you consider email validation?

Read the posting code guidelines, please.

Same Topic

Posted: Sun Mar 27, 2005 2:21 pm
by Bob Norris
Sorry,,

I always screw up when I join a new forum till I get going.

When you use the forum: http://www.cyberoperator.com/cbc/comments/index.php
It requires the user to input and email or it wont work. I would like to forgo email from being mandatory field. Thank you again Sir

Posted: Sun Mar 27, 2005 6:57 pm
by feyd
okay, that's a somewhat different thing all together.. using the originally posted code, edit line 278. Remove the part of the expression in the if involving $vemail being equal to a empty string. Keep lines 283 through 286, but add to the if expression (on the leading edge)

Code: Select all

$vemail != '' and