icon Get the most out of Surmunity, read our tips here! Need an interesting blog to read? You've got to read the Surpass Blog! | Welcome! Please register to access all of our features.
Old October 30th, 2007, 11:26 PM   #1 (permalink)
wgm
Registered User
Super #1
 
Joined in Mar 2005
Lives in Washougal, WA
1,302 posts
Gave thanks: 23
Thanked 39 times
Calling MarkRH

In regards to this PHP Random Text

Having a bit of trouble implementing the code you posted, your assistance would be greatly appreciated, thanks.

Have a separate file named imgver.php in place.

Form is here http://www.wmcintosh.com/contact.php

email.php
Code:
<?php 

if($_SERVER['REQUEST_METHOD'] == "POST") {

$receiverMail= "email removed";

$name= trim(strip_tags(stripslashes($_POST['name'])));
$email= trim(strip_tags(stripslashes($_POST['email'])));
$subject= trim(strip_tags(stripslashes($_POST['subject'])));
$msg= trim(strip_tags($_POST['msg']));
$code = trim(strip_tags(stripslashes($_POST['code'])));

$ip= getenv("REMOTE_ADDR");
$msgformat= "From: $name ($ip)\nEmail: $email\n\n$msg";

// VALIDATION
if(empty($name) || empty($email) || empty($subject) || empty($msg) || empty($code)) {
  echo '<div class="error">Unable to send email: missing field or fields.</div>';
}
elseif(!ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {
  echo '<div class="error">Unable to send email: invalid email address.</div>';
}else{
mail($receiverMail, $subject, $msgformat, "From: $name <$email>");
  echo '<div class="success">Email sent successfully. Thank you.</div>';
}
}

?>
Contact form...
Code:
<form action="http://www.wmcintosh.com/contact.php" method="post">
<table border="0" align="center" cellpadding="2" cellspacing="0" width="75%">
<tr>
<td colspan="2" align="center" valign="middle"><?php include('xxxxxxxx/email.php'); ?></td><tr>
<td align="right" valign="middle"><b>Name:</b></td><td align="left"><input type="text" name="name" size="50" class="input" value="<?php echo $_POST['name']; ?>"></td><tr>
<td align="right" valign="middle"><b>Email:</b></td><td align="left"><input type="text" name="email" size="50" class="input" value="<?php echo $_POST['email']; ?>"></td><tr>
<td align="right" valign="middle"><b>Subject:</b></td><td align="left"><input type="text" name="subject" size="50" class="input" value="<?php echo $_POST['subject']; ?>"></td><tr>
<td align="right" valign="top"><b>Comment:</b></td><td align="left"><textarea rows="8" cols="38" name="msg" class="input"><?php echo $_POST['msg']; ?></textarea></td><tr>
<td align="right" valign="middle"><b>Verify:</b></td><td align="left"> [like img or text to be here] <input type="text" name="code" size="10" class="input" value="<?php echo $_POST['code']; ?>"></td><tr>
<td align="right" valign="middle"><br /></td><td align="left"><input type="submit" style="width: 100px;" value="Send!"> <?php echo $txt['contactformnote']; ?></td><tr>
<td align="right" valign="middle"><br /></td><td align="left"><br /></td>
</tr>
</table>
</form>
Probably or most likely going about it all wrong.
wgm is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old October 31st, 2007, 9:40 AM   #2 (permalink)
wgm
Registered User
Super #1
 
Joined in Mar 2005
Lives in Washougal, WA
1,302 posts
Gave thanks: 23
Thanked 39 times
I combined contact form with email.php together if that makes it easier to implement, easy to switch back if necessary (as posted above).

Code:
<?php echo '<form action="http://www.wmcintosh.com/contact.php" method="post">
      <table border="0" align="center" cellpadding="2" cellspacing="0" width="75%">
      <tr>
      <td colspan="2" align="center" valign="middle">';
      
      if($_SERVER['REQUEST_METHOD'] == "POST") {
      
      $receiverMail= "my email removed";
      
      $name= trim(strip_tags(stripslashes($_POST['name'])));
      $email= trim(strip_tags(stripslashes($_POST['email'])));
      $website = trim(strip_tags($_POST['website']));
      $subject= trim(strip_tags(stripslashes($_POST['subject'])));
      $msg= trim(strip_tags($_POST['msg']));
      $code = trim(strip_tags(stripslashes($_POST['code'])));
      
      $ip= getenv("REMOTE_ADDR");
      $msgformat= "From: $name ($ip)\nEmail: $email\nWebsite: $website\n\n$msg";
            
      // VALIDATION
      if(empty($name) || empty($email) || empty($subject) || empty($msg)) {
        echo '<div class="error">Unable to send email: missing field or fields.</div>';
      }
      elseif(!ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {
        echo '<div class="error">Unable to send email: invalid email address.</div>';
      }else{
      mail($receiverMail, $subject, $msgformat, "From: $name <$email>");
        echo '<div class="success">Email sent successfully. Thank you.</div>';
      }
      } echo '</td><tr>
      <td align="right" valign="middle"><br></td><td align="left">' . $txt['contactformnote'] . '</td><tr>
      <td align="right" valign="middle"><b>Name:</b></td><td align="left"><input type="text" name="name" size="50" class="input" value="' . $_POST['name'] . '"></td><tr>
      <td align="right" valign="middle"><b>Email:</b></td><td align="left"><input type="text" name="email" size="50" class="input" value="' . $_POST['email'] . '"></td><tr>
      <td align="right" valign="middle">Website:</td><td align="left"><input type="text" name="website" size="50" class="input" value="' . $_POST['website'] . '"></td><tr>
      <td align="right" valign="middle"><b>Subject:</b></td><td align="left"><input type="text" name="subject" size="50" class="input" value="' . $_POST['subject'] . '"></td><tr>
      <td align="right" valign="top"><b>Comment:</b></td><td align="left"><textarea rows="8" cols="38" name="msg" class="input">' . $_POST['msg'] . '</textarea></td><tr>
      <td align="right" valign="middle"><b>Verify:</b></td><td align="left">(verify been disabled)</td><tr>
      <td align="right" valign="middle"><br></td><td align="left"><input type="submit" style="width: 100px;" value="Send!" disabled="disabled"></td><tr>
      <td align="right" valign="middle"><br></td><td align="left"><br></td>
      </tr>
      </table>
      </form>' . "\n";
?>
This morning added Website field, playing and learning, but adding for the verification has me lost.
wgm is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old November 5th, 2007, 7:33 PM   #3 (permalink)
Race Surpass
Super #1
 
MarkRH's Avatar
 
Joined in Jul 2006
Lives in Oklahoma City, OK
Hosted on sh102
1,218 posts
Gave thanks: 18
Thanked 86 times
Sorry for taking so long to see this.. but in that portion of the contact form you need to add the code:
Code:
<P>
I am a human code (case sensitive): <IMG SRC="php/human_code.php" WIDTH="60" HEIGHT="20" BORDER="1" ALIGN="middle" ALT="human code"> (If you can't tell what some of the characters are, just reload the page by right-clicking somewhere on this  page and select the <STRONG>refresh</STRONG> menu option and let it generate a new sequence). 
</p>
The important bit is what's in the <IMG> tag. The human_code.php script is the one that generates the image. Of course, change the relative path and scriptname if your is different. The form on my website that uses this is www.markheadrick.com/addguest.htm

Inside your email.php script, add the following bit of verification code:

PHP Code:
$human_code stripslashes($_POST['code']); 

if (!isset(
$_SESSION['code'])) {
  
// do whatever needs to be done because the session variable does not exist.
  // most likely because a bot was trying to use the form and never called the human_code.php script
}

if (
$human_code != $_SESSION['code']) {
//  do whatever needs to be done if code does not match or was empty.  could have been
// a bot or a typo made by a person.

The basic premise is that when a human views the contact form, the human_code.php script randomly generates an image and sends the image to be displayed and stores that value in the session variable. The form processing script checks the code entered on the form against that session variable value to make sure they match.

Hopefully that's clear as mud.. brain's kinda fried after work.
MarkRH is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
This user thanks MarkRH for this great post!
wgm (November 5th, 2007)
Old November 5th, 2007, 9:47 PM   #4 (permalink)
wgm
Registered User
Super #1
 
Joined in Mar 2005
Lives in Washougal, WA
1,302 posts
Gave thanks: 23
Thanked 39 times
No problem MarkRH, you were either busy or doing something else, after all there if life beyond forums.

Been added http://www.wmcintosh.com/contact.php
Hope its works like it should (though I did reword it some, not the code).

I really appreciate the assistance, thank you.
wgm is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old November 10th, 2007, 7:17 PM   #5 (permalink)
wgm
Registered User
Super #1
 
Joined in Mar 2005
Lives in Washougal, WA
1,302 posts
Gave thanks: 23
Thanked 39 times
I tried to modify the code for random numbers and letters only.

What I was going for was to display 48 to 57, 65 to 90 and 97 to 122 randomly ( http://www.asciitable.com/ ), but failed in my attempts.

Thanks, any information would help.
wgm is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old November 10th, 2007, 8:14 PM   #6 (permalink)
Race Surpass
Super #1
 
MarkRH's Avatar
 
Joined in Jul 2006
Lives in Oklahoma City, OK
Hosted on sh102
1,218 posts
Gave thanks: 18
Thanked 86 times
Try this modified human_code.php:

PHP Code:
<?php
function randchr() {
    
$chr_array = array(chr(rand(48,57)), chr(rand(65,90)), chr(rand(97,122)) );
    return 
$chr_array[rand(0,2)];
}

    
session_start();

    
// generate random characters and output it as an image

    
$code randchr().randchr().randchr().randchr().randchr();
    
$im = @imagecreate(6020) or die("Cannot Initialize new GD image stream");
    
$background_color imagecolorallocate($im255255255);
    
$text_color imagecolorallocate($im2331491);
    
imagestring($im433,  $code$text_color);
    
$_SESSION['code'] = $code;
    
header("Content-type: image/gif");
    
imagegif($im);
    
imagedestroy($im);
?>
Hope it helps..
MarkRH is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
This user thanks MarkRH for this great post!
wgm (November 10th, 2007)
Old November 10th, 2007, 8:24 PM   #7 (permalink)
wgm
Registered User
Super #1
 
Joined in Mar 2005
Lives in Washougal, WA
1,302 posts
Gave thanks: 23
Thanked 39 times
Really really appreciate the help, thank you very much, appears to work just fine.

Okay I won't bug you anymore, just wish my brain would comprehend PHP more.
wgm is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On