Results 1 to 8 of 8
Thread: PHP Session Captcha
Hybrid View
-
26th June 2008 11:37 #1Registered User
Join Date: Jul:2006
Location:
Posts: 1,071
PHP Session Captcha
captcha . . icn.bg. , Set- security_code (, $_POST).
, , , ? - ?
, , :
, else, .. $_SESSION.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>"; }
:
- php , captcha session_start();
- Cookie- .
- Cookie-, PHPSESSID = .
-
26th June 2008 12:32 #2
, .
" ", :
security_code ?Code:$_SESSION['security_code'] = $code;
1. , .
2. print_r($_SESSION); die; security_code .Last edited by Skydive; 26th June 2008 at 12:38.
-
26th June 2008 18:13 #3Registered User
Join Date: Jul:2006
Location:
Posts: 1,071
, HTML-, :
captcha.php e (CaptchaSecurityImages.php), . captcha.zip , . , , ...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-->
-
, . ...
-
26th June 2008 18:25 #4
?
error_log ?PHP Code:session_start();
, , Captcha .- . - :<li> (cookies) .</em></li>
- $code.PHP Code:$_SESSION['security_code'] = $code;
-
26th June 2008 18:35 #5Registered User
Join Date: Jul:2006
Location:
Posts: 1,071
$code , , . , ( HTML , JS CSS). captcha.php , contacts.php .
-
26th June 2008 18:43 #6
-
26th June 2008 20:32 #7Registered 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:
.
Edit2:
, captcha.php include/ root ( ./ ) img , ... , .
, !
Last edited by mialy; 26th June 2008 at 20:59.
-
28th June 2008 13:00 #8
, " " .
, , PHP engine . .. , , , register_globals, magic_quotes_* .. PHP , - .
- , , . - Session, . , handle- ( ). , , , - . Session ( ), , .
PHP sucks ( ).




Reply With Quote

Lenovo ThinkPad 15 IdeaPad 15
5th May 2023, 22:16 in