Results 1 to 8 of 8

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date: Jul:2006
    Location:
    Posts: 1,071

    PHP Session Captcha

    captcha . . icn.bg. , Set- security_code (, $_POST).

    , , , ? - ?

    , , :
    Code:
    if(isset($_SESSION['security_code'])){
      if(empty($_POST['security_code'])) $error_msg .= "<li>   !</li>";
      else if($_SESSION['security_code'] != $_POST['security_code']) $error_msg .= "<li>   !</li>";
    } else {
      $error_msg .= "<li> (cookies)      .</em></li>";
    }
    , else, .. $_SESSION.

    :
    - php , captcha session_start();
    - Cookie- .
    - Cookie-, PHPSESSID = .

  2. #2
    relative dude Skydive's Avatar
    Join Date: Nov:2002
    Location: /
    Posts: 2,863
    , .

    " ", :
    Code:
    $_SESSION['security_code'] = $code;
    security_code ?
    1. , .
    2. print_r($_SESSION); die; security_code .
    Last edited by Skydive; 26th June 2008 at 12:38.

  3. #3
    Registered User
    Join Date: Jul:2006
    Location:
    Posts: 1,071
    , HTML-, :

    Code:
    <?php
       session_start();
    ?>
    <!-- html/head/body/etc -->
    <?php
      $name = "";
      $mail = "";
      $subject = "";
      $message = "";
      $error_msg = "";
    
      print_r($_SESSION);//       ,    - 
      
      if(!empty($_POST['submit'])){
        if(empty($_POST['name']) || strlen(trim($_POST['name'])) <= 5){
          $error_msg .= "<li>      !</li>";
        } else $name = $_POST['name'];
    
        if(empty($_POST['email']))
          $error_msg .= "<li>       !</li>";
        else if(!preg_match( '/[.+a-zA-Z0-9_-]+@[a-zA-Z0-9-]+.[a-zA-Z]+/', $_POST['email']))
          $error_msg .= "<li>      !</li>";
        else 
          $mail = $_POST['email'];
    
        if(empty($_POST['subject']) || strlen(trim($_POST['subject'])) <= 5){
          $error_msg .= "<li>   !</li>";
        } else { $subject = $_POST['subject']; }
        
        if(empty($_POST['message']) || strlen(trim($_POST['message'])) <= 5){
          $error_msg .= "<li>        !</li>";
        } else { $message = $_POST['message']; }
        
        if(isset($_SESSION['security_code'])){
          if(empty($_POST['security_code'])) $error_msg .= "<li>   !</li>";
          else if($_SESSION['security_code'] != $_POST['security_code']) $error_msg .= "<li>   !</li>";
        } else {
          $error_msg .= "<li> (cookies)      .</em></li>";
        }
    
        unset($_SESSION['security_code']);
    
        if(strlen($error_msg) > 0){
          echo '   :<ul>'.$error_msg.'</ul>';
        } else {
          $headers = "From: " . $name . " <" . $mail . ">\r\n";
          $headers .= "MIME-Version: 1.0 \r\n";
          $headers .= "Content-Type: text/plain; charset=windows-1251; \r\n";
    
          if(!@mail($mailto, $subject, $message, $headers)){
            echo '     !';
          } else { 
            echo '   !';
          }
    
          $subject = "";
          $message = ""; 
        }
      } else {
        $name = "";
        $mail = "";
        $subject = "";
        $message = "";
      }
    
    ?>
              <form method="post" action="./contacts.php" onsubmit="return checkForm(this)" >
                <table>
                  <tr>
                    <td> :</td>
                    <td>
                      <input name="name" type="text" maxlength="40" value="<?php echo $name; ?>" />
                    </td>
                  </tr>
                  <tr>
                    <td> .:</td>
                    <td><input name="email" type="text" maxlength="40" value="<?php echo $mail; ?>" /></td>
                  </tr>
                  <tr>
                    <td> ():</td>
                    <td><input name="subject" type="text" maxlength="40" value="<?php echo $subject; ?>" /></td>
                  </tr>
                  <tr>
                    <td colspan="2"><textarea name="message" cols="40" rows="8"><?php echo $message; ?></textarea></td>
                  </tr>
                  <tr>
                    <td> :</td>
                    <td><img src="./include/captcha.php" />
                         <input id="security_code" name="security_code" type="text" maxlength="6" /></td>
                  </tr>
                  <tr>
                    <td colspan="2">
                     <input name="submit" value="" id="submit" type="submit" /></td>
                  </tr>
                </table>
    <!-- body/html etc-->
    captcha.php e (CaptchaSecurityImages.php), . captcha.zip , . , , ...

    - , . ...

  4. #4
    White awesomeness z0ne's Avatar
    Join Date: Feb:2002
    Location: o
    Posts: 13,331
    ?

    PHP Code:
    session_start(); 
    error_log ?
    <li> (cookies) .</em></li>
    , , Captcha .- . - :

    PHP Code:
    $_SESSION['security_code'] = $code
    - $code.

  5. #5
    Registered User
    Join Date: Jul:2006
    Location:
    Posts: 1,071
    $code , , . , ( HTML , JS CSS). captcha.php , contacts.php .

  6. #6
    White awesomeness z0ne's Avatar
    Join Date: Feb:2002
    Location: o
    Posts: 13,331
    print_r($_SESSION);// , -
    .

  7. #7
    Registered User
    Join Date: Jul:2006
    Location:
    Posts: 1,071
    .

    contacts.php , , , root-a - . , captcha.zip - form.php - .

    .
    contacts.php $_SESSION['bla'] = "blabla"; session_start();, print_r($_SESSION);, , .. . captcha.php contacts.php, img , .

    ?

    -------
    root public_html/

    Edit:
    Quote Originally Posted by mialy View Post
    -
    .

    Edit2:
    , captcha.php include/ root ( ./ ) img , ... , .

    , !
    Last edited by mialy; 26th June 2008 at 20:59.

  8. #8
    Registered User tedych's Avatar
    Join Date: Nov:2003
    Location:
    Posts: 17,654
    , " " .
    , , PHP engine . .. , , , register_globals, magic_quotes_* .. PHP , - .
    - , , . - Session, . , handle- ( ). , , , - . Session ( ), , .
    PHP sucks ( ).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Copyright © 1999-2011 . .
iskamPC.com | mobility.BG | Bloody's Techblog | | 3D Vision Blog |