This is a discussion on new to PHP within the PHP Language forums, part of the PHP Programming Forums category; I've just finished my first PHP script (fronted at <URL:http://www.malva ceae.info/Index/Vernacular/index....
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I've just finished my first PHP script (fronted at <URL:http://www.malva
ceae.info/Index/Vernacular/index.html). One thing is puzzling me - when parsing the query string split("&", $QUERY_STRING) works, but split('&', $QUERY_STRING) doesn't, yet split('=', <string>) does/ What subtlety am I missing? -- Stewart Robert Hinsley http://www.malvaceae.info http://www.meden.demon.co.uk |
|
|||
|
"Stewart Robert Hinsley" <{$news$}@meden.demon.co.uk> wrote in message news:tzU36XALutjAFw0v@meden.demon.co.uk... > I've just finished my first PHP script (fronted at <URL:http://www.malva > ceae.info/Index/Vernacular/index.html). > > One thing is puzzling me - when parsing the query string > > split("&", $QUERY_STRING) works, but > split('&', $QUERY_STRING) doesn't, yet > > split('=', <string>) does/ > > What subtlety am I missing? > -- Don't know, but there's parse_str() so you don't need to parse the query string yourself. |
|
|||
|
With total disregard for any kind of safety measures Stewart
Robert Hinsley <{$news$}@meden.demon.co.uk> leapt forth and uttered: > I've just finished my first PHP script (fronted at > <URL:http://www.malva ceae.info/Index/Vernacular/index.html). > > One thing is puzzling me - when parsing the query string > > split("&", $QUERY_STRING) works, but > split('&', $QUERY_STRING) doesn't, yet > > split('=', <string>) does/ > > What subtlety am I missing? Why are you doing that in the first place? PHP automatically converts query string values for you. In any case, you should be using explode() rather than split() as it is faster. split() uses regex parsing which carries an extra overhead. Would I be correct in assuming that you are coming from a Perl background? -- Phil Roberts | Dork Pretending To Be Hard | http://www.flatnet.net/ |
|
|||
|
In article <Xns94D8F095AEF02philroberts@216.196.97.132>, Phil Roberts
<philrob@HOLYflatnetSHIT.net> writes >With total disregard for any kind of safety measures Stewart >Robert Hinsley <{$news$}@meden.demon.co.uk> leapt forth and >uttered: > >> I've just finished my first PHP script (fronted at >> <URL:http://www.malva ceae.info/Index/Vernacular/index.html). >> >> One thing is puzzling me - when parsing the query string >> >> split("&", $QUERY_STRING) works, but >> split('&', $QUERY_STRING) doesn't, yet >> >> split('=', <string>) does/ >> >> What subtlety am I missing? > >Why are you doing that in the first place? PHP automatically >converts query string values for you. That's what I thought, but it didn't seem to work. Now I'm past the steep part of the learning curve, I can experiment some more. > >In any case, you should be using explode() rather than split() as >it is faster. split() uses regex parsing which carries an extra >overhead. Point taken. > >Would I be correct in assuming that you are coming from a Perl >background? > More or less (previously FORTRAN, Pascal, CORAL, C and C++). -- Stewart Robert Hinsley |
|
|||
|
Phil Roberts wrote:
> With total disregard for any kind of safety measures Stewart > Robert Hinsley <{$news$}@meden.demon.co.uk> leapt forth and > uttered: > > >>I've just finished my first PHP script (fronted at >><URL:http://www.malva ceae.info/Index/Vernacular/index.html). >> >>One thing is puzzling me - when parsing the query string >> >>split("&", $QUERY_STRING) works, but >>split('&', $QUERY_STRING) doesn't, yet >> >>split('=', <string>) does/ >> >>What subtlety am I missing? > > > Why are you doing that in the first place? PHP automatically > converts query string values for you. > Phil is correct. PHP has a solution for accessing varaibles passed in the URL. It makes them available as an associative array called $_GET This array variable is called a super-global. PHP also provides other superglobals to make accessing the environment variables easier. check them out here http://www.php.net/reserved.variables $_SESSION is particularly cool, but you need to run the session_start() function first before it works. Unfortunately the above page neglects to mention that and it has caught some people out. As a newbie, you will want to make sure you get to know PHP's session handling capabilities -- IT WILL SAVE YOU A LOT OF WORK! http://www.php.net/manual/en/ref.session.php remember that before the $_SESSION superglobal came along, it was neccesary to use the other session functions all the time, now you can do things like. <?php session_start(); if(!isset($_SESSION["uname"])) { if(blnAutheticated($_POST)) { // use form data $_SESSION["uname"] = $_POST["uname']; } else { header("Location: login.php"); // redirect them die(); } } echo "You are currently logged in as ".$_SESSION["uname"]; ?> obviously the above code requires you to write a blnAutheticated() function which accepts an associative array that it will search for authentication tokens. No fartin' about with cookies and what not... hmmm... I seem to have gotten a bit side-tracked... ------------ And now a word from our sponsor ------------------ Want to have instant messaging, and chat rooms, and discussion groups for your local users or business, you need dbabble! -- See http://netwinsite.com/sponsor/sponsor_dbabble.htm ---- |
|
|||
|
Terence wrote:
> Phil is correct. PHP has a solution for accessing varaibles passed in > the URL. It makes them available as an associative array called $_GET Or $_POST if your form uses the POST method. > obviously the above code requires you to write a blnAutheticated() > function which accepts an associative array that it will search for > authentication tokens. > > No fartin' about with cookies and what not... If you wanna fart around with cookies, though (what a weird phrase that is! ;) ) the $_COOKIES is useful. Cookies are ok, but session data is more than likely better. I'm not gonna say "always better" because somebody or other will have some example of a case where they're not... =) Regards, - Dan http://www.dantripp.com/ |