如何使用https在localhost上安全地从客户端向服务器发送密码

问题描述:

I looked for hours and I couldn't find a solution to my problem.

I'm currently testing a website on my laptop(local host). My site has a server side(php) and a client side.

I'm looking for away to send password using HTTPS, without specifying the absolute path. (My php and html are in the same directory)

My code looks like that:

      <!-- Submit data to server-side -->
      <form name="input" action="databasebuilder.php" method="post">
          <ul>
             <li>User name: <input type="text" name="user"> </li>
             <li>Password: <input type="text" name="password"> </li>
             <li>First name: <input type="text" name="name"> </li>
             <li>Last name: <input type="text" name="last"> </li>
             <li>Email: <input type="text" name="email"> </li>
         </ul>
             <input type="submit" value="Submit">
     </form>

Either choose an absolute path or make sure that the page will be loaded using HTTPS. If the user types

http://localhost/...

in browser, your web application should redirect to:

https://localhost

You can ensure this for example using PHP or apache's mod_rewrite


You can create the absolute path dynamically using PHP. Have a look at this example:

$path  = 'https://';
$path .= $_SERVER['HTTP_HOST'] . '/';
$path .= 'path/to/your/app/action.php';
echo '<form action="' . $path . '"....';