0% found this document useful (0 votes)
13 views

Program Php

The document outlines a Women's Safety Website, including functionalities for user registration, login, and sending emergency alerts. It consists of multiple PHP files that handle user sessions, database connections, and form submissions, ensuring a secure environment for users. The website aims to provide safety resources and a supportive community for women.

Uploaded by

Janvi Chechani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Program Php

The document outlines a Women's Safety Website, including functionalities for user registration, login, and sending emergency alerts. It consists of multiple PHP files that handle user sessions, database connections, and form submissions, ensuring a secure environment for users. The website aims to provide safety resources and a supportive community for women.

Uploaded by

Janvi Chechani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

#9lagout page

<?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']);

$stmt = $pdo->prepare("INSERT INTO alerts (user_id, message, location)


VALUES (?, ?, ?)");

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');
}

$stmt = $pdo->prepare("SELECT * FROM users WHERE id = ?");


$stmt->execute([$_SESSION['user_id']]);
$user = $stmt->fetch();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dashboard - 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 class="current"><a
href="dashboard.php">Dashboard</a></li>
<li><a href="logout.php">Logout</a></li>
</ul>
</nav>
</div>
</header>

<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'];

$stmt = $pdo->prepare("SELECT * FROM users WHERE email = ?");


$stmt->execute([$email]);
$user = $stmt->fetch();

if ($user && password_verify($password, $user['password'])) {


$_SESSION['user_id'] = $user['id'];
redirect('dashboard.php');
} else {
$error = "Invalid email or password";
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login - 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 class="current"><a href="login.php">Login</a></li>
<li><a href="register.php">Register</a></li>
</ul>
</nav>
</div>
</header>

<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);

$stmt = $pdo->prepare("INSERT INTO users (name, email, password) VALUES


(?, ?, ?)");

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

<?php include 'includes/functions.php'; ?>


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>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 class="current"><a href="index.php">Home</a></li>
<?php if (isLoggedIn()): ?>
<li><a href="dashboard.php">Dashboard</a></li>
<li><a href="logout.php">Logout</a></li>
<?php else: ?>
<li><a href="login.php">Login</a></li>
<li><a href="register.php">Register</a></li>
<?php endif; ?>
</ul>
</nav>
</div>
</header>
<div class="container">
<h1>Welcome to Women's Safety Website</h1>
<p>Our mission is to provide a safe and supportive environment for
women. Join our community to access safety resources and emergency
alerts.</p>
<?php if (!isLoggedIn()): ?>
<a href="register.php" class="btn">Join Now</a>
<?php endif; ?>
</div>
</body>
</html>

#3 main css file

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 .highlight, header .current a {


color: #e8491d;
font-weight: bold;
}

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;
}

input[type="text"], input[type="email"], input[type="password"] {


width: 100%;
padding: 10px;
margin-bottom: 10px;
}

.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());
}
?>

You might also like