Category Archives: programming

Ways to avoid duplicates due to browser refresh

Below are scenarios that may cause duplicates

  1. browser refresh upon successful form submission
  2. browser refresh while the page still processing/loading
  3. resubmit the form again (by clicking on the button more than once)

Solutions

  1. Post-redirect-get (PRG) – on wikipedia
  2. One easy way is to have injected a hidden parameter with a random hash/number (e.g called token). Upon submission you’ll have to check that the token you expect (which you’ll have probably stored in the http session) is being sent together with the other POST parameters. On valid submission you’ll remove/invalidate this token. That way when a POST comes which a non recognised token then it’s most probably a duplicate or out of date request. source
  3. To check whether the data submitted exist in the database. This is the most tedious part to do and you need to have a unique data for this. i.e. the data must be unique in the table or create a unique data for this purpose sent together with other data.
  4. Add a one-time token to your forms and save it to the $_SESSION-variable. Then if it is used (form is submitted), remove it from the session (or create a new token). If the form is then sent again, the two tokens don’t match and you have a duplicate entry (you can ignore the second for example). source 

 

CodeIgniter vs Laravel

I’ve been using laravel for years already. Now I need to move to Laravel and I need strong reasons why I should.

Here I compiled some

  1. Laravel is truly OOP
  2. The ORM (eloquent) in Laravel is really powerful
  3. Can tune the speed with cache and queue
  4. Artisan command that really help doing job faster – e.g. creating controllers, models, run migration (database) etc.
  5. Migration that acts like database version control for the development team
  6. RESTful resource controllers
  7. Many available packages developed by other programmers that can be used
  8. More support, community, references. e.g. laracasts.com, laravel.io
  9. Powerful routes
  10. Class autoloading?

And below are the articles you may wan to read that are also my reference to the above points.

  1. laravel vs CI. A difficult choice

R&D List – Things to learn

Things to explore, study, learn

  • AWS – EC2, RDS, S3 – to set up a complete application platform and see how flexible and easy to manage
  • how to sync database updates among programmers just what git does for source codes
  • git stashes, submodules and subtrees
  • update svn from production server
  • push to deploy with git to production server (from gitlab)

Others:

Simple datatables.net code

This is just a basic code to use datatables.

Important components in the code:

  1. include of js, css on top
  2. declaring ‘thead’ tag
  3. declaring ‘id’ of the table to be same as called in js at the bottom
  4. include js script at the bottom

or can refer here for code

 

<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css">
<script src="https://code.jquery.com/jquery-1.12.3.js"></script>
<script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
 
<h1>A List</h1>
 
<table id="myTable" class="display" cellspacing="0" border="1">
    <thead>
        <tr>
            <th>org</th>
            <th>session</th>
            <th>total</th>
        </tr>
    </thead>
 
    <?php
    $counter = 0;
 
    foreach ($branch_list as $row) {
    ?>
    <tr>
        <td><?php echo $row->orgname; ?></td>
        <td><?php echo $row->sessionname; ?></td>
        <td><?php echo $row->total_student; ?></td>
    </tr>
    <?php } ?>
</table>
 
<script>
$(document).ready(function() {
    $('#myTable').DataTable();
} );
</script>