Wednesday, December 18, 2019

Php login logout simple example for newbie




Source code:
index.php

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Himel Sarkar</title>
<link rel="stylesheet" href="">
</head>
<body>
<form action="welcome.php" method="get" accept-charset="utf-8">

<input placeholder="User Name" type="text" name="username">

<input placeholder="Password" type="password" name="password">
<input type="submit" name="" value="login">
</form>
</body>
</html>

---------------------------------------------------------------------------------------------------------------------


welcome.php

<?php 
$dbu="testmail@gmail.com";
$dbp="12345";
echo "Database User name: ".$dbu. "<br>And password: ".$dbp."<br>";
$u=$_REQUEST['username'];
$p=$_REQUEST['password'];



if ($dbu==$u) {
echo '<font color="green"><br><h1>You are logged in </h1><br></font>';
} else {
echo '<font color="red"><br><h1>Not logged in </h1><br></font>';
}

echo "User info:".$u.":".$p;
 ?>








Tuesday, December 17, 2019

Paying with images in php coding






Source code:

upload.php

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Himel Sarlar</title>
<link rel="stylesheet" href="">
</head>
<body>

<form enctype="multipart/form-data" action="welcome2.php" method="POST" accept-charset="utf-8">
<input type="file" name="profilepicture">
<input type="submit" value="UPLOAD">
</form>

</body>
</html>


---------------------------------------------------------------------------------------------------------------------

welcome2.php




<pre>
<?php



$p=$_FILES["profilepicture"];
echo var_dump($p)."<br>";
//echo var_dump($p);
$p["tmp_name"];
$f=$p["name"];
echo $p["tmp_name"];

  $s=floor(($p["size"]/1000));

if ($s>1000) {
echo "<br>".($s/1000)." MB";
} else {
echo  "<br>".$s." KB <br>";

}
echo "<br>tmp_name:".$p["tmp_name"];
move_uploaded_file($p["tmp_name"],"img/".$p["name"]);

echo "<img src='img/$f' >";
?>

</pre>