05.05.2013 Views

Programming PHP

Programming PHP

Programming PHP

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Example 7-13. Setting preferences with sessions (continued)<br />

session_start();<br />

session_register('bg');<br />

session_register('fg');<br />

$bg_name = $_POST['background'];<br />

$fg_name = $_POST['foreground'];<br />

$bg = $colors[$bg_name];<br />

$fg = $colors[$fg_name];<br />

?><br />

Example 7-14 shows Example 7-12 rewritten to use sessions. Once the session is<br />

started, the $bg and $fg variables are created, and all the script has to do is use them.<br />

Example 7-14. Using preferences from sessions<br />

<br />

<br />

Front Door<br />

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!