Re: (PHP) Passing Variables Through URLs

  • From: "E.J. Zufelt" <everett@xxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Mon, 22 Dec 2008 10:04:23 -0400

Good morning,

You are correct. I believe that you used to be able to just use the variable, but this is turned off by default in most modern php installations.

I would recommend not passing the information to each URL, but using a session variable or a cookie to save the user's choice.

HTH,
Everett


----- Original Message ----- From: "tribble" <lauraeaves@xxxxxxxxx>
To: <programmingblind@xxxxxxxxxxxxx>
Sent: Monday, December 22, 2008 10:01 AM
Subject: Re: (PHP) Passing Variables Through URLs


Hi Jared --
First, when you type echo <<styles, don't you need to terminate the input
with the word 'styles' appearing on a line? Maybe I'm mistaken -- I never
used echo in this way in php.)

Second, you are passing variables as part of a URL, so in your receiving
file you should use something like

$css = $_GET["css"];

If I am mistaken, someone please correct me. I don't have a way of testing
it on my current computer.

Anyway, try that and see what happens.
--le

----- Original Message ----- From: "Jared Wright" <wright.jaredm@xxxxxxxxx>
To: <programmingblind@xxxxxxxxxxxxx>
Sent: Monday, December 22, 2008 7:29 AM
Subject: (PHP) Passing Variables Through URLs


'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

__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind


__________
View the list's information and change your settings at //www.freelists.org/list/programmingblind

Other related posts: