Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 When $_GET['whatever'] has no value...
Index -> Programming, PHP -> PHP Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
HyperFlexed




PostPosted: Tue Jul 24, 2007 10:28 am   Post subject: When $_GET['whatever'] has no value...

I have a bit of a problem. I am building a site that has index.php. The page one is viewing is specified by a $_GET variable called 'page'. If I make a request to simply index.php, I get an error, because $_GET['page'] is undefined. What value does $_GET['page'] have when it isn't specified in the URL? I guessed the empty string "", but this doesn't seem to work.

If all else fails, I can use MOD_REWRITE, but I'd like to avoid that if possible.
Sponsor
Sponsor
Sponsor
sponsor
Amailer




PostPosted: Tue Jul 24, 2007 11:05 am   Post subject: RE:When $_GET[\'whatever\'] has no value...

Nothing, its not set

use if isset(variable) to check if its set
HyperFlexed




PostPosted: Tue Jul 24, 2007 11:33 am   Post subject: RE:When $_GET[\'whatever\'] has no value...

Perfect Smile

THANK YOU!
md




PostPosted: Tue Jul 24, 2007 9:38 pm   Post subject: RE:When $_GET[\'whatever\'] has no value...

isset() returns if a variable has been set, it's a much better way of checking then seeing if it equals nothing
rizzix




PostPosted: Tue Jul 24, 2007 11:16 pm   Post subject: RE:When $_GET[\'whatever\'] has no value...

PHP is a badly designed language. Please try developing in something else.
octopi




PostPosted: Wed Jul 25, 2007 8:02 am   Post subject: Re: When $_GET['whatever'] has no value...

Rizzix, care to provide examples.

Once you master the 'unique' naming scheme used by php (for functions) I don't find it bad at all.
PaulButler




PostPosted: Wed Jul 25, 2007 10:29 am   Post subject: Re: When $_GET['whatever'] has no value...

octopi @ Wed Jul 25, 2007 8:02 am wrote:
Once you master the 'unique' naming scheme...


Or lack therof Razz

namespace_verb_noun (id3_get_tag)
namespaceverbnoun (imagecreatefromjpeg)
namespace_verbnoun (imap_getmailboxes)

The "namespaces" really being pesudo-namespaces, since PHP does not have any way to define namespaces or packages. There is not even consistency within pseudo-namespaces:

strpos
str_replace
Tony




PostPosted: Wed Jul 25, 2007 11:04 am   Post subject: RE:When $_GET[\'whatever\'] has no value...

Combo points for when your function names accidentally conflict with some arbitrary package.

PHP also tends to manifest horrible mess of a code. phpBB's index.php file has more lines of code than the entire codebase of the webapp I'm developing at work (Ruby/RoR)
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Sponsor
Sponsor
Sponsor
sponsor
McKenzie




PostPosted: Wed Jul 25, 2007 4:39 pm   Post subject: Re: When $_GET['whatever'] has no value...

Seems to me, if you are going to have a PHP section though, it should be to promote PHP, not simply tell people to develop in some other language. PHP is limited. But it is also very simple and widely used, and I would argue worth knowing how to use.
rizzix




PostPosted: Wed Jul 25, 2007 11:14 pm   Post subject: RE:When $_GET[\'whatever\'] has no value...

Well it has some serious security issues. PHP makes it easy to write really bad code. There are other languages that are probably equal on grounds with PHP on language security, but at least they have some really solid frameworks that accounts for the flaws.

PHP simply does not enforce any (secure) style of coding. It's very relaxed. While this is amazing for prototyping, it's bad for anything serious.

Just look at our own compsci.ca, it runs on phpbb: a php base project. It has a large number of (potential) security flaws in it self. It is also difficult to improve or maintain it. You cannot blame the phpbb programmer alone on for the quality of software. In fact phpbb is probably(?) one of the better ones out there.

Also, if one wishes to learn to develop good software, why not learn it, using language/frameworks that enforce good practises.

PS: I totally agree with teaching them how to user it properly. That's exactly what md and all have tried (above). I'm just saying that there might be better alternatives to start with. After that one can always switch if they want.
Aziz




PostPosted: Thu Jul 26, 2007 9:40 am   Post subject: Re: When $_GET['whatever'] has no value...

McKenzie @ Wed Jul 25, 2007 5:39 pm wrote:
Seems to me, if you are going to have a PHP section though, it should be to promote PHP, not simply tell people to develop in some other language.


wtd's "Why Java Sucks" topic comes to mind Hit Wall
PaulButler




PostPosted: Thu Jul 26, 2007 3:55 pm   Post subject: RE:When $_GET[\'whatever\'] has no value...

On the plus side, I just learned that PHP has anonymous (lambda) functions. They aren't very good, and you have to pass the code to create_function as a string, but PHP does have them.
wtd




PostPosted: Thu Jul 26, 2007 6:12 pm   Post subject: Re: When $_GET['whatever'] has no value...

Aziz @ Thu Jul 26, 2007 10:40 pm wrote:
McKenzie @ Wed Jul 25, 2007 5:39 pm wrote:
Seems to me, if you are going to have a PHP section though, it should be to promote PHP, not simply tell people to develop in some other language.


wtd's "Why Java Sucks" topic comes to mind Hit Wall


You might also have noticed the Introduction to Java thread.

I believe the best situation is balanced discussion. We should not simply tell people to use another programming language, but neither should we cheerlead for PHP. I think this thread fufills that goal.
PaulButler




PostPosted: Thu Jul 26, 2007 7:13 pm   Post subject: RE:When $_GET[\'whatever\'] has no value...

Well, I'm not sure a balanced discussion is necessary when someone asks a basic question about the language. I shouldn't be the one to talk, because I contributed to the PHP bashing, but the thread had already gotten a bit off-topic at that point.
rizzix




PostPosted: Thu Jul 26, 2007 8:04 pm   Post subject: RE:When $_GET[\'whatever\'] has no value...

Well, PaulButler I don't want to create a "Why PHP sucks" thread. Razz

I just thought to myself that maybe I could throw in my two cents. Heh.
Display posts from previous:   
   Index -> Programming, PHP -> PHP Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 21 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: