Solved

combining a text only and text size function with php

Posted on 2006-11-27
3
230 Views
Last Modified: 2011-09-20

I have two things working and want to combine them


firstly a text only on/off switcher which I am going to use to import the stylesheets


$text_only = isset($_GET['text_only']) ? $_GET['text_only'] : 1;

 if ($text_only==1) {
 ?>
<a href="<?php echo $_SERVER['PHP_SELF'];?>?text_only=0">off</a>
// import css here
<?
}
else {
?>
<a href="<?php echo $_SERVER['PHP_SELF'];?>?text_only=1">on</a></span>
// import css here
<?
}
?>


secondly the text size links


<a href="<? $_SERVER['PHP_SELF'];  ?>?text_size=medium" class="size1" id="one">A</a>
<a href="<? $_SERVER['PHP_SELF']; ?>?text_size=larger" class="size2" id="two">A</a>
<a href="<? $_SERVER['PHP_SELF']; ?>?text_size=largest" class="size3" id="three">A</a>


<?
$text_size = isset( $_REQUEST['text_size'] ) ? $_REQUEST['text_size'] : '';

switch ($text_size) {
case "medium":
?>
<link href="css/medium.css" rel="stylesheet" type="text/css" />
<?
break;
case "larger":
?>
<link href="css/larger.css" rel="stylesheet" type="text/css" />
<?
break;
case "largest":
?>
<link href="css/largest.css" rel="stylesheet" type="text/css" />
<?
break;
}
?>

these work great independently but when I use one the other switches off. any ideas how I can combine them?


Ross
0
Comment
Question by:roscoeh23
  • 2
3 Comments
 
LVL 8

Accepted Solution

by:
Autogard earned 500 total points
ID: 18023308
The key is to pass both values in the URL.  To do that you just append your parameters with a "&":

http://www.mydomain.com/mypage.php?text_only=0&text_size=largest

To get this to happen, just do something like this:

<a href="<? $_SERVER['PHP_SELF'];  ?>?text_size=medium&text_only=<?php echo $_GET['text_only']; ?>" class="size1" id="one">A</a>

This is assuming that they first went to the page and selected text-only, and then when the page reloaded they can then select which size of text they want.  You will need to incorporate this code with some condition checking to see if $_GET['text_only'] is set, etc...
0
 

Author Comment

by:roscoeh23
ID: 18026519
it needs to remember what values are set and then keep them from page to page. I suspect a cookie or session is required and also a way of combining the values.


my css for the divs are simple they just have stuff like

div {

font-size:120%

}



for the text only I am just shutting off all css except the font-size ones.

Ross
0
 
LVL 8

Assisted Solution

by:Autogard
Autogard earned 500 total points
ID: 18028522
OK,

One way to do it is through sessions, yes.  Another way is just to keep passing it from page to page.  Sessions is probably the better idea, though.

If you want to use sessions you can do something like:

# Start your session
session_start();

# Check if a new value is passed in
$_SESSION['text_only'] = isset($_GET['text_only']) ? $_GET['text_only'] : 1;

# Now do your css stuff based on what the $_SESSION['text_only'] value is set at
...

Then you do the same kind of thing on the text_size.  Basically, as long as the person has their browser open the $_SESSION values will hold, until you change them of course.

Take a look at http://us2.php.net/manual/en/ref.session.php for more info on sessions.

As for cookies, you could probably use them, but from what I understand they are more for keeping their choices from session to session.
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question