简体   繁体   中英

How do I pass values from html pages

I have a registration html page where there are some input fields of username, password, street,phone etc. and a submit button. Once submit button is clicked. I want the username and password being passed to another html page called login, where the user will enter the info(username,password) from registration page.

What would be the easiest way to do this? Thank you!

您可以在session中设置值,然后在任何页面中获取值之后

It seems you have multiple html pages like login, registration etc. In this case you need to hit the server each time to fetch a page. Then in the Login page those user credentials can be fetched from previously saved data only from server side (Better not to save these data in browser's session storage, cookie etc). If you have implemented in one single Html page, then you can save these values in a javascript variable. I think Single page approach will help you.

To better summarize, you would be better with a "Single Sign-On (SSO)" solution. I recommend using a MySQL database to handle the data for the logins (Most WebHosts include at least one MySQL database). How you go about setting it up is another story (Make sure to test your security by a trusted third-party). Using SSO would allow you the person to log in once, and the MySQL database would allow whatever pages it needs the data to use one document in a fixed location, fixing your "Passing" issue.

Also, Do head nnnnnn's point. It would increase your functionality (Unless you want to verify the details via email or something first).

I recommend using PHP and a MySQL Database, where you have all the Passwords and usernames in it. It's a Server based script.

So your form should be like:

<form action="script.php" method="post">
   <Input Name="username" placeholder="Username" id="username"> <br>
   <Input Name="password" placeholder="Password" type="password" id="password> <br>
   <Input Name="street" placeholder="Street" id="street"> <br>
   <Input Name="phone" placeholder="Phone" id="phone"> <br>
   <Input type="submit" value="Submit">
</form>

And in php you start like this.

<?php
   $username = $_POST['username'];
   $Password = $_POST['password'];
   $street = $_POST['street'];
   $phone = $_POST['phone'];
?>

Now you can work with the variables $username and $Password. You can write them into database, therefore you have to search for: MYSQL-Insert PHP

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM