NYCPHP Meetup

NYPHP.org

[nycphp-talk] newbie - square one

Jeff Siegel jsiegel1 at optonline.net
Tue Dec 2 08:06:24 EST 2003


Sarah,

"So for this link, I know I would put "somepage.php?params=value"
cause this is the syntax of a query string and how one passes params
via HTTP, but.... in the somepage.php, what do I do? Where do
I put the first <?php ... ?> stuff? How do I extract "params" as
a variable and get its user-selected value?

The documentation seems to imply I would just put:

<?php
$params=value;
...
?>"

Here's the basics:
	You've got "somepage.php?params=value". To grab that value you could 
use something like the following on somepage.php:
	$sMyValue = $_GET['params'];
You could put this at/near the top of the page within the php tags 
since, I assume, the remainder of the page is based on the user's selection.

You'll want to use some sort of test to make sure that the value of 
$_GET['params'] is a legitimate value since a user can muck around with 
a value that is appended to a URL. So...if you used a switch statement, 
(http://us4.php.net/manual/en/control-structures.switch.php) you could 
have a default value to handle the case where the user has played around.

Don't forget that PHP is server-side and Javascript is client-side. I 
believe some others on the list can address the issue of having the two 
communicate...in a sense.

Please keep in mind, having been burnt badly by this, that some users 
will intentionally turn off Javascript "just to see what happens" so 
that, depending on what you're trying to do with the Javascript, it can 
really create a mess.

Jeff Siegel
	

-sry wrote:
> Okay, here's a really, REALLY basic question. I always seem to
> get the high-level stuff and miss the basics (kinda like Algebra
> stumps me even with a calculator but Calculus I do in my head :*)
> 
> I've RTFM at php.net - very nice docs, like the searchability and
> index. Good online reference book. Alas, I want to do my very
> first PHP page--well, okay, not the first, I did a "Hello world" and
> phpinfo.php and those went fine and told me a bunch about my
> installation, all well and interesting, but now I want to do something
> I can actually USE.
> 
> Let's say I have a page somepage.html and it has an onLoad(params) 
> function in the BODY tag that currently calls some JavaScript
> funciton. Elsewhere on the page, I have a bunch of links to a PHP version 
> of somepage.html and want to pass it different "params" for each of the
> links, each of which will "convert" the JavaScript/HTML behavior into 
> PHP/HTML behavior and do something different with the onLoad()
> depending on which "params" value is clicked by the user.
> 
> Never mind if this how to actually do it - I know I should just start
> with a php page, but I want to do it this way to LEARN, okay?
> If I change too many things at once, I will get lost on what is 
> actually happening; my debugging habits are old and fixed. I can
> only change one thing at a time or I miss the problem completely.
> 
> So for this link, I know I would put "somepage.php?params=value"
> cause this is the syntax of a query string and how one passes params
> via HTTP, but.... in the somepage.php, what do I do? Where do 
> I put the first <?php ... ?> stuff? How do I extract "params" as
> a variable and get its user-selected value? 
> 
> The documentation seems to imply I would just put:
> 
> <?php
> $params=value;
> ...
> ?>
> 
> and that the query string will have "created" the variable $params
> and somehow PHP will "know" what's in the query string and
> "value" will be defined...really? I don't have to extract some 
> ENV-VAR like old-fashioned CGI processing?
> 
> And since the assignment I want to do is in the BODY tag, how
> do I write the body tag with a PHP variable? like this:
> 
> <?php
> $params=value;
> echo "<BODY onLoad=\"myJavaScriptFunc(\" + $params + \");\" ";
> ?>
> 
> That didn't seem to do it for me so I must have misread or
> misunderstood the docs. Enlighten my ignorant self, someone?
> 
> -sry
> ----------------------------------------------------------------------
> Sarah R. Yoffa
> http://www.sarahryoffa.com/
> sryBoston at hotmail.com
> "Stupid rules are meant to be changed, not broken."
>       [-sry on sci.space.shuttle, c. 1993]
> ----------------------------------------------------------------------
> _______________________________________________
> talk mailing list
> talk at lists.nyphp.org
> http://lists.nyphp.org/mailman/listinfo/talk
> 




More information about the talk mailing list