Jump to content

URL Password in PHP


Th0ughts

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/175750-url-password-in-php/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/175750-url-password-in-php/#findComment-926161
Share on other sites

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;
}

Link to comment
https://forums.phpfreaks.com/topic/175750-url-password-in-php/#findComment-926162
Share on other sites

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';
}

Link to comment
https://forums.phpfreaks.com/topic/175750-url-password-in-php/#findComment-928807
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.