Anyone know PHP

jaguar • Mar 6, 2003 1:57 am
I've been doing a few little things in PHP over the last week for a particular purpose and i'm confused about one thing

I've got a script that refers to itself when it runs, checking a value ($id) that would have been set if the page/script is beign viewed for the second time

the code to check that is

if ($id) {

blahblabla

}

Which as i thought checked that $id existed (in the url). It doesn't seem to work. If i get $id to check against a certain value i know it will be it works, but clearly the person who told me this was wrong or i've totally missed something.

Any ideas from the crowd?
Skunks • Mar 6, 2003 10:52 am
Newer installs of PHP have a config option (register_globals) off. When it is on, GET, POST, and cookie variables are automagically set. Load foo.php?bar=baz, and $bar will be 'baz' within the script. It was disabled by default to protect people with horribly atrocious coding standards from people sending them bogus value and faking authentication.

Use $_GET['id'].
Undertoad • Mar 6, 2003 10:55 am
Also, personally speaking I avoid such shortcuts. C programmers love to write weird conditions that take hours to figure out. That's not so critical when performance is not the major factor. If I have a php script that goes to page two, I write something really bloody obvious like

if ($page2 == "yes")
// --- Page TWO section ----------------

...because even though it takes more effort now, it means I'll be able to figure out what I did a year from now, when I've forgotten the whole project and the client wants me to change the whole thing.
dave • Mar 6, 2003 11:29 am
I would be fired if I didn't write clean, well-commented code. I'm in the habit now of writing more comment than code. It's just something you get used to.
blowmeetheclown • Mar 6, 2003 1:24 pm
I've always had the mindset that if your vars and funcs were well-named, then you wouldn't necessarily need to comment. Then my last perl script came to 1500 lines before completion. Yikes!
dave • Mar 6, 2003 1:29 pm
That's how I used to be. Unfortunately, they don't stand for that shit here.
russotto • Mar 6, 2003 4:55 pm
If you can't understand it from a non-symbolic disassembly listing, you don't belong in the business, that's what I always say.
Cam • Mar 6, 2003 6:22 pm
I realized this week that I have no idea how to program in Java anymore, I took it my first semester and now couldn't write a line of code without a book.

Okay I'm done crying now.
jaguar • Mar 7, 2003 7:28 am
Thanks skunks, the info dated to php3 (which i was not aware of). It's not anything related to anything authish so faking a var is not an issue, though i'll admit it's sloppy as hell, php is not a language i claim to know at all, i'm just playing around atm.

UT the code is commented etc, i just put the minimum to get the point across.