php - Javascript that saves what user typed -


i have website similar pastebin. there text box on index.php , captcha code complete after finish typing upload paste. if enter wrong code, many do, including me, new page comes says mistyped, when go index.php have written in text box gone? isn't cookies or cache can save this?

here's gif showing mean.

https://gyazo.com/4db14468e5ba74837e7b9c9db5715cf9

i think can fixed using kind of javascript or cookie, don't know 1 or anything?

please help.

edit: index.php

$_session["dox"] = $dox;  $hidden = md5(mt_rand()); $_session["hidden"] = $hidden;  $poster = md5(mt_rand()); $_session["poster"] = $poster;  ?>  <!doctype html public "-//w3c//dtd xhtml 1.0 strict//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> <title>cloudnine beta - title</title> <link href="style/purple.css" rel="stylesheet" type="text/css" /> </head> <body id="center" onload="document.getelementbyid('captcha-form').focus()"> <h1>website</h1> <p><h2><strong>information exchange<p></strong></h2>   <div style="color:rgb(255, 51, 51);text-shadow:rgb(194, 31, 31) 0px 1px 3px;font-size: 22px;"> <div style="margin-top:22px;margin-bottom:22px;"></div>this site still under development, if find bugs, please report them bblaal@blabla.com</a> </div>  <h3><a href="privacy.php">privacy policy</a> | <a href="/old">old</a>  |  <a href="doxviewer.php">archive</a> | <a href="/fail">fail</a> | <a href="faq.php">faq</a> <form action="post.php" method="post"></h3> <p> <input type="text" id="name" name="<?php echo $_session["name"]; ?>" rows="25" cols="80" style="font-size:16px;text-align:center;font-family:courier;color:white;border-top-left-radius:4px 4px;border-top-right-radius:4px 4px;border-bottom-right-radius:4px 4px;border-bottom-left-radius:4px 4px;background-color: rgb(30, 4, 38); border-width: 1px; border-style: solid; padding: 5px; border-color: white; " placeholder="name"></textarea> <br /> <p> <textarea id="dox" name="<?php echo $_session["dox"]; ?>" rows="25" cols="80" placeholder="info goes here. post whatever info want here. try stick our strict non-removal policy, once post go up, stay unless shit. asking post removed surest way them updated , expanded upon. no, isn't doxbin."></textarea>  <p><strong>type in captcha here.</p><strong> <img src="captcha.php" id="captcha" /><br/> <a href="#" onclick="     document.getelementbyid('captcha').src='captcha.php?'+math.random();     document.getelementbyid('captcha-form').focus();"     id="change-image">not readable? change text.</a><br/><br/>  <input type="text" id="poster" name="<?php echo $_session["poster"]; ?>" rows="25" cols="80" style="font-size:16px;text-align:center;font-family:courier;color:white;border-top-left-radius:4px 4px;border-top-right-radius:4px 4px;border-bottom-right-radius:4px 4px;border-bottom-left-radius:4px 4px;background-color: rgb(30, 4, 38); border-width: 1px; border-style: solid; padding: 5px; border-color: white; " placeholder="poster (optional)"><br /> <input type="text" name="captcha" id="captcha-form" autocomplete="off" style="font-size:16px;text-align:center;font-family:courier;color:white;border-top-left-radius:4px 4px;border-top-right-radius:4px 4px;border-bottom-right-radius:4px 4px;border-bottom-left-radius:4px 4px;background-color: rgb(30, 4, 38); margin-right:5px;border-width: 1px; border-style: solid; padding: 5px; border-color: white; " placeholder="enter captcha"> <br/> <input type="submit" value="post" style="font-size:16px;text-align:center;font-family:courier;color:white;border-top-left-radius:4px 4px;border-top-right-radius:4px 4px;border-bottom-right-radius:4px 4px;border-bottom-left-radius:4px 4px;background-color: rgb(30, 4, 38); margin-right:5px;border-width: 1px; border-style: solid; padding: 5px; border-color: white; " /><br /> <input type="text" name="<?php echo $hidden; ?>" value="" style="visibility: hidden;" /> </p>  <?php /** validate captcha */ if (!empty($_request['captcha'])) {     if (empty($_session['captcha']) || trim(strtolower($_request['captcha'])) != $_session['captcha']) {         $captcha_message = "invalid captcha";         $style = "background-color: #ff606c";     } else {         $captcha_message = "valid captcha";         $style = "background-color: #ccff99";     }      $request_captcha = htmlspecialchars($_request['captcha']);      echo <<<html         <div id="result" style="$style">         <h2>$captcha_message</h2>         <table>         <tr>             <td>session captcha:</td>             <td>{$_session['captcha']}</td>         </tr>         <tr>             <td>form captcha:</td>             <td>$request_captcha</td>         </tr>         </table>         </div> html;     unset($_session['captcha']); } ?>  </form>    <p> <div style="margin-top:10px;margin-bottom:10px;text-align:center;color:white;font-size:18px;font-family:arial;font-weight:normal;"> follow on twitter: <a href="https://twitter.com/user" style="color:rgb(242, 242, 242);">@user</a> | contact us: <a href="mailto:blabal@gmail.com" style="color:rgb(242, 242, 242);">blabla@gmail.come</a> | <a href="t" style="color:rgb(242, 242, 242);">our pgp key</a> (use email) </div> </p> </body> </html> 

captcha.php code:

<?php /**  * script para la generaciĆ³n de captchas  *  * @author  jose rodriguez <jose.rodriguez@exec.cl>  * @license gplv3  * @link    http://code.google.com/p/cool-php-captcha  * @package captcha  * @version 0.3  *  */   session_start();  if (!isset($_post['captcha'])) {     $_post['captcha'] = "undefine"; }  $captcha = new simplecaptcha();    // optional change configuration... //$captcha->wordsfile = 'words/es.php'; //$captcha->session_var = 'secretword'; //$captcha->imageformat = 'png'; //$captcha->linewidth = 3; //$captcha->scale = 3; $captcha->blur = true; //$captcha->resourcespath = "/var/cool-php-captcha/resources";  // optional simple autodetect language example /* if (!empty($_server['http_accept_language'])) {     $langs = array('en', 'es');     $lang  = substr($_server['http_accept_language'], 0, 2);     if (in_array($lang, $langs)) {         $captcha->wordsfile = "words/$lang.php";     } } */    // image generation $captcha->createimage();      /**  * simplecaptcha class  *  */ class simplecaptcha {      /** width of image */     public $width  = 200;      /** height of image */     public $height = 60;      /** dictionary word file (empty random text) */     public $wordsfile = 'words/en.php';      /**      * path resource files (fonts, words, etc.)      *      * "resources" default. security reasons, better move      * directory location outise web server      *      */     public $resourcespath = 'resources';      /** min word length (for non-dictionary random text generation) */     public $minwordlength = 5;      /**      * max word length (for non-dictionary random text generation)      *       * used dictionary words indicating word-length      * font-size modification purposes      */     public $maxwordlength = 8;      /** sessionname store original text */     public $session_var = 'captcha';      /** background color in rgb-array */     public $backgroundcolor = array(255, 255, 255);      /** foreground colors in rgb-array */     public $colors = array(         array(27,78,181), // blue         array(22,163,35), // green         array(214,36,7),  // red     );      /** shadow color in rgb-array or null */     public $shadowcolor = null; //array(0, 0, 0);      /** horizontal line through text */     public $linewidth = 0;      /**      * font configuration      *      * - font: ttf file      * - spacing: relative pixel space between character      * - minsize: min font size      * - maxsize: max font size      */     public $fonts = array(         'antykwa'  => array('spacing' => -3, 'minsize' => 27, 'maxsize' => 30, 'font' => 'antykwabold.ttf'),         'candice'  => array('spacing' =>-1.5,'minsize' => 28, 'maxsize' => 31, 'font' => 'candice.ttf'),         'dingdong' => array('spacing' => -2, 'minsize' => 24, 'maxsize' => 30, 'font' => 'ding-dongdaddyo.ttf'),         'duality'  => array('spacing' => -2, 'minsize' => 30, 'maxsize' => 38, 'font' => 'duality.ttf'),         'heineken' => array('spacing' => -2, 'minsize' => 24, 'maxsize' => 34, 'font' => 'heineken.ttf'),         'jura'     => array('spacing' => -2, 'minsize' => 28, 'maxsize' => 32, 'font' => 'jura.ttf'),         'staypuft' => array('spacing' =>-1.5,'minsize' => 28, 'maxsize' => 32, 'font' => 'staypuft.ttf'),         'times'    => array('spacing' => -2, 'minsize' => 28, 'maxsize' => 34, 'font' => 'timesnewromanbold.ttf'),         'verasans' => array('spacing' => -1, 'minsize' => 20, 'maxsize' => 28, 'font' => 'verasansbold.ttf'),     );      /** wave configuracion in x , y axes */     public $yperiod    = 12;     public $yamplitude = 14;     public $xperiod    = 11;     public $xamplitude = 5;      /** letter rotation clockwise */     public $maxrotation = 8;      /**      * internal image size factor (for better image quality)      * 1: low, 2: medium, 3: high      */     public $scale = 2;      /**       * blur effect better image quality (but slower image processing).      * better image results scale=3      */     public $blur = false;      /** debug? */     public $debug = false;      /** image format: jpeg or png */     public $imageformat = 'jpeg';       /** gd image */     public $im;        public function __construct($config = array()) {     }       public function createimage() {         $ini = microtime(true);          /** initialization */         $this->imageallocate();          /** text insertion */         $text = $this->getcaptchatext();         $fontcfg  = $this->fonts[array_rand($this->fonts)];         $this->writetext($text, $fontcfg);          $_session[$this->session_var] = $text;          /** transformations */         if (!empty($this->linewidth)) {             $this->writeline();         }         $this->waveimage();         if ($this->blur && function_exists('imagefilter')) {             imagefilter($this->im, img_filter_gaussian_blur);         }         $this->reduceimage();           if ($this->debug) {             imagestring($this->im, 1, 1, $this->height-8,                 "$text {$fontcfg['font']} ".round((microtime(true)-$ini)*1000)."ms",                 $this->gdfgcolor             );         }           /** output */         $this->writeimage();         $this->cleanup();     }        /**      * creates image resources      */     protected function imageallocate() {         // cleanup         if (!empty($this->im)) {             imagedestroy($this->im);         }          $this->im = imagecreatetruecolor($this->width*$this->scale, $this->height*$this->scale);          // background color         $this->gdbgcolor = imagecolorallocate($this->im,             $this->backgroundcolor[0],             $this->backgroundcolor[1],             $this->backgroundcolor[2]         );         imagefilledrectangle($this->im, 0, 0, $this->width*$this->scale, $this->height*$this->scale, $this->gdbgcolor);          // foreground color         $color           = $this->colors[mt_rand(0, sizeof($this->colors)-1)];         $this->gdfgcolor = imagecolorallocate($this->im, $color[0], $color[1], $color[2]);          // shadow color         if (!empty($this->shadowcolor) && is_array($this->shadowcolor) && sizeof($this->shadowcolor) >= 3) {             $this->gdshadowcolor = imagecolorallocate($this->im,                 $this->shadowcolor[0],                 $this->shadowcolor[1],                 $this->shadowcolor[2]             );         }     }          /**      * text generation      *      * @return string text      */     protected function getcaptchatext() {         $text = $this->getdictionarycaptchatext();         if (!$text) {             $text = $this->getrandomcaptchatext();         }         return $text;     }         /**      * random text generation      *      * @return string text      */     protected function getrandomcaptchatext($length = null) {         if (empty($length)) {             $length = rand($this->minwordlength, $this->maxwordlength);         }          $words  = "abcdefghijlmnopqrstvwyz";         $vocals = "aeiou";          $text  = "";         $vocal = rand(0, 1);         ($i=0; $i<$length; $i++) {             if ($vocal) {                 $text .= substr($vocals, mt_rand(0, 4), 1);             } else {                 $text .= substr($words, mt_rand(0, 22), 1);             }             $vocal = !$vocal;         }         return $text;     }         /**      * random dictionary word generation      *      * @param boolean $extended add extended "fake" words      * @return string word      */     function getdictionarycaptchatext($extended = false) {         if (empty($this->wordsfile)) {             return false;         }          // full path of words file         if (substr($this->wordsfile, 0, 1) == '/') {             $wordsfile = $this->wordsfile;         } else {             $wordsfile = $this->resourcespath.'/'.$this->wordsfile;         }          if (!file_exists($wordsfile)) {             return false;         }          $fp     = fopen($wordsfile, "r");         $length = strlen(fgets($fp));         if (!$length) {             return false;         }         $line   = rand(1, (filesize($wordsfile)/$length)-2);         if (fseek($fp, $length*$line) == -1) {             return false;         }         $text = trim(fgets($fp));         fclose($fp);           /** change ramdom volcals */         if ($extended) {             $text   = preg_split('//', $text, -1, preg_split_no_empty);             $vocals = array('a', 'e', 'i', 'o', 'u');             foreach ($text $i => $char) {                 if (mt_rand(0, 1) && in_array($char, $vocals)) {                     $text[$i] = $vocals[mt_rand(0, 4)];                 }             }             $text = implode('', $text);         }          return $text;     }         /**      * horizontal line insertion      */     protected function writeline() {          $x1 = $this->width*$this->scale*.15;         $x2 = $this->textfinalx;         $y1 = rand($this->height*$this->scale*.40, $this->height*$this->scale*.65);         $y2 = rand($this->height*$this->scale*.40, $this->height*$this->scale*.65);         $width = $this->linewidth/2*$this->scale;          ($i = $width*-1; $i <= $width; $i++) {             imageline($this->im, $x1, $y1+$i, $x2, $y2+$i, $this->gdfgcolor);         }     }         /**      * text insertion      */     protected function writetext($text, $fontcfg = array()) {         if (empty($fontcfg)) {             // select font configuration             $fontcfg  = $this->fonts[array_rand($this->fonts)];         }          // full path of font file         $fontfile = $this->resourcespath.'/fonts/'.$fontcfg['font'];           /** increase font-size shortest words: 9% each glyp missing */         $lettersmissing = $this->maxwordlength-strlen($text);         $fontsizefactor = 1+($lettersmissing*0.09);          // text generation (char char)         $x      = 20*$this->scale;         $y      = round(($this->height*27/40)*$this->scale);         $length = strlen($text);         ($i=0; $i<$length; $i++) {             $degree   = rand($this->maxrotation*-1, $this->maxrotation);             $fontsize = rand($fontcfg['minsize'], $fontcfg['maxsize'])*$this->scale*$fontsizefactor;             $letter   = substr($text, $i, 1);              if ($this->shadowcolor) {                 $coords = imagettftext($this->im, $fontsize, $degree,                     $x+$this->scale, $y+$this->scale,                     $this->gdshadowcolor, $fontfile, $letter);             }             $coords = imagettftext($this->im, $fontsize, $degree,                 $x, $y,                 $this->gdfgcolor, $fontfile, $letter);             $x += ($coords[2]-$x) + ($fontcfg['spacing']*$this->scale);         }          $this->textfinalx = $x;     }        /**      * wave filter      */     protected function waveimage() {         // x-axis wave generation         $xp = $this->scale*$this->xperiod*rand(1,3);         $k = rand(0, 100);         ($i = 0; $i < ($this->width*$this->scale); $i++) {             imagecopy($this->im, $this->im,                 $i-1, sin($k+$i/$xp) * ($this->scale*$this->xamplitude),                 $i, 0, 1, $this->height*$this->scale);         }          // y-axis wave generation         $k = rand(0, 100);         $yp = $this->scale*$this->yperiod*rand(1,2);         ($i = 0; $i < ($this->height*$this->scale); $i++) {             imagecopy($this->im, $this->im,                 sin($k+$i/$yp) * ($this->scale*$this->yamplitude), $i-1,                 0, $i, $this->width*$this->scale, 1);         }     }         /**      * reduce image final size      */     protected function reduceimage() {         // reduzco el tamaƱo de la imagen         $imresampled = imagecreatetruecolor($this->width, $this->height);         imagecopyresampled($imresampled, $this->im,             0, 0, 0, 0,             $this->width, $this->height,             $this->width*$this->scale, $this->height*$this->scale         );         imagedestroy($this->im);         $this->im = $imresampled;     }        /**      * file generation      */     protected function writeimage() {         if ($this->imageformat == 'png' && function_exists('imagepng')) {                header("content-type: image/png");             imagepng($this->im);         } else {             header("content-type: image/jpeg");             imagejpeg($this->im, null, 80);         }     }        /**      * cleanup      */     protected function cleanup() {         imagedestroy($this->im);     } }     ?> 

the text box content , captcha response both posted post.php when form submitted. if captcha verification fails, send text box content along failure in form links index.php content can used initial value of text box.

or use ajax send text , captcha, waiting either success message , link follow, or error new captch. in case of error, display message , new captcha user can try again, , page doesn't reload until there success.


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -