duanmei4149 2013-04-25 22:30
浏览 50
已采纳

在PHP MySQL中将用户名传递给url

I am developing a site in PHP that allows users to sign up and enter in some information, and I would like to give each user a unique URL. When the user logs in to his profile, I want JUST the username to be passed to the URL (like www.mysite.com/profile.php?user=username) in order to rewrite it later. However, I'm using the $_POST method, and I'm concerned if I use $_GET while logging in the password will be passed to the URL as well. What should I do?

  • 写回答

4条回答 默认 最新

  • dtuqxb3884 2013-04-25 22:35
    关注

    There shouldn't really be a problem doing this. You could simply use a POST method that points to a URL with a GET parameter.

    So you make a POST request to:

    www.mysite.com/profile.php?user={$username}
    

    This way the user variable in the URL doesn't need to be used in the authentication.
    Consider this for a simplistic example:

    <form method="post" action="/profile.php?username=hasan">
      <input type="text" name="username" value="hasan" />
      <input type="text" name="password" value="********" />
    </form>
    

    The URL you are posting to doesn't have to be hard coded either - you could always dynamically add the user name before submitting the form.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?