A simple web application built with PHP, MySQL, HTML, and CSS that allows users to register, log in, upload images with captions, and view their profile with a gallery of uploaded images.
Features
- User Registration and Login: Users can create an account and log in securely using email and password.
- Image Upload: Authenticated users can upload images with captions.
- Profile Page: Displays user information and a gallery of their uploaded images.
- Responsive Design: Styled with CSS for a modern, mobile-friendly interface.
- Secure Authentication: Passwords are hashed using PHP’s
password_hashfunction. - Session Management: Uses PHP sessions to maintain user authentication state.
- Frontend: HTML, CSS
- Backend: PHP
- Database: MySQL
- Server: Local server (e.g., XAMPP, WAMP, or LAMP)
- Styling: Custom CSS with responsive design
- PHP 7.4 or higher
- MySQL or MariaDB
- A web server (e.g., Apache) with PHP support
- A MySQL database
- A local or remote server environment (e.g., XAMPP, WAMP, or a hosting provider)
-
Clone the Repository:
git clone https://github.com/your-username/your-repo-name.git
Replace
your-usernameandyour-repo-namewith your GitHub username and repository name. -
Set Up the Web Server:
- Place the project folder in your web server’s root directory (e.g.,
htdocsfor XAMPP). - Ensure your web server (e.g., Apache) and MySQL are running.
- Place the project folder in your web server’s root directory (e.g.,
-
Create the Database:
-
Create a MySQL database (e.g.,
image_upload_db). -
Run the following SQL to create the necessary tables:
CREATE TABLE users ( id INT AUTO_INCREMENT PRIMARY KEY, email VARCHAR(255) NOT NULL UNIQUE, password VARCHAR(255) NOT NULL, profile_name VARCHAR(100) NOT NULL ); CREATE TABLE images ( id INT AUTO_INCREMENT PRIMARY KEY, profile_name VARCHAR(100) NOT NULL, image_path VARCHAR(255) NOT NULL, caption TEXT, upload_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP );
-
-
Configure Database Connection:
-
Open
register.php,upload.php,profile.php, andlogin.php. -
Update the following variables with your database credentials:
$servername = "localhost"; $username = "your_database_username"; $password = "your_database_password"; $dbname = "your_database_name";
-
Replace
your_database_username,your_database_password, andyour_database_namewith your actual MySQL credentials.
-
-
Set Up Upload Directory:
- Create a folder named
Uploadsin the project root directory. - Ensure the
Uploadsfolder has write permissions (e.g.,chmod 777 Uploadson Linux). - Verify that the folder path in
upload.php($target_dir = "Uploads/";) matches your setup.
- Create a folder named
-
Access the Application:
- Open your browser and navigate to
http://localhost/your-project-folder/index.html. - Register a new account or log in to start using the application.
- Open your browser and navigate to
- Home Page (
index.html):- Provides links to log in or create a new account.
- Sign Up (
signup.html):- Enter your email, password, and profile name to register.
- Login (
login.html):- Log in with your email and password to access your profile.
- Profile (
profile.php):- View your profile information and uploaded images.
- Use the
+button to navigate to the upload page.
- Upload (
upload.html):- Upload an image with an optional caption.
- Images are saved in the
Uploadsfolder and displayed in the profile gallery.
To ensure the project works smoothly when uploaded to GitHub, consider the following:
-
Database Credentials:
-
The provided PHP files (
register.php,upload.php,profile.php,login.php) contain placeholder database credentials (username,password,dbname). Update these with actual values before deployment. -
Do not commit sensitive credentials to GitHub. Use a
.gitignorefile to exclude a configuration file (e.g.,config.php) containing sensitive data:config.php Uploads/*
-
Create a
config.phpfile to store database credentials and include it in the PHP files:<?php $servername = "localhost"; $username = "your_database_username"; $password = "your_database_password"; $dbname = "your_database_name"; ?>
Then, update the PHP files to include
config.php:include 'config.php';
-
-
Uploads Folder:
- The
Uploadsfolder will store user-uploaded images. Since GitHub is not a hosting platform, you cannot directly run PHP or store uploaded files on GitHub. Host the project on a server (e.g., Heroku, a VPS, or a shared hosting provider) that supports PHP and MySQL. - Ensure the
Uploadsfolder is included in the repository if you want to track its structure, but exclude actual uploaded files using.gitignore.
- The
-
File Permissions:
- Ensure the
Uploadsfolder has the correct permissions (e.g.,777for testing,755for production) on your hosting server. - Verify that your hosting environment allows file uploads and that the PHP
upload_max_filesizeandpost_max_sizesettings are sufficient.
- Ensure the
-
Relative Paths:
- The project uses relative paths (e.g.,
Uploads/,styles.css). Ensure your hosting environment maintains the same directory structure. - If deploying to a subdirectory, adjust paths in
upload.phpandprofile.phpas needed.
- The project uses relative paths (e.g.,
-
Dependencies:
- The project has no external dependencies beyond PHP and MySQL, making it lightweight and easy to deploy.
- Ensure your hosting provider supports PHP 7.4+ and MySQL.
-
Security Considerations:
- Validate and sanitize user inputs to prevent SQL injection and XSS attacks (current code uses prepared statements, which is good practice).
- Consider adding file type validation in
upload.phpto restrict uploads to image files (e.g., PNG, JPG). - Use HTTPS on your production server to secure user data.
- Database Connection Errors: Ensure your database credentials are correct and the MySQL server is running.
- File Upload Issues: Verify that the
Uploadsfolder exists and has write permissions. Check PHP’sfile_uploadssetting inphp.ini. - Session Issues: Ensure PHP sessions are enabled on your server.
- GitHub Limitations: GitHub is a version control platform, not a hosting service. You cannot run PHP or MySQL directly on GitHub. Use a hosting provider for deployment.
- Fork the repository.
- Create a new branch (
git checkout -b feature-branch). - Make your changes and commit (
git commit -m "Add feature"). - Push to the branch (
git push origin feature-branch). - Create a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.
#php #mysql #login #signup #authentication #webdevelopment #phpdeveloper #authsystem #xampp #backend #fullstack #webapp #html #css #javascript