Security code on register form

Hello,this is my first time on this site,
i know this site because i read 101 Tips & Tricks PHP
it’s good book.

now i have problem about register page

don’t care language

i have problem about security code
i have Register.html ->Register.php

on Register.php i’ll compare security code and security image
if it’s not the same i’ll go back to Register.html

This is my problem.
when i go back by header i’ll lost all information on all Textfields.
how can i go back to Register.html without lost data on form
i tried to use javascript and php like this

<?php
if (!=)
{
<script>
history(-1);
</script>
}
?>

it’s not work.
i looking for result on internet,they said i have to understand between run on server and run on client
what should i do?

Thank you very much
i think i will learn more on this site
i hope i’ll to be professional the same DR.Davey Shafik … some day

You are using two different files therefore sessions will help you to retain the form values on error. Please visit http://www.sitepoint.com/forums/showthread.php?p=3533540

I have already mentioned in my last post what to do. See the code and read comments too.

and if i use the same file.what should i do?

ohhhh…! sorry sir,
Thank you very much

Hi lung,

Welcome to sitepoint forums!

This type of problem is already discussed in this forum for several times as far as i remember. But I don’t remember the exact keywords to search in. You can try even in google.

But the basic logic with this (what I normally do) is, having the processing script and html form in the same file. That means the page has to be submitted to the same page and on top of the page it has to check whether page is posted.


if($_SERVER['REQUEST_METHOD'] == 'POST'){
    if(!NOT_ERROR_FOUND){
        // do the form processing stuffs
    }
    // if there are errors form will remain with posted values in $_POST which you can use in your form below
}
// below this line your form will exist like
echo '<form name="frm1" action="" method="post">';
echo 'First Name: <input type="text" name="firstname" value="' . (isset($_POST['firstname']) ? $_POST['firstname'] : '')  . '" />';
echo '</form>';

I know this is not the complete code but hope it will point to right direction!

Good luck!