(PHP) Passing Variables Through URLs

  • From: Jared Wright <wright.jaredm@xxxxxxxxx>
  • To: programmingblind@xxxxxxxxxxxxx
  • Date: Mon, 22 Dec 2008 08:29:28 -0500

'llo all, I have the following PHP code at the bottom of each page on a site to allow the user to change the style sheet used to display the content.


---

<?php
echo <<<styles
<a href=$page.php?css=standard>Normal Colors</a> - <a href=$page.php?css=schoolcolors>HS Colors (vaguely)</a> - <a href=$page.php?css=othercolors>Other Colors</a></br></br>
?>


---

And in my PHP file that places the head and navigation bar into each page, I have:

---


<?php
if ($css==null) {
$css = "standard";
}
echo "<head><link rel=\"stylesheet\" type=\"text/css\" href=\"Stylesheets/$css.css\"/>
<title> $title </title></head>";
?>

---

$page and $title are defined on each specific webpage. But the one place where I try to pass variables within the URL is setting $css. However, when I click any of the links that reload the page with this CSS variable defined from that first section, nothing seems to change in what is sent to the browser by the second chunk. When I check the source of the new page, it's still referencing standard.css in the head. Anyone know what might be sticking me? I'm still awfully green with PHP, so please point out any dumb trivial thing I might have done. In just typing this, I realized that I don't know if it's because the if statement is for some reason throwing $css back to "standard" each time because I'm passing $css incorrectly somehow and it is null when that gets evaluated... Do I have to define $css in the second piece of code and then only define, not declare, it with the URL? I thought PHP would create the variable on the fly, but like I said, I'm green. Thanks in advance for any help.

Jared


P.S. If you're reading that code with your eyeballs, I apologize. *smile*
__________
View the list's information and change your settings at //www.freelists.org/list/programmingblind

Other related posts: