Program Php
Program Php
<?php
include 'includes/functions.php';
session_destroy();
redirect('index.php');
?>
#8create_alert.php file:
<?php
include 'includes/db_connect.php';
include 'includes/functions.php';
if (!isLoggedIn()) {
redirect('login.php');
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$user_id = $_SESSION['user_id'];
$message = sanitize($_POST['message']);
$location = sanitize($_POST['location']);
try {
$stmt->execute([$user_id, $message, $location]);
$_SESSION['success'] = "Alert sent successfully.";
// In a real application, you would send notifications to emergency contacts
here
} catch(PDOException $e) {
$error = "Failed to send alert. Please try again.";
}
redirect('dashboard.php');
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Create Alert - Women's Safety Website</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<header>
<div class="container">
<div id="branding">
<h1><span class="highlight">Women's</span> Safety</h1>
</div>
<nav>
<ul>
<li><a href="index.php">Home</a></li>
<li><a href="dashboard.php">Dashboard</a></li>
<li><a href="logout.php">Logout</a></li>
</ul>
</nav>
</div>
</header>
<div class="container">
<h1>Create Emergency Alert</h1>
<form action="" method="post">
<div>
<label for="message">Alert Message:</label>
<input type="text" id="message" name="message" required>
</div>
<div>
<label for="location">Your Location:</label>
<input type="text" id="location" name="location" required>
</div>
<button type="submit" class="btn">Send Alert</button>
</form>
</div>
</body>
</html>
#7dasboard page
<?php
include 'includes/db_connect.php';
include 'includes/functions.php';
if (!isLoggedIn()) {
redirect('login.php');
}
<div class="container">
<h1>Welcome, <?php echo htmlspecialchars($user['name']); ?>!</h1>
<h2>Safety Tips</h2>
<ul>
<li>Always be aware of your surroundings</li>
<li>Trust your instincts</li>
<li>Keep your phone charged and with you at all times</li>
<li>Share your location with trusted friends or family</li>
<li>Learn basic self-defense techniques</li>
</ul>
<h2>Emergency Alert</h2>
<p>If you feel unsafe, click the button below to send an alert to your
emergency contacts.</p>
<a href="create_alert.php" class="btn">Send Emergency Alert</a>
</div>
</body>
</html>
#6 login page
<?php
include 'includes/db_connect.php';
include 'includes/functions.php';
if (isLoggedIn()) {
redirect('dashboard.php');
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$email = sanitize($_POST['email']);
$password = $_POST['password'];
<div class="container">
<h1>Login</h1>
<?php if (isset($error)): ?>
<div class="alert alert-danger"><?php echo $error; ?></div>
<?php endif; ?>
<?php if (isset($_SESSION['success'])): ?>
<div class="alert alert-success"><?php echo $_SESSION['success'];
unset($_SESSION['success']); ?></div>
<?php endif; ?>
<form action="" method="post">
<div>
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
</div>
<div>
<label for="password">Password:</label>
<input type="password" id="password" name="password" required>
</div>
<button type="submit" class="btn">Login</button>
</form>
</div>
</body>
</html>
#5 registartion page
<?php
include 'includes/db_connect.php';
include 'includes/functions.php';
if (isLoggedIn()) {
redirect('dashboard.php');
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$name = sanitize($_POST['name']);
$email = sanitize($_POST['email']);
$password = password_hash($_POST['password'], PASSWORD_DEFAULT);
try {
$stmt->execute([$name, $email, $password]);
$_SESSION['success'] = "Registration successful. Please log in.";
redirect('login.php');
} catch(PDOException $e) {
$error = "Registration failed. Please try again.";
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Register - Women's Safety Website</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<header>
<div class="container">
<div id="branding">
<h1><span class="highlight">Women's</span> Safety</h1>
</div>
<nav>
<ul>
<li><a href="index.php">Home</a></li>
<li><a href="login.php">Login</a></li>
<li class="current"><a href="register.php">Register</a></li>
</ul>
</nav>
</div>
</header>
<div class="container">
<h1>Register</h1>
<?php if (isset($error)): ?>
<div class="alert alert-danger"><?php echo $error; ?></div>
<?php endif; ?>
<form action="" method="post">
<div>
<label for="name">Name:</label>
<input type="text" id="name" name="name" required>
</div>
<div>
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
</div>
<div>
<label for="password">Password:</label>
<input type="password" id="password" name="password" required>
</div>
<button type="submit" class="btn">Register</button>
</form>
</div>
</body>
</html>
#4 home page
body {
font-family: Arial, sans-serif;
line-height: 1.6;
margin: 0;
padding: 0;
background-color: #f4f4f4;
}
.container {
width: 80%;
margin: auto;
overflow: hidden;
padding: 20px;
}
header {
background: #50b3a2;
color: white;
padding-top: 30px;
min-height: 70px;
border-bottom: #e8491d 3px solid;
}
header a {
color: #ffffff;
text-decoration: none;
text-transform: uppercase;
font-size: 16px;
}
header ul {
padding: 0;
margin: 0;
list-style: none;
overflow: hidden;
}
header li {
float: left;
display: inline;
padding: 0 20px 0 20px;
}
header #branding {
float: left;
}
header #branding h1 {
margin: 0;
}
header nav {
float: right;
margin-top: 10px;
}
header a:hover {
color: #ffffff;
font-weight: bold;
}
.btn {
display: inline-block;
padding: 10px 20px;
background: #50b3a2;
color: #ffffff;
text-decoration: none;
border: none;
border-radius: 5px;
cursor: pointer;
}
.btn:hover {
background: #3a8279;
}
form {
background: #ffffff;
padding: 20px;
border-radius: 5px;
}
.alert {
padding: 15px;
margin-bottom: 20px;
border: 1px solid transparent;
border-radius: 4px;
}
.alert-success {
color: #3c763d;
background-color: #dff0d8;
border-color: #d6e9c6;
}
.alert-danger {
color: #a94442;
background-color: #f2dede;
border-color: #ebccd1;
}
#2 common function
<?php
session_start();
function isLoggedIn() {
return isset($_SESSION['user_id']);
}
function redirect($url) {
header("Location: $url");
exit();
}
function sanitize($input) {
return htmlspecialchars(strip_tags($input));
}
?>
#1 .database connection
<?php
$host = 'localhost';
$dbname = 'women_safety';
$username = 'your_username';
$password = 'your_password';
try {
$pdo = new PDO("mysql:host=$host;dbname=$dbname", $username,
$password);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
die("Could not connect to the database $dbname :" . $e->getMessage());
}
?>