how to add short code of captcha in template page in wordpress - captcha

I have used wordpress plugin captcha and I create contact form with html. how I can use this captcha shortcode in html form. Is it possible to use this captcha shortcode in html form

Here is a simple one;
Save the following code as captcha.php
<?php
session_start();
$md5_hash = md5(rand(0,9999));
$security_code = substr($md5_hash, 25, 5);
$enc=md5($security_code);
$_SESSION['count'] = $enc;
$secure = $_SESSION['count'];
// echo "--------------------------$secure<br>";
$width = 100;
$height = 40;
$image = ImageCreate($width, $height);
$white = ImageColorAllocate($image, 255, 255, 255);
$black = ImageColorAllocate($image, 0, 100, 0);
$grey = ImageColorAllocate($image, 204, 204, 204);
ImageFill($image, 0, 0, $grey);
//Add randomly generated string in white to the image
ImageString($image, 10, 30, 10, $security_code, $black);
ImageRectangle($image,0,16,$width-1,$height-1,$grey);
imageline($image, 0, $height/2, $width, $height/2, $grey);
imageline($image, $width/2, 0, $width/2, $height, $grey);
header("Content-Type: image/jpeg");
ImageJpeg($image);
ImageDestroy($image);
ImageDestroy($image);
?>
save the following file as index.php
<?php
#session_start();
#$key=$_SESSION['count'];
if (isset($_POST['submit'])) {
$imag = $_POST['captcha'];
$captcha = md5($imag);
//echo "$imag = = = $key<br>";
if($captcha==$key)
{
echo "true";
}
else{
echo "false";
}
}
?>
<html>
<head>
<title>Captcha Sample</title>
</head>
<body>
<img name="" src="captcha.php" width="180" height="53" alt="">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="text" value="" id="captcha" name="captcha">
<input type="submit" name="submit" id="submit" value="Submit">
</form>
</body>
</html>
From the example above, the captcha.php file is included in the index.php file and it will produce an image captcha which is random. If the user enters a correct captcha as displayed in the image, it will return True else False.

Related

Bootstrap 4.3.1 dropdown login form redirect upon success

I am building a site where users can login via a Bootstrap Dropdown, i did have it working, it would log user in and refresh the whole page with login session BUT if user entered wrong creds it wouldn't stay open and alert them. I got around this by putting the login form in an iframe in the dropdown but it's no longer starting the session - any ideas please? I'm trying to not be vague so here is the code in the iframe and the actual URL below that - thank you :)
<div class="header_login_form_dropdown">Login</div>
<form name="login" action="" method="post" class="form">
<div class="form-group">
<label class="login_form_dropdown" for="lopc_username">Email</label>
<input type="email" class="form-control" id="lopc_username" placeholder="email#company.com" name="lopc_username">
</div>
<div class="form-group">
<label class="login_form_dropdown" for="lopc_password">Password</label>
<input type="password" class="form-control" id="lopc_password" name="lopc_password">
</div>
Forgot password
<button type="submit" name="submit" class="btn btn-primary login_btn">LOGIN</button>
<div style="padding:15px 0 15px 0; border-top: 2px solid #eee; font-size: 14px; color: #696969">
New customer? Register here
</div>
<?php
if (isset($_POST['submit']))
{
include('../265451/92631043.php');
$lopc_username = mysqli_real_escape_string($conn,$_POST['lopc_username']);
$lopc_password = mysqli_real_escape_string($conn,(md5($_POST['lopc_password'])));
$lopc_last_login = date("Y-m-d H:i:s");
$query = "SELECT * FROM lopc_reg_users WHERE lopc_username = '$lopc_username' AND lopc_password = '$lopc_password' ";
$result = mysqli_query($conn,$query);
if(mysqli_num_rows($result) == 1)
{
$_SESSION['lopc_username'] = $_POST['lopc_username'];
$lopc_username = $_SESSION['lopc_username'];
$query2 = "UPDATE lopc_reg_users SET lopc_last_login = '$lopc_last_login' WHERE lopc_username = '$lopc_username' ";
$result2 = mysqli_query($conn,$query2);
//header("Location: ".$_SERVER['PHP_SELF']);
?>
<script>
window.parent.location.reload();
</script>
<?php
exit;
}
else
{
echo '<div class="login_error">Username or password does not exist.</div>';
}
}
?>
</form>
https://littleorangeprinting.co.uk/2021
Login: test#test.com
Pass: testing4321

ReactPHP --> File upload --> $request->getUploadedFiles() returns empty array

I'm learning ReactPHP with the Book «ReactPHP for Beginners».
Everything worked fine, but now I'm on the section with file uploads.
There is a simple html form:
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8" />
<title>ReactPHP App</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" />
</head>
<body>
<div class="container">
<div class="row">
<form action="/upload" method="post" enctype="multipart/form-data" class="justify-content-center">
<div class="form-group">
<label for="file">Submit a file:</label>
<input type="file" name="file" id="file" accept="image/x-png,image/jpeg" />
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
</div>
</body>
</html>
And the PHP Code witch receives the form data ist also very simple:
<?php
use Psr\Http\Message\ServerRequestInterface;
use React\EventLoop\LoopInterface;
use React\ChildProcess\Process;
use React\Http\Message\Response;
return [
'/' => function(ServerRequestInterface $request, LoopInterface $loop) {
$childProcess = new Process('cat pages/index.html', __DIR__);
$childProcess->start($loop);
return new Response(
200,
['Content-Type' => 'text/html'],
$childProcess->stdout
);
},
'/upload' => function (ServerRequestInterface $request, LoopInterface $loop) {
$files = $request->getUploadedFiles();
$file = $files['file'];
print_r($file);
return new Response(
200, ['Content-Type' => 'text/plain'], ''
);
}
];
If I choose a JPG-File and click «Submit», $request->getUploadedFiles() always returns an empty array. What's wrong here? I work on Mac OS X (10.15.7) and I tried with different browsers.
It looks like that server needs additional middlewares setup to properly handle file upload. You have to import it from React\Http\Middleware\ namespace.
$server = new Server($loop,
new StreamingRequestMiddleware(),
new RequestBodyBufferMiddleware(8 * 1024 * 1024), // 8 MiB
new RequestBodyParserMiddleware(8 * 1024 * 1024, 1), // 8 MiB
function (ServerRequestInterface $request) use ($router) {
return $router($request);
});
Those additional midlewares are specific for the web browser as long as ReactPHP is able to handle file upload if we are using curl, e.g.
$ curl --form file=#some_file_that_we_are_going_to_upload http://0.0.0.0:8080/upload
Please have in mind that path and port are related to example from book „ReactPHP for Beginners”

Why do I keep seeing the undefined index error for line 13 ('file')?

I am trying to create a simple drag and drop page using php. When I click the "submit" button, I get an error: Notice: Undefined index: file in C:\xampp\htdocs\phpfiles\DragAndDrop\includes\gallery-upload.inc.php on line 13. Why is it not reading the "file" index from the htmlphp?
Here is the HTML and PHP code:
enter code here
<!--continuted from HTML page-->
</section>
<?php
$_SESSION['username'] = "Admin";
if (isset($_SESSION['username'])) {
echo '<div class="gallery-upload">
<form action="includes/gallery-upload.inc.php" method="post" enctype="mutipart/form-data">
<input type="text" name="filename" placeholder="File Name...">
<input type="text" name="filetitle" placeholder="Image Title...">
<input type="text" name="filedesc" placeholder="Image description...">
<input type="file" name="file">
<button type="submit" name="submit">Upload</button>
</form>
</div>';
}
?>
</main>
</body>
</html>
<!--and the php page-->
<?php
if (isset($_POST['submit'])) {//checks submit form and posts the info
$newFileName = $_POST['filename'];
if (empty($_POST['filename'])) { //if filename is emptly
$newFileName = "gallery"; //if filename is empty, generates name
} else {
$newFileName = strtolower(str_replace(" ", "-", $newFileName)); //if spaces are in the name, creates stringholder
}
$imageTitle = $_POST['filetitle'];
$imageDesc = $_POST['filedesc'];
$file = $_FILES['file'];
}
?>
You have a typo:
mutipart/form-data
Should be
multipart/form-data

Placement of Login code to website using Facebook account

Hi I'm new to web development. I would like to code for Login to website using Facebook account which I know that I need to add this js to install the Facebook SDK:
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'your-app-id',
xfbml : true,
version : 'v2.4'
});
};
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
However, I'm unsure on where to put it. It was mentioned that I should insert it directly after the opening <body> tag on each page I want to load it. However, Both of my register and login.php were done in floating div. There's no <body> tag. Hence, I not sure where to add this code in too:
<?php
if(!isset($_SESSION))
{
session_start();
}
require_once('config.php');
require_once('facebook.php');
require_once('PHPMailer/PHPMailerAutoload.php');
$facebook = new Facebook($config);
$fbUser = $facebook->getUser();
$_SESSION[$PROJECT_NAME . '-allowUser'] = true;
$uri = explode('/', strtok($_SERVER["REQUEST_URI"],'?'));
if ($fbUser) {
$user_profile = $facebook->api('/me');
$fbEmail = $user_profile["email"];
$fbId = $user_profile["id"];
}
Below is my login.php.
login.php
<div id="loginScreen">
<div class="xclose">
<em>×</em>
</div>
<div id="loghead">Facebook Connect</div>
<div class="articlepreview">
<form name="loginForm" method="post" id="registrationForm"
action="processLogin">
<div class="signintitle">Sign in to your Account</div>
<div class="form-group">
<input class="emailaddr" type="email" name="emailaddr" required
id="emailaddr" placeholder="Email Address"> <br> <input
type="password" name="password" required class="password"
id="id_password" placeholder=Password
<?php
if (preg_match ( "/^.*(?=.{8,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).*$/", $password )) {
echo "Your passwords is strong.";
} else {
echo "Your password is weak.";
}
?>
required>
</div>
<br>
<center>
<input class="greybtn" type="submit" value="Sign in" name="signin">
</center>
<div class="forgotpw" style="text-align: center;">
<br> Forgot Password? <br>
Create an Account <br>
</div>
</form>
</div>

How to add autocomplete data into invoice dynamically

I am looking for a way to add autocomplete data from my code to an "invoice" page automatically. I want the user to be able to also click to add or remove each item(quickbooks style, with multiple form fields available, and adding dynamically) and in the long run, be able to drag elements to a certain position in the invoice. All I am looking for now is this :
good : pseudocode on how to do this
best : basic working code to take off with.
This is what I have so far :
Page that calls the data :
<?php
require 'database.php';
require 'results.php';
if(!empty($_GET['wid'])) { $wid = $_GET['wid']; }
elseif(!empty($_POST['wid'])) { $wid = $_POST['wid']; }
else { $wid = null; }
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link href="css/bootstrap.min.css" rel="stylesheet">
<script src="js/bootstrap.min.js"></script>
<script src="js/jquery-1.9.1.min.js"></script>
<script src="js/engine.js"></script>
</head>
<body>
<div class="container-fluid">
<div class="span10 offset1">
<div class="row">
<h3>Add Item to Workorder</h3>
</div>
<form class="form-horizontal" action="additems.php" method="post">
<?php
// Add Custom Call for values from prior page ?>
<input type="hidden" name="wid" value="<?php echo htmlentities($wid); ?>">
<?php
//not required, but for get link purposes
if(isset($_POST['search']) && $_POST['search']!=''){
$search = $_POST['search'];
} elseif (isset($_GET['search']) && $_GET['search']!=''){
$search = $_GET['search'];
} else {
$search='';
}
//
echo"
<input type='text' class='search_input' name='search' id='search' placeholder='search' value='$search' autofocus>
<div id='search_output' class='search_output'>";
?>
Page that retrieves results :
<?php
require_once"database.php";//connection to database
$pdo = Database::connect();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
if(isset($_POST['search']) && $_POST['search']){
$search=$_POST['search'];
} elseif(isset($_GET['search']) && $_GET['search']){
$search=$_GET['search'];
}
if(isset($search)){
$search = '%' . strtr($search, ['%' => '\%', '_' => '\_']);
$search = str_replace(" ", "%", $search);
$search= "%$search%";
$sql="select * from products where `model` LIKE ? OR `category` LIKE ? OR `description` LIKE ? OR `subcategory` LIKE ? LIMIT 50;";
$statement = $pdo->prepare($sql);
$statement->execute([$search, $search, $search, $search]);
//configure for your custom data dump to autocomplete
echo "
<table class='table table-striped table-bordered' width='100%'>
<thead>
<tr>
<th>Model</th>
<th>Category</th>
<th>Description</th>
</tr>
</thead>
<tbody>
";
while($row = $statement->fetch()){
$item=$row['model'];
$title=$row['category'];
$description=$row['description'];
echo "
<tr>
<td>
<a href='?item=$item'>
$item
</td><td>
$title
</td><td>
$description
</a>
</td>
</tr>
";
}
//
}
This code contains Javascript and AJAX code which is for making dynamic search from the input and displaying the sql results in the 'search_output'.
<input type='text' class='search_input' onkeyup="performSearch(this.value);" id='search' placeholder='search' value='$search' autofocus>
<div id='search_output' class='search_output'>";
<script>
function performSearch(data) {
if (data.length > 0) {
var xmlhttp = new XMLHttpRequest() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("search_output").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET", "YOURPHPFILENAME.php?search=" + data, true);
xmlhttp.send();
}
}
</script>
Unfortunately for other Dynamic features you will need to learn JQUERY/AJAX and understand HTML DOM. There may be Third party API which may do this.