Th0ughts Posted September 28, 2009 Share Posted September 28, 2009 Hi guys, I'm brand new to php, I know nothing about it (except for some very basics). I'm coding a desktop app which I would like to have some small amount of protection, so I am implementing a PHP hardware id grabber. Basically, what I would like doesn't have to be secure server side, as I will do all security client side. Okay, now to what I am having problems with! I just need a simple passworded page. I found this example here which works (only not how I'd like...) http://www.stevedawson.com/article0014.php What I'd like to do is use something like that but... site.com/protectedpage.pgp?password=xxxxxx with the above script, this doesn't seem possible. I'd appreciate all help! tl;dr: script where i can type ?variable=value in the url which, if the "password" is correct, will then display plain text. Quote Link to comment Share on other sites More sharing options...
Alex Posted September 28, 2009 Share Posted September 28, 2009 The is used to get variables from the query string in the URL. Basic example: if($_GET['password'] == 'somepassword') { echo 'Text..'; } else { echo 'Incorrect password'; } Quote Link to comment Share on other sites More sharing options...
Th0ughts Posted September 28, 2009 Author Share Posted September 28, 2009 Thanks! One more question regarding this subject... Is it possible to have multiple passwords and have them echo different text? Would I do something like: [/url] if($_GET['password'] == 'somepassword') { echo 'Text..'; } else { if($_GET['password'] == 'anotherpass') echo info2 else if($_GET['password'] == 'yetagainanotherpass' echo info3 else echo wrong pass It seems very rudimentary to do it that way, and I'm sure it will cause errors too. Thanks again... EDIT: I realize that I didn't format that properly, I was just trying to get my point across. Quote Link to comment Share on other sites More sharing options...
Alex Posted September 28, 2009 Share Posted September 28, 2009 You could use an else if Like so: if($_GET['password'] == 'somepass1') { echo 'Some text 1'; } else if($_GET['password'] == 'somepass2') { echo 'Some text 2'; } else { echo 'Wrong password'; } Tip: Brackets around conditional statements aren't required unless you're evaluating more than one expression between them. Since you're only preforming one echo in the above you could also do this (with the same exact effect). if($_GET['password'] == 'somepass1') echo 'Some text 1'; else if($_GET['password'] == 'somepass2') echo 'Some text 2'; else echo 'Wrong password'; That being said, just addressing your specific question about conditionals, I would actually do it another way; utilizing a PHP switch statement. Like so: switch($_GET['password']) { case 'pass1': echo 'Something'; break; case 'pass2': echo 'Something else'; break; default: echo 'Wrong password'; break; } Quote Link to comment Share on other sites More sharing options...
Th0ughts Posted October 2, 2009 Author Share Posted October 2, 2009 You could use an else if Like so: if($_GET['password'] == 'somepass1') { echo 'Some text 1'; } else if($_GET['password'] == 'somepass2') { echo 'Some text 2'; } else { echo 'Wrong password'; } Tip: Brackets around conditional statements aren't required unless you're evaluating more than one expression between them. Since you're only preforming one echo in the above you could also do this (with the same exact effect). if($_GET['password'] == 'somepass1') echo 'Some text 1'; else if($_GET['password'] == 'somepass2') echo 'Some text 2'; else echo 'Wrong password'; That being said, just addressing your specific question about conditionals, I would actually do it another way; utilizing a PHP switch statement. Like so: switch($_GET['password']) { case 'pass1': echo 'Something'; break; case 'pass2': echo 'Something else'; break; default: echo 'Wrong password'; break; } Thanks a ton! If I ever decided to implement a username system, it would go something like this, right? if($_GET['user'] == 'someuser1') { if($_GET['password'] == 'somepass1') { echo 'Some text 1'; } Quote Link to comment Share on other sites More sharing options...
Gayner Posted October 2, 2009 Share Posted October 2, 2009 Ur missing a } Quote Link to comment Share on other sites More sharing options...
Th0ughts Posted October 2, 2009 Author Share Posted October 2, 2009 Ur missing a } Right, it would go at the end to signify the end of the if command/actions, right? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.