简体   繁体   中英

Website Signup and Login using javascript?

I don't know how to store sign up and login details in JavaScript. I used php and database to store information on my previous project so I have no idea how to do it in JavaScript.

Below is the sign up html code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Registration</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="keywords" content="Game Website Template, free templates,
             website templates, CSS, XHTML" />
<meta name="description" content="Game Website Template - download free 
            XHTML/CSS files from templatemo.com" />
<link href="templatemo_style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="templatemo_wrapper_outer">
<div id="templatemo_wrapper_inner">

    <div id="templatemo_banner"></div> <!-- end of banner -->

    <div id="templatemo_menu">
        <ul>
            <li><a href="index.php">Home</a></li>
            <li><a href="Game.php">Games</a></li>
            <li><a href="My Profile.php">Profile</a></li>
            <li><a href="#">Download</a></li>
            <li><a href="#">Contact</a></li>
        </ul>
    </div> <!-- end of menu -->

<h1> Online game shop </h1>

<h2> Enter the details bellow. </h2>
<form method ="POST" action = "PHP.php" >

<h9> *Compulsory fields    </h9>
<br>
<br>
 *First Name <input type="text" name="fname" 
           class="form-control" placeholder="First Name" required/> <br>
<br>
 *Last Name  <input type= "text" name="lname" 
         class ="form-control" placeholder="Last Name" required/>
<br>
<br>
 *E-mail Address <input type="email" name="Eadd"class="form-control" 
           placeholder="E-mail Address" required/> 
<br>
<br>
 *Mobile number <input type="int" max="10" min="10"name="Mnum" 
          class="form-control" placeholder="mobile Number" required/> 
<br>
<br>
 *Password <input type="password"name="pass" 
          class="form-control" placeholder="Password" required/> 
<br>
<br>
*Confirm Password <input type="password"name="Cpass" 
          class="form-control" placeholder="Confirm Password" required/> 
<br>
<br>
    *Gender <br>
<input type="radio" name="gen" value="m">Male<br>
 <input type="radio" name="gen" value="f">Female
<br>
<br>
<button type="submit" class="btn btn-default">Submit</button>
</div>
</form>
<div id="templatemo_footer">
        Copyright © 2048 <a href="#">Your Company Name</a> 
    </div> <!-- end of footer -->
</body>
</html>

Please note that the above code is from my previous project and still has php in, so I want to remove the php and store the information the user provides using javascript.

Any help would be appreciated !

This is the server code, but its only for the first name field, I was trying it out but failed.

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class info extends HttpServlet {
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
//String s, goods[] = {"Fifa 15", "Battlefield 5", "GTA 6"};
String name= req.getParameter("fname");

//int price []={10,20,30};
//int cost;
PrintWriter out = res.getWriter();
res.setContentType("text/html");
HttpSession session = req.getSession(true);

if ( session == null ) return;
//for (int i = 0; i < goods.length; i++)
//if ( session.getAttribute(name) != null )
session.setAttribute(name, new Integer(0) );

out.println("<html><body><h2>You are Registered !! </h2><ul>");


out.println("</ul></body></html>");
}
}

You can't use a client side language for server side scripting.. if you want to use javascript, use node.js or something. Just for the sake of clarification, javascript runs in the users browser and all changes to HTML/CSS are made in the clients browser, while php runs on the server before sending the HTML to the client. have a read on JavaScript

You can't store login details using just JavaScript. You can use node.js if you want to stick with JavaScript to make server calls. Otherwise you'll want to pass the login details to PHP which can be done as a form submission or an AJAX call.

You could do a challenge response in javascript, but still you need to have some sort of server call.

Creating challenge-response sign-in

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