0

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>
Canttouchit
  • 3,149
  • 6
  • 38
  • 51
  • If the form isn't already on HTTPS, there is no way to do that. – Pekka Jun 30 '13 at 08:47
  • You want to tell me that each time I sign up to a site it is opening a new html page in https, for credentials? – Canttouchit Jun 30 '13 at 08:51
  • You can use Ajax, too. But you'll probably have to give it an absolute path. Why don't you want that? – Thilo Jun 30 '13 at 08:52
  • @Alon well, no - but when they switch from http to https, those other sites don't have a problem specifying an absolute path. Why do you? – Pekka Jun 30 '13 at 08:53
  • I've never uploaded a website to the internet before, I don't know yet if I'd gave to use absolute path or not so I'd like to keep it as flexible as possible. – Canttouchit Jun 30 '13 at 08:54

1 Answers1

1

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 . '"....'; 
hek2mgl
  • 152,036
  • 28
  • 249
  • 266
  • I don't understand. I'm using action="databasebuilder.php". I don't want client to load page in https I want only the action to be performed in https – Canttouchit Jun 30 '13 at 08:48
  • 3
    Loading the page over http and send the form with https using a relative path is not possible. Either use an absolute path or load the page using https – hek2mgl Jun 30 '13 at 08:51
  • But using an absolute path will force me to change the code once it is uploaded to the real server? no – Canttouchit Jun 30 '13 at 08:57
  • yes. since you have `location.host` it is possible. Maybe this helps you further: Or check this: stackoverflow.com/questions/4140324/parse-url-with-javascript – hek2mgl Jun 30 '13 at 09:33
  • Well correct me if I'm wrong but to do it in JS will be a mistake since I need the location of the server and the Javascript will run on client side once I'd upload the files to the server. So I suppose the PHP is the only option here – Canttouchit Jun 30 '13 at 09:47
  • 1
    `location.host` will contain the name of the *server* where the page has been loaded from – hek2mgl Jun 30 '13 at 09:49