Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
//create table if doesn't exist
try
{
$mysql_conn->exec("CREATE TABLE IF NOT EXISTS peukku_viestit (
	id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, 
	message VARCHAR(500), 
	parent INT DEFAULT -1, 
	rating INT DEFAULT 0, 
	user_id INT, 
	submit_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP)");
}catch (PDOException $e){
	die("Virhe: " . $e->getMessage());
}

Luodaan käyttäjälle istunto, jonka perusteella hänet voidaan yksilöidä. $_

Code Block

// create session cookie
session_start();

if (!isset($_SESSION['session']) || !isset($_SESSION['token']))
{
	// this variable is to make sure we get post from correct form
	// we will add it to every form as a hidden field
	$_SESSION['token'] = uniqid(md5(microtime()), true); 
	// this is for making it harder to hijack one's session cookie 
	// save ip and user agent which created the session
	$_SESSION['session'] = md5($_SERVER['REMOTE_ADDR'] . $_SERVER['HTTP_USER_AGENT']); 
}

2.2.2 Lähetetyn tiedon käsittely

...