Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
8 views

php

The document is an HTML template for a PHP web application that includes multiple forms for user input, such as login and age verification. It contains commented-out PHP code snippets demonstrating various functionalities like handling GET and POST requests, form validation, and database connectivity. Additionally, it showcases how to use Bootstrap for styling and includes examples of using cookies and password hashing.

Uploaded by

padagik228
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

php

The document is an HTML template for a PHP web application that includes multiple forms for user input, such as login and age verification. It contains commented-out PHP code snippets demonstrating various functionalities like handling GET and POST requests, form validation, and database connectivity. Additionally, it showcases how to use Bootstrap for styling and includes examples of using cookies and password hashing.

Uploaded by

padagik228
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

P

H 1|Page
<!doctype html>

<html lang="en">

<head>

<!-- Required meta tags -->

<meta charset="utf-8">

<meta name="viewport" content="width=device-width, initial-scale=1">

<!-- Bootstrap CSS -->

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC
" crossorigin="anonymous">

<title>Master</title>

</head>

<body>

<h1 class="text-center">PhP Code</h1>

<!-- #Form - 1 -->

<!-- <form action="index.php" method="post"> //change method from post to get as per the use.

<label>User Id </label>

<input type="text" name="username"><br>

<label>Passwd </label>

<input type="password" name="password"><br>

<input type="submit" value="Login">

</form> -->

<!-- #Form - 2 -->

<!-- <form action="index.php" method="post">

<label>Enter a number : </label>

<input type="text" name="x">

<input type="submit" value="Okay">

</form> -->

2|Page
<!-- #Form - 3 -->

<!-- <form action="index.php" method="post">

<label>Enter your age</label>

<input type="text" name="age">

<input type="submit" value="Check" >

</form> -->

<!-- #Form - 4

<form action="index.php" method="post"> //change method from post to get as per the use.

<label>User Id </label><br>

<input type="text" name="username"><br>

<label>Passwd </label><br>

<input type="password" name="password"><br>

<label>E-mail</label><br>

<input type="text" name="email"><br>

<label>Age</label><br>

<input type="text" name="age"><br>

<input type="submit" name="login" value="Login">

</form> -->

<!-- #FORM - 5 Remove '//' from action in form tag-->

<!--

<form action="<?php // htmlspecialchars($_SERVER["PHP_SELF"]) ?>" method="post">

<label>User Name </label><br>

<input type="text" name="username"><br>

<label>Password </label><br>

<input type="password" name="password"><br>

<input type="submit" name="login" value="Login">

</form> -->

3|Page
<?php

//Form - 1 GET Request

//$_GET request

// echo $_GET["username"] . "<br>";

// echo $_GET["password"] . "<br>";

//#Form - 1 POST Request

//$_POST request

// echo "Your Id : {$_POST["username"]} <br>";

// echo "Password : {$_POST["password"]} <br>";

//String :-)

// echo "php code.<br>";

//Variables :-)

// $a = "Arthur";

// $b = null;

//If you want to add $ sign than use '\'. like \${Variable_name}

// echo "Hi my name is {$a} <br>";

// $num1 = 4;

// $num2 = 3;

// $num3 = $num1 + $num2;

// echo "Total : $num3";

//#Form - 2

/*

$x = $_POST["x"];

4|Page
$total = null;

$total = abs($x);

$total = round($x);

$total = floor($x); //round the no. i.e : 12.96 : 12

$total = ceil($x); //round the no. i.e : 12.01 : 13

$total = pi(); //print the value of pi

$total = rand(1, 100); //genrate random no.

echo $total;

*/

//#Form - 3

/*

$age = $_POST["age"];

if ($age >= 18){

echo "You are eligible for vote.";

else{

echo "You are not eligible for vote.";

*/

//Loop

// for($i=1;$i<=10;$i++){

// echo "Hi <br>";

// }

//Array

//$arr = array('Rolex','Timex','Casio');

//echo count($arr);

//array_push($arr,'Omega','Fossil'); //Add in last.

5|Page
//array_pop($arr); //Delete from last.

//array_shift($arr); //Delete from first.

//$arr = array_reverse($arr);

// foreach($arr as $ar){

// echo $ar."<br>";

// }

// echo "<br>".$arr[0];

#Form - 4

/*

if (isset($_POST["login"])) {

$username = filter_input(INPUT_POST, "username", FILTER_SANITIZE_SPECIAL_CHARS);

$password = $_POST["password"];

$email = filter_input(INPUT_POST, "email", FILTER_SANITIZE_EMAIL);

$age = filter_input(INPUT_POST, "age", FILTER_SANITIZE_NUMBER_INT);

if (empty($username) && empty($password)) {

echo "Both User Id & Password is missing.";

elseif (empty($username)) {

echo "User Id is missing.";

elseif (empty($password)) {

echo "Password is missing.";

else {

echo "Hello {$username}";

echo "<br>your E-mail is : {$email}<br>";

6|Page
echo "your age is : $age";

*/

//Cookie Press F12 to see it.

// setcookie("Amit", "Coca-Cola", time() + (86400 * 2), "/");

//Hasing

/*

$passwd = "Astrum420";

$hash = password_hash($passwd, PASSWORD_DEFAULT);

if(password_verify("Astrum420", $hash)){

echo "Your are in";

else{

echo "Incorrect Password";

*/

//Database Connectivity ;)

/*

$db_server = "localhost";

$db_user = "root";

$db_pass = "";

$db_name = "php"; //database name

$conn = "";

try{

7|Page
$conn = mysqli_connect($db_server, $db_user, $db_pass, $db_name);

catch(mysqli_sql_exception){

echo "Could not Connected.";

*/

//Check DB is Connected

/*

if($conn){

echo " Connected";

else{

echo "Try Again";

*/

//insert into database

/*

$username = "Arthur";

$password = "Delta420";

$hash = password_hash($password, PASSWORD_DEFAULT);

$sql = "insert into userdata (Name, password)

values('$username','$hash')";

try{

mysqli_query($conn, $sql);

echo "Thanks for Registration.";

catch(mysqli_sql_exception){

8|Page
echo "Fail to Register User.";

*/

//Select * from database

/*

$sql = "select * from userdata";

$table = mysqli_query($conn, $sql);

if(mysqli_num_rows($table) > 0)

while($row = mysqli_fetch_assoc($table))

echo "User ID : " . $row["User ID"] . "<br>";

echo "Name : " . $row["Name"] . "<br>";

echo "Password : " . $row["Password"] . "<br>";

echo "Date : " . $row["Date"] . "<br>";

};

else

echo "No Record Found.";

*/

//FORM - 5 //login

/*

if($_SERVER["REQUEST_METHOD"] == "POST"){

$username = filter_input(INPUT_POST, "username", FILTER_SANITIZE_SPECIAL_CHARS);

9|Page
$password = filter_input(INPUT_POST, "password", FILTER_SANITIZE_SPECIAL_CHARS);

if (empty($username) && empty($password)) {

echo "Both User Name & Password is empty.";

elseif (empty($username)) {

echo "Please enter a User Name.";

elseif (empty($password)) {

echo "please enter a Password.";

else{

$hash = password_hash($password, PASSWORD_DEFAULT);

$sql = "INSERT INTO rags (User_Name, Password)

VALUES('$username', '$hash')";

try{

mysqli_query($conn, $sql);

echo "You're login.";

catch(mysqli_sql_exception){

echo "That User Name is taken";

*/

//Close Database

/*

if(mysqli_close($conn))

10 | P a g e
echo "Database Close.";

*/

?>

<!-- Bootstrap Bundle with Popper -->

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"
integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
crossorigin="anonymous"></script>

</body>

</html>

<?php

//include("#write file name like : index.html,index.php");

?>

11 | P a g e

You might also like