• Display Simple Flash Messages Based on Session using PHP

    Kindly follow below steps to display simple flash messages based on session using PHP.

    Step 1 : Create index.php

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    
    <!--?php 
    //------------------------------------------------------------------------------
    // A session is required for the messages to work
    //------------------------------------------------------------------------------
    if( !session_id() ) session_start();
     
    //------------------------------------------------------------------------------
    // Include the Messages class and instantiate it
    //------------------------------------------------------------------------------
    require_once('class.messages.php');
    $msg = new Messages();
     
    //------------------------------------------------------------------------------
    // Add some messages
    //------------------------------------------------------------------------------
    //$msg--->add('s', 'The is a sample Success Message');
    //$msg-&gt;add('e', 'The is a sample Error Message');
    //$msg-&gt;add('w', 'The is a sample Warning Message');
    //$msg-&gt;add('i', 'The is a sample Information Message');
     
    //------------------------------------------------------------------------------
    // Print the HTML page as usual
    //------------------------------------------------------------------------------
    ?&gt;<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
     
            		<link href="style.css" rel="stylesheet" type="text/css" />

    Simple, Session-Based Flash Messages

    1
    2
    3
    4
    5
    6
    
            <!--?php 
            //------------------------------------------------------------------------
            // Display any messages
            //------------------------------------------------------------------------
            echo $msg--->display();
            ?&gt;

    Create a New Message

    Message Text:
    Message Type:



    1
    
     

    1
    
     

    Step 2 : Create process-form.php

    1
    
     

    Step 3 : Create class.messages.php

    1
    
     

    Step 4 : Create style.css

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    
    .messages { width: 100%; -moz-border-radius: 4px; border-radius: 4px; display: block; padding: 10px 0; margin: 10px auto 10px; clear: both; }
    .messages a.closeMessage { margin: -14px -8px 0 0; display:none; width: 16px; height: 16px; float: right; background: url(images/messages/close.png) no-repeat; }
    /*.messages:hover a.closeMessage { visibility:visible; }*/
    .messages p { margin: 3px 0 3px 10px !important; padding: 0 10px 0 23px !important; font-size: 14px; line-height: 16px; }
    .messages.error { border: 1px solid #C42608; color: #c00 !important; background: #FFF0EF; }
    .messages.error p { background: url(images/messages/cross.png ) no-repeat 0px 50%; color:#c00 !important; }
    .messages.success {background: #E0FBCC; border: 1px solid #6DC70C; } 
    .messages.success p { background: url(images/messages/tick.png) no-repeat 0px 50%; color: #2B6301 !important; }
    .messages.warning { background: #FFFCD3; border: 1px solid #EBCD41; color: #000; }
    .messages.warning p { background: url(images/messages/warning.png ) no-repeat 0px 50%; color: #5F4E01; }
    .messages.information, .messages.info { background: #DFEBFB; border: 1px solid #82AEE7; }
    .messages.information p, .messages.info p { background: url(images/messages/help.png ) no-repeat 0px 50%; color: #064393; }
    .messages.information a { text-decoration: underline; }

Comments on this post

Leave a Reply

  • Security Code :


    − one = 3