CodeIgniter Forums
How Can I Destroy User Data After Insertion ? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: How Can I Destroy User Data After Insertion ? (/showthread.php?tid=10256)

Pages: 1 2


How Can I Destroy User Data After Insertion ? - El Forum - 07-24-2008

[eluser]Zeeshan Rasool[/eluser]
Hi all, here is a problem im facing.

Problem is , when i create a new user and click submit button the CREATE_USER_DB function executes and new user has been inserted. But when i refresh the page by pressing F5 or else an other user data is inserted in DB with same record values
How can i destroy userdata or $_POST data so it can be stopped?

Very Thnx in Advance.


How Can I Destroy User Data After Insertion ? - El Forum - 07-24-2008

[eluser]sanct_arvin[/eluser]
redirect it to another page.


Code:
$query = $this->db->insert('users', $_POST);
        $user_id = $this->db->insert_id();

            $data['msg'] = 'Successfully Registered: '.$_POST['lname'].', '.$_POST['fname'];
            $data['title'] = 'Successful'; //title of the page
            $data['sec'] = 5; //secs before redirection
            $data['heading'] ='Successfully Registered'; // heading :D
            $data['url'] = base_url().'index.php/user/nextlocation'; //your next location
            $_SESSION['user_id']= $user_id; //set session variable to check if he/she is logged in

        $this->load->view('prompt.php', $data);

create a redirection page


in your prompt.php
Code:
<html>
<head>
    <title><?=$title?></title>
    
    <meta http-equiv="refresh" content="<?=$sec?>;url=<?=$url?>">

<style>
    td, th, pre, body, input, textarea, span, div, p{
        font-family: Verdana, Arial;
        font-size: 11px;
        vertical-align:top;
    }
    .main{
        display: inline;
        width: 95%;
    }
    .right{ width:100%}
    .left{ padding-left: 10px; padding-right: 10px;}

    .msg{border:1px dashed fff }
    
    
</style>
</head>
<body>
<?=$sec?>
<?=$url?>
    
    <h3>&lt;?=$heading?&gt;</h3>    
    
    <div class='msg'>
        &lt;?=$msg?&gt;
    </div>
    
&lt;/body&gt;
&lt;/html&gt;

i use it every time i don't want a duplicate data Big Grin
you can use it in every pages that would insert data.
kudos!

regards
- sanct_arvin


How Can I Destroy User Data After Insertion ? - El Forum - 07-24-2008

[eluser]Sumon[/eluser]
You can also use
Code:
foreach($_POST as $Key => $Value)
  {
     $POST[$Key] = "";
     unset($POST[$Key]);
  }
After this when your page reloaded all fields will be empty. So empty data can't register itself.

Hope it helps you


How Can I Destroy User Data After Insertion ? - El Forum - 07-24-2008

[eluser]Grahack[/eluser]
Strange, I thought that this F5 thing was browser related. No matter what happens server-side, our browsers often remember what they "posted", so resetting the $_POST array seems to me useless.


How Can I Destroy User Data After Insertion ? - El Forum - 07-24-2008

[eluser]Sumon[/eluser]
Ops... sorry for my post. You are right. It's completely browser dependent. So it might better to redirect into another function().


How Can I Destroy User Data After Insertion ? - El Forum - 07-24-2008

[eluser]Zeeshan Rasool[/eluser]
Thnx yaar! so what shud me do now?


How Can I Destroy User Data After Insertion ? - El Forum - 07-24-2008

[eluser]sanct_arvin[/eluser]
redirect it to another page after your insert

use redirect() function


How Can I Destroy User Data After Insertion ? - El Forum - 07-24-2008

[eluser]Zeeshan Rasool[/eluser]
Got it ! thank you all


How Can I Destroy User Data After Insertion ? - El Forum - 07-25-2008

[eluser]Colin Williams[/eluser]
It is generally good practice to redirect "successful" form posts (though doing a meta redirect from HTML is not the best thing, when you can just initiate a new HTTP request from PHP), and use Session variables to pass along information, like messages, or even original $_POST data. Some frameworks do this.... has me thinking... Gah! So many good ideas for CI libraries!


How Can I Destroy User Data After Insertion ? - El Forum - 02-08-2009

[eluser]gh0st[/eluser]
The way I used to do it was;

Form -> processSomething.php -> Result

I call it a "processing file" and it does the work and redirects once its finished so that if the user press back or press F5 it won't cache the result.

Although you still need to do checks to ensure that the data in processSomething.php is valid and accurate (perhaps delaying how many times someone can press `submit` on a form, etc) you can stop this issue.

But I'm not sure whether using a redirect as shown above is firstly MVC, and secondly correct.

Thanks