Thursday, January 29, 2015

HTML Comment

<!--This is a comment. Comments are not displayed in the browser-->

<p>This is a paragraph.</p>

Wednesday, January 21, 2015


    <title>HTML with PHP</title> 
      <h1>My Example</h1> 
            <?php //your php code here ?> 
            <b>Here is some more HTML</b> 
            <?php //more php code ?> 
<?php  Echo "<html>"; 
Echo "<title>HTML with PHP</title>"; 
Echo "<b>My Example</b>"; 
 //your php code here 
 Print "<i>Print works too!</i>";  ?>

PHP Sessions

A session is a way to store information (in the form of variables) to be used across multiple pages. Unlike a cookie, specific variable information is not stored on the users computer. It is also unlike other variables in the sense that we are not passing them individually to each new page, but instead retrieving them from the session we open at beginning of each page.

Call this code mypage.php

<?php  // this starts the session  session_start(); 
 // this sets variables in the session  
 print "Done"; ?>

Now we are going to make a second page. We again will start with session_start() (we need this on every page) - and we will access the session information we set on our first page. Notice we aren't passing any variables, they are all stored in the session.
Call this code mypage2.php
<?php  // this starts the session  session_start(); 
 // echo variable from the session, we set this on our other page 
 echo "Our color value is ".$_SESSION['color'];
 echo "Our size value is ".$_SESSION['size']; 
 echo "Our shape value is ".$_SESSION['shape'];  ?>

All of the values are stored in the $_SESSION array, which we access here. Another way to show this is to simply run this code:

<?php  session_start();  Print_r ($_SESSION); ?>

Modify or Remove a Session

// you have to open the session to be able to modify or remove it  session_start(); 
 // to change a variable, just overwrite it
 //you can remove a single variable in the session  unset($_SESSION['shape']);
 // or this would remove all the variables in the session, but not the session itself 
 // this would destroy the session variables 
 session_destroy();  ?>