开发者

Insert login creditials in php url?

开发者 https://www.devze.com 2023-03-31 09:30 出处:网络
I am trying to be able to log-in to开发者_运维技巧 a PHP webpage with the credentials in the URL.

I am trying to be able to log-in to开发者_运维技巧 a PHP webpage with the credentials in the URL.

Example:

http://www.mywebsite.com/logon.php?logon=user&password=password

The URL above inserts user and password into the text fields but does not submit the page and continue.

  • How do I submit a page via URL?
  • Is it possible? If not, sorry for the question.


There are two versions of the answer, here: how to do what you asked, and how to do what you actually want. Chances are you don't actually want to do it the way you asked, because passing the password in the URL field is a super-bad idea. To answer the question as asked, it goes like this:

  • To read the values out of the URL string, you can use the $_GET array. To print what logon is passed, do:

    echo($_REQUEST[logon]);
    

    To submit the data in the first place, you'll need to use a form. There are other methods, but this is the most basic. Something like this:

    <form action="logon.php" method="get">
    <input name="logon">
    <input name="password">
    <input type=submit value="Login">
    </form>
    
  • That being said, better practice would be to pass the password through the POST parameter, which at least isn't visible in the addressbar. To do this, simply substitute:

    <form action="logon.php" method="post">
    <input name="logon">
    <input name="password">
    <input type=submit value="Login">
    </form>
    


It depends on how the website's login system is designed:

  • The form: The names of the username and password fields need to be the same as in your url
  • The PHP: Most forms use a HTTP POST method to send their data to their server. What you are doing is sending data using a HTTP GET method.
0

精彩评论

暂无评论...
验证码 换一张
取 消