new to PHP

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....


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-28-2004
Stewart Robert Hinsley
 
Posts: n/a
Default new to PHP

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
Reply With Quote
  #2 (permalink)  
Old 04-28-2004
Chung Leong
 
Posts: n/a
Default Re: new to PHP


"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.


Reply With Quote
  #3 (permalink)  
Old 04-28-2004
Phil Roberts
 
Posts: n/a
Default Re: new to PHP

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/
Reply With Quote
  #4 (permalink)  
Old 04-28-2004
Stewart Robert Hinsley
 
Posts: n/a
Default Re: new to PHP

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
Reply With Quote
  #5 (permalink)  
Old 04-29-2004
Terence
 
Posts: n/a
Default Re: new to PHP

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 ----
Reply With Quote
  #6 (permalink)  
Old 04-30-2004
Dan Tripp
 
Posts: n/a
Default Re: new to PHP

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/
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 08:47 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0