Jump to content
Open

PHP CHALLANGE - PART 1 -

Recommended Posts

Salut,

Sa se faca un calculator in limbajul de programare PHP care sa afiseze rezultatul in litere

4+4 rezultatul afisat sa fie "opt' nu "8"

Si daca cineva incearca sa introduca litere in calcul sa se blocheze accesul acelui browser timp de 60 minute.

Si scripturile postate sa fie cat mai diferite de la utilizator la utilizator.

Scriptul meu


<?php
if(isset($_COOKIE['1d7ae0532395d267dd3526beb707240b'])){
echo "<font color='red'><center><h2>Ai fost blocat pe acest site</h2></center></font>";
}else{

if(isset($_POST['a'])){

$array = array("1","2","3","4","5","6","7","8","9","10");
$litere = array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","s","t","u","v","w","x","y","z");
$array2 = array("unu","doi","trei","patru","cinci","sase","sapte","opt","noua","zece");
$a = htmlentities(strtolower(str_replace($litere,null,($_POST['a']))));
$b = htmlentities(strtolower(str_replace($litere,null,($_POST['b']))));
echo str_replace($array,$array2,$a + $;
if($a ==0 && $b == 0){
setcookie(md5("blocat"),md5("blocat"),time()+6500);
}


}else{
echo '<form action="" method="POST">
<input type="text" name="a"><br> +
<input type="text" name="b"><br>:
<input type="submit" value="Submit">
</form> ';
}
}
?>

Link to comment
Share on other sites

Am uitat cat de mult ador si urasc php-ul in acelasi timp.


<!DOCTYPE html>
<html>
<body>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<input type="text" name="a"> + <input type="text" name="b">
<input type="submit">
</form>

<?php

function retnum($num) {
$var = array( 1 => "unu",
2 => "doi",
3 => "trei",
4 => "patru",
5 => "cinci",
6 => "sase",
7 => "sapte",
8 => "opt",
9 => "noua",
0 => "zero" );
$mun = strrev($num); $hue = "";
while ((int)$mun > 0) {
$hue .= $var[$mun%10] . " ";
$mun /= 10;
}
return $hue;
}

if (isset($_COOKIE["lol_cookies"])) {
$hue = array("nope", "rekt", ":^)");
echo $hue[array_rand($hue)];
} else {
if ((isset($_POST["a"])) && (isset($_POST["b"]))) {
$a = $_POST["a"]; $b = $_POST["b"];
if ( ($a != null && !is_numeric($a)) ||
($b != null && !is_numeric($) ) {
setcookie("lol_cookies", "shrekt :^)", time()+(60*60));
} else {
$num = $a + $b;
echo retnum($num);
}
}
}

?>

</body>
</html>

Link to comment
Share on other sites

Stiu ca e mai fain sa verifici daca este setata o variabila sau nu, dar asa e mai scurt:


<?php

ini_set('display_errors', FALSE);

if (preg_match('/[a-z]/i', $_POST['a'] . $_POST['b']) || $_COOKIE['blocked']) {
if (!$_COOKIE['blocked']) setcookie('blocked', 1, time() + 3600);
die('Access denied!');
}

?>
<form method="post">
<input type="text" name="a" value="0" /> +
<input type="text" name="b" value="0" /> =
<input type="text" value="<?=['zero', 'unu', 'doi', 'trei', 'patru', 'cinci', 'sase', 'sapte', 'opt', 'noua', 'zece'][$_POST['a'] + $_POST['b']]?>" disabled />
<input type="submit" />
</form>

Edited by totti93
  • Upvote 1
Link to comment
Share on other sites

Stiu ca e mai fain sa verifici daca este setata o variabila sau nu, dar asa e mai scurt:


<?php

ini_set('display_errors', FALSE);

if (preg_match('/[a-z]/i', $_POST['a'] . $_POST['b']) || $_COOKIE['blocked']) {
if (!$_COOKIE['blocked']) setcookie('blocked', 1, time() + 3600);
die('Access denied!');
}

?>
<form method="post">
<input type="text" name="a" value="0" /> +
<input type="text" name="b" value="0" /> =
<input type="text" value="<?=['zero', 'unu', 'doi', 'trei', 'patru', 'cinci', 'sase', 'sapte', 'opt', 'noua', 'zece'][$_POST['a'] + $_POST['b']]?>" disabled />
<input type="submit" />
</form>

Foarte bine lucrat.

Link to comment
Share on other sites

  • Active Members

Plm calculator inseamna macar sa poata face toate operatiile de baza + ,* ,- ,/ .

Ce sa mai zic de evaluarea unei expresii matematice cu paranteze si cu ordinea efectuarii operatiilor.

<?php class calculator{ private $cifre=array(0=>"zero",1=>"unu",2=>"doi" - Pastebin.com

Ms @proof nu mai folosi nicodata PHP_SELF nesintetizat baga scrip.php/"><script>alert(1)</script>

Edited by danyweb09
Link to comment
Share on other sites

Daca totti a adaugat varianta cea mai scurta si dany cea mai complexa, adaug si eu ceva intre. Adica nu face mare lucru da are si multe linii :)

Ca informatii, aduna doar numere intregi pozitive de lungime limitata.


<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>PHP Challenge</title>
</head>
<style type="text/css">#content {text-align: center;}</style>
<body>
<div id="content">
<?php if (allowed()) : ?>
<form action="challenge.php" method="post">
<label for="a">A: </label>
<input type="text" name="a" value="" /><br /> + <br />
<label for="b">B: </label>
<input type="text" name="b" value="" /><br /><br />
<input type="submit" value="Calculeaza" />
</form>
<h4><?php echo validate(); ?></h4>
<?php else : ?>
<img src="http://i.imgur.com/ql2uzA1.png"/>
<?php endif; ?>
</div>
</body>
</html>

<?php

function translate( $number ) {

$units = array('zero', 'unu', 'doi', 'trei', 'patru', 'cinci', 'sase', 'sapte', 'opt', 'noua', 'zece', 'unsprezece', 'doisprezece', 'treisprezece', 'paisprezece', 'cincisprezece', 'saisprezece', 'saptesprezece', 'optsprezece', 'nouasprezece');
$tens = array(2 => 'douazeci', 3 => 'treizeci', 4 => 'patruzeci', 5 => 'cincizeci', 6 => 'saizeci', 7 => 'saptezeci', 8 => 'optzeci', 9 => 'nouazeci');

if ($number < 20) {
return $units[$number];
}

if ($number < 100) {
$quotient = floor($number / 10);
$remainder = $number % 10;

return $tens[$quotient] . ($remainder ? " si $units[$remainder]" : "");
}

if ($number < 1000) {
$quotient = floor($number / 100);
$remainder = $number % 100;

return ($quotient == 1 ? " o suta " : ($quotient == 2 ? " doua sute " : "$units[$quotient] sute ")) . ($remainder ? translate($remainder) : "");
}

if ($number < 1000000) {
$quotient = floor($number / 1000);
$remainder = $number % 1000;

return ($quotient == 1 ? " o mie " : ($quotient == 2 ? " doua mii " : translate($quotient) . ($number >= 20000 ? " de " : "") . " mii ")) . ($remainder ? translate($remainder) : "");
}

if ($number < 1000000000) {
$quotient = floor($number / 1000000);
$remainder = $number % 1000000;

return ($quotient == 1 ? " un milion " : ($quotient == 2 ? " doua milioane " : translate($quotient) . ($number >= 20000000 ? " de " : "") . " milioane ")) . ($remainder ? translate($remainder) : "");
}

if ($number < 1000000000000) {
$quotient = floor($number / 1000000000);
$remainder = $number % 1000000000;

return ($quotient == 1 ? " un miliard " : ($quotient == 2 ? " doua miliarde " : translate($quotient) . ($number >= 20000000000 ? " de " : "") . " miliarde ")) . ($remainder ? translate($remainder) : "");
}

return "Come on ... give me a break";
}

function validate() {
if (isset($_POST['a']) && isset($_POST['b'])) {
$a = trim($_POST['a']);
$b = trim($_POST['b']);

if ($a != '' && $b != '') {
if ( ! ctype_digit($a) || ! ctype_digit($) {
setcookie('forbidden', TRUE, time() + (60 * 60));
header("Location: {$_SERVER['REQUEST_URI']}");
} else {
return "$a + $b = " . ($a + $ . " ( " . translate($a + $ . " )";
}
}
}
}

function allowed() {
return isset($_COOKIE['forbidden']) ? FALSE : TRUE;
}

Edited by BitMap
wrong tags
  • Upvote 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...