Saturday, 24 December 2016

Send/receive Multiple Checkboxes Value on Another Page in PHP

Some time we require to populate multiple checkboxes on web page and send these values to another page or save in database. foe example some time we get the list of students from database and take their attendance by just clicking checkboxes for them.

How to create multi select checkboxes? see the example by clicking here.

To create multiple checkboxes use following code

<form id="xyz" action="2.php" method="post" target="">
<input name='rid[]' type='checkbox' class='checkbox' value="1" />
<input name='rid[]' type='checkbox' class='checkbox' value='2' />
<input name='rid[]' type='checkbox' class='checkbox' value='3' />
<input name='rid[]' type='checkbox' class='checkbox' value='4' />
 <input type="submit" name="submit" value="Get Selected Certificates" />
</form>



On the another page receive the value of checkboxes using PHP code


        if(!empty($_POST['rid'])) 
        {
                echo "<h2> You have selected: </h2>";
                foreach($_POST['rid'] as $chvalue)
              {
                echo $chvalue;

               }
        }



Thursday, 1 December 2016

How to manage session from login to logout in Java.

An application may begin with some kind of user identification and validation that must be propagated through several other Web pages. Several approaches can be taken to accommodate this need, depending on the requirements of the application. Because the Web server doesn’t remember clients from one request to the next, the only way to maintain a session is for clients to keep track of it.
Without going into details about session concept (you can get it from web), I focus on programming techniques to manage session in web applications.
How to create session?
HttpSession session = req.getSession(true);
Above code will create session on server.
To use class HttpSession, you will have to import package by using code
import javax.servlet.http.*;
How to set session value?
After creation of session, we required to set session value using following code
session.setAttribute("session name", “session value”);
How to print session value?
out.println((String)session.getAttribute("session name"));
How to remove session?
session.removeAttribute("session name");
How to allow to access page content if session is created (means authenticated user is logged in and session is created) and denied if session is not created?
Login example 1 click here
Login example 2 click here

It is a basic requirement of validating authenticated user on every page if he/she has logged in till his/her logged out. You can use following code.
if(session.getAttribute("session name")!=null)
{
// page content if user is valid
}
else
{
out.println("you are not logged in");
}
How to destroy session?
If user want to be logged out from his/her session, you can provide logged out facility to destroy session using code
session.invalidate();



Change image source dynamically on hyperlink

 Changing image source dynamically using JQuery. Here in this example I have created there hyperlink and stored all images in the same folde...