Open Posted February 9, 2015 Report Posted February 9, 2015 Salut, Sa se faca un calculator in limbajul de programare PHP care sa afiseze rezultatul in litere4+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<?phpif(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> '; }} ?> Quote
pr00f Posted February 9, 2015 Report Posted February 9, 2015 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><?phpfunction 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> Quote
Open Posted February 9, 2015 Author Report Posted February 9, 2015 @pr00f Bravo, frumos lucrat. Quote
tromfil Posted February 9, 2015 Report Posted February 9, 2015 Mi-a?i amintit de forma polonez?. Read this, c? posibil s? v? fie util: Evaluare de Expresii Aritmetice Quote
player81 Posted February 11, 2015 Report Posted February 11, 2015 @open la $array si $array2 mai bine il declari pe 0, respectiv zero in loc de 10 si zece! Quote
totti93 Posted February 11, 2015 Report Posted February 11, 2015 (edited) Stiu ca e mai fain sa verifici daca este setata o variabila sau nu, dar asa e mai scurt:<?phpini_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 February 11, 2015 by totti93 1 Quote
Open Posted February 11, 2015 Author Report Posted February 11, 2015 Stiu ca e mai fain sa verifici daca este setata o variabila sau nu, dar asa e mai scurt:<?phpini_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. Quote
Active Members dancezar Posted February 13, 2015 Active Members Report Posted February 13, 2015 (edited) 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.comMs @proof nu mai folosi nicodata PHP_SELF nesintetizat baga scrip.php/"><script>alert(1)</script> Edited February 13, 2015 by danyweb09 Quote
BitMap Posted February 13, 2015 Report Posted February 13, 2015 (edited) 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><?phpfunction 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 February 13, 2015 by BitMap wrong tags 1 Quote