Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE HTML>
- <html>
- <head>
- <style>
- .error {color: #FF0000;}
- </style>
- <title>Login Form</title>
- </head>
- <body>
- <?php
- /*$str = "Hello";
- echo password_hash($str,1);*/
- // define variables and set to empty values
- $nameErr = "";
- $passwordErr = "";
- $user = "";
- $password = "";
- if ($_SERVER["REQUEST_METHOD"] == "POST")
- {
- if (empty($_POST["user"]))
- {
- $nameErr = "Name is required";
- } else
- {
- $user = test_input($_POST["user"]);
- // check if name only contains letters and whitespace
- if (!preg_match("/^[a-zA-Z0-9 ]*$/",$user))
- {
- $nameErr = "Only letters,number and white space allowed";
- }
- }
- if (empty($_POST["pass"]))
- {
- $passwordErr = "Password is required";
- } else {
- $password = test_input($_POST["pass"]);
- }
- }
- function test_input($data)
- {
- $data = trim($data);
- $data = stripslashes($data);
- $data = htmlspecialchars($data);
- return $data;
- }
- ?>
- <h2>Login Form</h2>
- <?php
- $start = intval(isset($_POST['start'])?$_POST['start']:0);
- if(isset($_POST['previous'])){
- $start = $start -1;
- //if($start < 1) $start = 1;
- $start= max($start, 1);
- }
- else if(isset($_POST['next'])){
- $start = $start + 1;
- }
- else {
- $start = 1;
- }
- ?>
- <script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
- <script>
- function deleteBook(b) {
- $(document).ready(function() {
- var book = $(b).parent('td').prev('td').html();
- if(confirm("Are you sure you want to delete book - "+book+"?") == false){
- return;
- }
- var ids = $(b).attr('id').substr(6).split('-');
- var book_id_to_delete = ids[0];
- var user_id = ids[1];
- //alert("book_id is " + book_id_to_delete + ", user_id is " + user_id);
- $.ajax({
- type: "POST",
- url: "" + "deletebook.php",
- data: {
- 'book_id': book_id_to_delete,
- 'user_id': user_id,
- submit: 'submit',
- },
- success: function(res) {
- if (res == "deleted") {
- $(b).closest('tr').remove();
- } else {
- alert(res);
- }
- }
- });
- });
- }
- </script>
- <script>
- function sortTable(n) {
- var table, rows, switching, i, x, y, shouldSwitch, dir, switchcount = 0;
- table = document.getElementById("myTable");
- switching = true;
- dir = "asc";
- while (switching) {
- switching = false;
- rows = table.getElementsByTagName("TR");
- for (i = 1; i < (rows.length - 1); i++) {
- shouldSwitch = false;
- x = rows[i].getElementsByTagName("TD")[n];
- y = rows[i + 1].getElementsByTagName("TD")[n];
- if (dir == "asc") {
- if (x.innerHTML.toLowerCase() > y.innerHTML.toLowerCase()) {
- shouldSwitch= true;
- break;
- }
- } else if (dir == "desc") {
- if (x.innerHTML.toLowerCase() < y.innerHTML.toLowerCase()) {
- shouldSwitch = true;
- break;
- }
- }
- }
- if (shouldSwitch) {
- rows[i].parentNode.insertBefore(rows[i + 1], rows[i]);
- switching = true;
- switchcount ++;
- } else {
- if (switchcount == 0 && dir == "asc") {
- dir = "desc";
- switching = true;
- }
- }
- }
- }
- </script>
- <form method="post" action="">
- Name: <input type="text" name="user" value="<?php echo $user;?>">
- <span class="error">* <?php echo $nameErr;?></span>
- <br><br>
- password: <input type="password" name="pass" value="<?php echo $password;?>" >
- <span class="error">* <?php echo $passwordErr;?></span>
- <br><br>
- <input type="submit" name="submit" value="Login">
- <br><br>
- <input type="hidden" value="<?php echo $start;?>" name="start"/>
- <button type="button" name="button" onclick="window.location.href='/ooRigester.php'">SignUp</button>
- <br><br>
- <input type='submit' name='previous' value='previous' method="post" <?php echo ($start <= 1 ? "disabled" : ""); ?>>
- <input type='submit' name='next' value='next' method="post"><br>
- </form>
- <br>
- <?php
- include_once('User.php');
- if(isset($_POST['submit']) OR isset($_POST['next']) OR isset($_POST['previous'])){
- $username = $_POST["user"];
- $password = $_POST["pass"];
- $object = new User();
- $object->username= $username;
- $object->Password=$password;
- if( $object->isAuthenticated() ){
- echo "User Verified . <br><br>";
- $start = 0;
- if(isset($_POST['next']))
- {
- $start = $_POST['start'];
- }
- else if(isset($_POST['previous']))
- {
- $start = $_POST['start']-2;
- }
- $object->getBooks($start);
- }
- //For test git
- else{
- echo "Wrong User Name Or Password . Please try again <br>";
- }
- }
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement