![]() |
Anyone know PHP
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? |
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']. |
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. |
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.
|
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!
|
That's how I used to be. Unfortunately, they don't stand for that shit here.
|
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.
|
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. |
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. |
All times are GMT -5. The time now is 02:27 PM. |
Powered by: vBulletin Version 3.8.1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.