tags:

views:

19

answers:

3

So after reviewing some tutorials on how to change text size and creating my own using PHP I was wondering how can I have my text size remembered across many different pages on my web site using PHP SESSIONS?

Here is the PHP text sizer code below.

$size = 100;

if(isset($_GET['i']) && is_numeric($_GET['i'])) {
    $s = $_GET['i'];
}

if($s == TRUE){
    $size = ($s * 1.2);
}


if(isset($_GET['m']) && is_numeric($_GET['m'])) {
    $m = $_GET['m'];
}

if($m == TRUE){
    $size = ($m * 0.8);
}


if(isset($_GET['n']) && is_numeric($_GET['n'])) {
    $n = $_GET['n'];
}

if($n == TRUE){
    $size = 100;
}

Here is the CSS code.

#content {
  font-size : <?php echo $size; ?>%;
}

And here is the xHTML.

<a href="index.php?i=<?php echo $size; ?>" title=""> Increase</a><br />
<a href="index.php?m=<?php echo $size; ?>" title=""> Decrease</a><br />
<a href="index.php?n=<?php echo $size; ?>" title=""> Normal</a><br />
A: 

Just don't use $_GET variables, use $_SESSION vars instead. Be sure to include the relevant session_start() functions and all that.

eykanal
so do I change all my `$_GET` to `$_SESSION`?
How to
If you're not familiar with how to use session variables, read the tutorial mentioned in @jakeisonline's post. They're very simple to use and can be extremely helpful.
eykanal
A: 

As mentioned, you'll want to your the $_SESSION object instead of $_GET. You'll need to add a call to session_start() at the start of each page (check the examples on this link; will show you how to use sessions on a basic level). You may also want to take a look at Local Web Storage (browser-based) in HTML5. Check out this tutorial. It's quite easy to implement. Of course, not all browsers implement web storage, but it's pretty ubiquitous (Depending if you want to support < IE8)

Typeoneerror
+1  A: 

First all, make sure you out put session_start() on all pages, before any content is posted.

From here, you're able to set session variables (which will be saved into a session cookie typically).

So when your user clicks a link, PHP should set something like $_SESSION['i'] = $_GET['i']; and then when you visitor comes back to a page, you just see if $_SESSION['i'] has a value - if it does, use this value, if not, revert to default.

Check out this great tutorial: php sessions - why use them?

jakeisonline