Search This Blog

Sunday, October 23, 2016


Now I am studying basic PHP coding. So trying to make a website without using Javas_script , Jquery, Ajax or any framework. So now I am facing lot of problems. But I get a major problem actually not problem it's difficult to understand to me and all of the students, that is session .  So Today I am going to share some of experience and understanding about session. I guess it will very helpful for beginners.

Login and Logout by using SESSION :

Yes I thing login and logout is the main work of a session. And yes it true. Now I am trying to make you understand how SESSION works to maintain this login and logout.  And could not give anybody to visit any page without UserName or PassWord.

Code : 
1. phpTagstart   session_start();// you are just start  session on your page. Normally it should open the        //first login check file in php .

2.  $signal="user is valid";     if(isset($_SESSION["anytext"]))
 //  Then wright this in your second line.  It means that a  //validation text which is set by you in SESSION and you push to a variable called $signal .
// this "anytext" could be anything.

if($signal=="user is valid")  {  phptegend  // And thirdly you should wright this line to check that  this text //was in this SESSION so this session page or form is valid. Some people are also called this line as //form validation.  

Wright all your php,html,java script everything in this gap  between  point 3 and point 4 .  

4. phpTagstart  }  phptegend     // Look carefully in last line (pont 3 ) we did not complete "{ " bracket.  So at the //end of the page we should use this line to close the bracket .   

  All blue code should be keep into php_tags .

( That's all. But it is not only  technich to maintain session. It's just easiest way as my opinion .)

Some Works of SESSION :

Hare are some basic works of SESSION:

1. SESSION a associative array. (It's like a global array but not global array. It's an array who can carry values from one page to another page )
    SESSION is a common space where can access from every page.

SESSION should start with this   session_start();  function declaration . After declaring one time it will continue in every page and carry value globally until session destroy. 

3. But we need to write session_start(); in every page at the upper site. I mean just after declaring 

4. We can push value form any page in session like this  $_SESSION["variable_name"] ; (no need use $) 

5. And get all value form session from every page under the session like 
 $variable = $_SESSION["variable_name"];  . But you must should see at beginning of the page should have  session_start();

6. We can also directly print any value from session like this echo "Welcome ".$_SESSION['variable_name'] ;  But make sure that this variable already pushed in the session .

No comments:

Post a Comment

Split A String By Coma (,)

Step 1.  create or replace type split_tbl as table of varchar2(32767); Step 2. create or replace function split (     p_list varchar2,...