Skip to content

Instantly share code, notes, and snippets.

@maxixo
maxixo / dashboard.php
Created January 24, 2026 01:20
logout in php
<?php
session_start();
if(!isset($_SESSION['user_id'])) {
header("location: logn.html");
exit;
}
echo "Welcome to your dashboard";
@maxixo
maxixo / login.html
Created January 23, 2026 21:50
sign in with session
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Login system</title>
</head>
<body>
<form action="login.php" method="POST">
<input type="emaiil" name="email" placeholder="email" required>
@maxixo
maxixo / login.php
Created January 23, 2026 11:53
login registration with php
<?php
$conn = new mysqli("localhost", "root", "", "user_system");
$username = $_POST['username'];
$email = $_POST['email'];
$password = password_hash($_POST['password'], PASSWORD_DEFAULT);
@maxixo
maxixo / gist:a23c3b074585eb9706bd2594bec1d2c1
Created January 20, 2026 20:26
updating and deleting in sql
// Updating data
$newName = "Alice smith ";
$idToUpdate = 3;
$sql = "UPDATE users_ SET name = '$newName' WHERE id=$idToUpdate";
if ($conn->query($sql)) {
echo "Record Updated";
} else{
@maxixo
maxixo / gist:722565e3233b55f840ea70114d983ae2
Created January 20, 2026 20:13
creating and reading data in php
<?php
// Create
$conn= new mysqli('localhost', "root", "", "myapp");
$name = "Alice";
$email = "alice@example.com";
$age = 25;
@maxixo
maxixo / gist:2d77e3780af9e291e1c515a28a420efd
Created January 20, 2026 14:15
connecting mysql to php
<?php
$host = 'localhost';
$user = 'root';
$password = "";
$dbname = "myapp";
//create connection
$conn = new mysqli($host,$user,$password,$dbname);
@maxixo
maxixo / gist:36f304d46b1c177aca96708384dcb250
Created January 16, 2026 22:33
How to upload files in PHP
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>File Upload</title>
</head>
<body>
<?php
if(isset($_FILES['myFile'])) {
@maxixo
maxixo / gist:c8523fd806bcef2463d3a7e5257929cb
Created January 15, 2026 23:23
Reading and writing to files in php
<?php
// WRITE to file
$handle = fopen("example.txt", "w");
fwrite($handle, "Hello, this is a test \n");
fwrite($handle, "We are writing to a file in PHP");
fclose($handle);
// READ from file
@maxixo
maxixo / gist:023e6f453e7d48adeb5c52bc2b8c4c0f
Created January 13, 2026 23:02
Sanitizing inputs in php
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>User Input</title>
</head>
<body>
<?php
// Define the function first
@maxixo
maxixo / gist:34c4436d48b712cf96aa6d48c84102d4
Created January 13, 2026 02:52
Basic form validation in php
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Form Validation</title>
</head>
<body>
<?php
$name = $email = $age = "";