forked from Gregwar/Captcha
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
// We need the session to check the phrase after submitting | ||
session_start(); | ||
?> | ||
|
||
<html> | ||
<?php | ||
if ($_SERVER['REQUEST_METHOD'] == 'POST') { | ||
// Checking that the posted phrase match the phrase stored in the session | ||
if (isset($_SESSION['phrase']) && $_SESSION['phrase'] === $_POST['phrase']) { | ||
echo "<h1>Captcha is valid !</h1>"; | ||
} else { | ||
echo "<h1>Captcha is not valid!</h1>"; | ||
} | ||
// The phrase can't be used twice | ||
unset($_SESSION['phrase']); | ||
} | ||
?> | ||
<form method="post"> | ||
Copy the CAPTCHA: | ||
<?php | ||
// See session.php, where the captcha is actually rendered and the session phrase | ||
// is set accordingly to the image displayed | ||
?> | ||
<img src="session.php" /> | ||
<input type="text" name="phrase" /> | ||
<input type="submit" /> | ||
</form> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
// We need the session to store the correct phrase for later check | ||
session_start(); | ||
|
||
// Including the autoload (you need to composer install in the main directory) | ||
require_once __DIR__.'/../vendor/autoload.php'; | ||
|
||
use Gregwar\Captcha\CaptchaBuilder; | ||
|
||
// Creating the captcha instance and setting the phrase in the session to store | ||
// it for check when the form is submitted | ||
$captcha = new CaptchaBuilder; | ||
$_SESSION['phrase'] = $captcha->getPhrase(); | ||
|
||
// Setting the header to image jpeg because we here render an image | ||
header('Content-Type: image/jpeg'); | ||
|
||
// Running the actual rendering of the captcha image | ||
$captcha | ||
->build() | ||
->output() | ||
; |