By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,050 Members | 1,343 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,050 IT Pros & Developers. It's quick & easy.

new to PHP

P: n/a
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
Jul 17 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
With total disregard for any kind of safety measures Stewart
Robert Hinsley <{$******@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/
Jul 17 '05 #2

P: n/a

"Stewart Robert Hinsley" <{$******@meden.demon.co.uk> wrote in message
news:tz**************@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.
Jul 17 '05 #3

P: n/a
In article <Xn*************************@216.196.97.132>, Phil Roberts
<ph*****@HOLYflatnetSHIT.net> writes
With total disregard for any kind of safety measures Stewart
Robert Hinsley <{$******@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
Jul 17 '05 #4

P: n/a
Phil Roberts wrote:
With total disregard for any kind of safety measures Stewart
Robert Hinsley <{$******@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 ----
Jul 17 '05 #5

P: n/a
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/
Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.