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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.