Hello World

Click Here


C:6:"Artist":55:{a:2:{s:5:"first";s:5:"Pablo";s:4:"last";s:7:"Picasso";}}


Unserialized Var Dump:
object(Artist)[2]
  private 'firstName' => string 'Pablo' (length=5)
  private 'lastName' => string 'Picasso' (length=7)


(key) One:

(value) Two

Nothing yet!



























assignment08a.php:
<?php
    
include('artist.php');
?>
<?php    
    session_start
();
    
    if (!isset(
$_SESSION['user']) ) {
        
$_SESSION["user"] = "Fred";
    }
    else {
        
// No one is logged in (guest)
    
}    
?>
<?php
    
// add 1 day to the current time for expiry time
    
$expiryTime time()+60*60*24;
    
    
// create a persistant cookie
    
$name "Username";
    
$value "Ricardo";
    
setcookie($name$value$expiryTime);
    
    
// create a session cookie
    
$name2 "Counter";
    
$value2 0;
    
setcookie($name2$value2);    
    
    echo 
"Hello World <br /><br />";
    echo 
"<a href='assignment08b.php'>Click Here</a>";
    echo 
"<br /><br /><br />";
?>
<?php
    $picasso 
= new Artist("Pablo""Picasso");
    
$p_serial serialize($picasso);
    echo 
$p_serial;
    echo 
"<br /><br /><br /> Unserialized Var Dump:<br />";
    
var_dump(unserialize($p_serial));
    echo 
"<br /><br />";
?>

<html lang="en">
    <head>
        <meta charset="utf-8" />
        <link rel="stylesheet" type="text/css" href="css/bucky.css">
        <script type="text/javascript" src="js/bucky.js"></script>
    </head>
    <body>
        <section id="leftbox">
            <form>
                <p>(key) One: <input type="text" id="one"></p>
                <p>(value) Two <textarea id="two"></textarea></p>
                <p><input type="button" id="button" value="Save"></p>
            </form>
        </section>
        <section id="rightbox">
            Nothing yet!
        </section>
    </body>
</html>

<?php
    
echo "<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />";
    echo 
"<strong>assignment08a.php:</strong>";
    echo 
"<br />";
    
show_source("assignment08a.php");
    echo 
"<br /><br />";
    echo 
"<strong>serializable.php:</strong>";
    echo 
"<br />";
    
show_source("serializable.php");
    echo 
"<br /><br />";
    echo 
"<strong>artist.php:</strong>";
    echo 
"<br />";
    
show_source("artist.php");
?>


serializable.php:
<?php

interface Serializable {
    
/* Methods */
    
public function serialize();
    public function 
unserialize($serialized);
}

?>


artist.php:
<?php
class Artist implements Serializable {
    private 
$firstName;
    private 
$lastName;
    public function 
__construct($first$last){
        
$this -> firstName $first;
        
$this -> lastName $last;
    }
    
// Implement the Serializable interface methods
    
public function serialize() {
        return 
serialize(
            array(
"first" => $this->firstName,
                
"last" => $this->lastName
            
)
        );
    }
    public function 
unserialize($data) {
        
// use the built-in PHP unserialize function
        
$data unserialize($data);
        
$this->firstName $data['first'];
        
$this->lastName $data['last'];
    }    
}
?>