Displaying Javascript once per session

There are situation ( like displaying a javascript  ad for example) where you'd want the Javascript to appear only once per browser session .

 This can be done using php isset() function : 

if(!isset($_SESSION['SAWAD'])){

echo ' Javascript source here ' ;

$_SESSION['SAWAD']=1;   // This will set the SESSION variable SAWAD , so next time javascript source will not be displayed//

}

?> 

 

  • ! reverses the value of  isset()
  • isset()  returns 1 if variable inside () is set

 

so if SESSION variable SAWAD has not been set , if statement will succeed