Showing posts with label code. Show all posts
Showing posts with label code. Show all posts

Wednesday, June 29, 2016

How to Code Your Own CAPTCHA Script In PHP

Today I will show you how to code your own CAPTCHA Script.
<?php
session_start();
$strlength = rand(4,7);

for($i=1;$i<=$strlength;$i++)
{
$textornumber = rand(1,3);
if($textornumber == 1)
{
$captchastr .= chr(rand(49,57));
}
if($textornumber == 2)
{
$captchastr .= chr(rand(65,78));
}
if($textornumber == 3)
{
$captchastr .= chr(rand(80,90));
}
}
$randcolR = rand(100,230);
$randcolG = rand(100,230);
$randcolB = rand(100,230);

/initialize image $captcha is handle dimensions 200,50
$captcha = imageCreate(200,50);
$backcolor = imageColorAllocate($captcha, $randcolR, $randcolG, $randcolB);

$txtcolor = imageColorAllocate($captcha, ($randcolR - 20), ($randcolG - 20), ($randcolB - 20));
for($i=1;$i<=$strlength;$i++)
{

$clockorcounter = rand(1,2);
if ($clockorcounter == 1)
{
$rotangle = rand(0,45);
}
if ($clockorcounter == 2)
{
$rotangle = rand(315,360);
}

//$i*25 spaces the characters 25 pixels apart
imagettftext($captcha,rand(14,20),$rotangle,($i*25),30,$txtcolor,"/arial.ttf",substr($captchastr,($i-1),1));
}
for($i=1; $i<=4;$i++)
{
imageellipse($captcha,rand(1,200),rand(1,50),rand(50,100),rand(12,25),$txtcolor);
}
for($i=1; $i<=4;$i++)
{
imageellipse($captcha,rand(1,200),rand(1,50),rand(50,100),rand(12,25),$backcolor);
}
//Send the headers (at last possible time)
header(Content-type: image/png);

//Output the image as a PNG
imagePNG($captcha);

//Delete the image from memory
imageDestroy($captcha);

$_SESSION[captchastr] = $captchastr;

?>
If you like this script then feel free to Subscribe to our blog and we will email you similar interesting and useful PHP scripts in your Inbox as soon as it is published on our blog.

Enjoy!


Sunday, June 5, 2016

How To Code A Simple Calculator In PHP

In this php tutorial you will learn how to make a simple PHP calculator
<?php

if($submit)
{
if($operator == *)
{
echo $numa * $numb;
} elseif($operator == /)
{
echo $numa / $numb;
} elseif($operator == +)
{
echo $numa + $numb;
} elseif($operator == -)
{
echo $numa - $numb;
}
} else { ?>
<form method="POST" action="<?php $_SERVER[PHP_SELF]; ?>">
<input type="text" name="numa" size="10">
<select name="operator">
<option value="+">Add</option>
<option value="-">Subtract</option>
<option value="*">Multiply</option>
<option value="/">Divide</option>
</select>
<input type="text" name="numb" size="10">
<input type="submit" value="Calculate" name="submit">
</form>
<?php } ?>
If you have any suggestions regarding the script please feel free to share it with us.Feel free to edit the above script to suit your personal needs.

Subscribe to our blog and we will email you similar interesting php scripts as soon as it is published.

Beside you could also refer to our PHP Interview Questions Series.

Enjoy!

Thursday, May 26, 2016

Code A Simple PHP Contact Form With A Reply To Option

Today I will show to how to code a Contact form in PHP Which also has a Reply To feature.It is very simple to do so using combination of HTML and PHP.

The Code for the form is given below:

Form Code:
<form action="procesar_form.php" method="post" name="formulario" id="formulario" onsubmit=return validarFormulario()>
<label for="nombre">Nombre </label>
<input type="text" name="nombre" id="nombre" size="60"/>

<label for="apellido">Apellido </label>
<input type="text" name="apellido" id="apellido" size="60"/>

<label for="email">Email </label>
<input type="text" name="email" id="email" size="60"/>

<label for="comentarios">Comentarios</label>
<textarea name="comentarios" id="comentarios" cols="44" rows="10"></textarea>

<input type="button" name="enviar" id="enviar" value="Enviar" onclick="validarFormulario()" /></textarea>

</form>

PHP Code
$email = $_POST[email];


$to = xyz@gmail.com;
$subject = Contacto Us;
$message = Name: . $_POST[name] . " " .
Surname: . $_POST[surname] . " " .
Email: . $_POST[email] . " " .
Comments: . $_POST[comments];
$headers = From: $email . " " .
Reply-to: $email . " " .
X-Mailer: PHP/ . phpversion();


mail($to, $subject, $message, $headers);


header("Location: ../../index.html");

Just put it all together and you are ready to go.I hope you enjoyed this free php script

Enjoy!

Sunday, May 22, 2016

PHP Source Code Utility Script

Highlight PHP syntax and optionally add line numbers to PHP source code or files, with several output options. Files to highlight are chosen in a form and temporarily uploaded to the remote server, or you can use this script on your local server to aid PHP development.

Download PHP Source Code Utility Script