Simple Registration Form in PHP with Validation | Tutsmake.com

How to Create a Virtual Host in XAMPP For PHP in Windows

The Virtual Host in PHP provides a domain URL in the local system. It allows you to run your application on a domain virtually. You can configure Apache virtual host easily for your application. If you create the Apache Virtual Host in PHP application then it will be super easy for you. You can run any PHP framework application through that virtual host. Once, you created the virtual host, it won’t require running your application again and again. This is the most beneficial thing to have the virtual host. Only, you will need to start the Apache server and your application will up automatically by typing the host URL in the browser. In this post, I will show you to create the Apache virtual host through XAMPP in Windows. I won’t take much time on describing this kind of stuff. Hence, Let’s come to the practical things.

Читайте также:  Checking if directory exists java

Prerequisites

Before creating the virtual host, it is mandatory to have the below applications in your windows system.

If you install XAMPP then it will provide you the Apache server and PHP inbuilt. So, after that, you won’t require an additional PHP development environment.

If you don’t have the XAMPP then it is highly recommended to have it in your system.

Create a PHP Project Folder

At the initial step, you will need to have the PHP application folder. Hence, I am creating a new folder inside the xampp/htdocs folder. Here, my folder name is php-app. Inside the folder, I am creating a PHP file named index.php. Also, I have added a simple message inside this file.

index.php file for virtual host

Create Apache Virtual Host in Windows

You will need to open the XAMPP Control Panel. Please make sure, Apache server is stopped before configuring the Virtual host.

XAMPP Control Panel - Apache Virtual Host

In the XAMPP Control Panel, there is the Explorer option. When you will click on that, it will redirect you to the Xampp installed directory.

XAMPP Control Panel - File Explorer

Inside the xampp directory, you will have the apache folder as shown below.

XAMPP Apache Folder - Create Virtual Host

Now, inside the apache folder, you will see the folder named extra. So, go inside that directory.

XAMPP Apache Extra - Create Apache Virtual Host

Inside the extra folder, you have to go inside the conf folder. This is basically a configuration folder of apache.

Apache Conf - Create Virtual Host

Inside the configuration folder, you will see the httpd-vhosts file. This is mainly virtual hosts file. So, you will need to configure the new virtual host inside this file.

Apache httpd vhosts file

Open this file in Notepad or Notepad++ as an administrator mode. Now, scroll down, and look for the highlighted lines.

Apache Configuration - Virtual Hosts

Configure Apache Virtual Host

You need to make a copy of the existing VirtualHost configuration, it will look like it as shown below.

 ##ServerAdmin webmaster@dummy-host2.example.com ##DocumentRoot "C:/xampp/htdocs/dummy-host2.example.com" ##ServerName dummy-host2.example.com ##ErrorLog "logs/dummy-host2.example.com-error.log" ##CustomLog "logs/dummy-host2.example.com-access.log" common ##
  • Firstly, you have to uncomment the snippet by removing (#) from each line.
  • Now, just keep the DocumentRoot and ServerName.
  • In the DocumentRoot, you need to pass the path of your PHP application.
  • Now, the last line is the ServerName. So, this will contain the URL of your virtual host on which your PHP application run.
 DocumentRoot "C:/xampp/htdocs/php-app/" ServerName myphp-app.com 

I have set the virtual host URL to myphp-app.com . Now, save the file and close it.

In the next step, you need to register this virtual domain in the localhost.

Configure Apache Virtual Host IP Address

We have the virtual host URL. But, now, this will need an IP address of the localhost. Hence, in order to register the virtual host domain, you will need to go to this path –

Inside this path, you will see the file named hosts.

Now, you will need to open this hosts file in the editor. So, better, you open it in Notepad++ as an administrator mode. Take a look at the screenshot, here you have to copy the highlighted line and paste it below the end of the commented lines.

Now, uncomment the host IP address. It should look like this.

Here, you need to register your virtual domain. In my case my virtual domain is myphp-app.com. Hence, I am registering this with the same IP address as we have for the local host.

Save the file and close it. That’s it for the configuration.

Restart Apache Server

Once you created Apache virtual host, it’s time to restart the Apache server inside the XAMPP control panel.

Start Apache Server in XAMPP

Once the Apache server is started, you will be able to access the virtual host URL in the browser. Here, you can see our PHP file is running through the virtual host.

PHP File Running through Apache Virtual Host

Bottom LInes

We configured Apache virtual host in XAMPP for the Windows platform. We registered the virtual host domain with the IP address. This IP address allowed our domain to run locally in the browser. We accessed a basic PHP file in the virtual host. Similarly, you can run any PHP application whether it is any framework like Laravel, Yii, CodeIgniter, etc. I hope this will be helpful for you. Feel free to ask if you will have any doubt regarding this post.

Источник

Login and Registration Form in PHP + MySQL using XAMPP

Simple login and registration form in PHP + MySQL + Boostrap using xampp. In this tutorial; you will learn how to create a simple login and registration form in PHP and MySQL using xampp with source code.

You can also download the complete source code of simple login and registration form in PHP + MYsql + Bootstrap using xampp from github.

Login and Registration Form in PHP and MySQL using XAMPP

  • Step 1 – Open the XAMPP Control Panel & Create PHP Project
  • Step 2 – Create Database and Table
  • Step 3 – Create a Database Connection File
  • Step 4 – Create a registration form and Insert data into MySQL database
  • Step 5 – Create Login Form in PHP with MySQL
  • Step 6 – Create User Profile and Fetch Data From MySQL Database
  • Step 7 – Create Logout.php file

Step 1 – Open the XAMPP Control Panel & Create PHP Project

Visit your xampp installed directory. Then open xampp control panel and start it; then visit xampp/htdocs directory. And inside this directory create php project directory.

Step 2 – Create Database and Table

Create a database name my_db and execute the below-given query in your database. The below query will create a table named users in your database with the following fields like uid, name, email, mobile:

CREATE DATABASE my_db; CREATE TABLE `users` ( `uid` bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY, `name` varchar(255) DEFAULT NULL, `email` varchar(255) DEFAULT NULL, `mobile` varchar(255) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1;

Step 3 – Create a Database Connection File

Create a file name db.php and update the below code into your file.

The below code is used to create a MySQL database connection in PHP. When you insert form data into MySQL database, there you will include this file:

Step 4 – Create registration form and Insert data into MySQL database

Create registration form file; which name registration.php. And add the following code into it:

 if (isset($_POST['signup'])) < $name = mysqli_real_escape_string($conn, $_POST['name']); $email = mysqli_real_escape_string($conn, $_POST['email']); $mobile = mysqli_real_escape_string($conn, $_POST['mobile']); $password = mysqli_real_escape_string($conn, $_POST['password']); $cpassword = mysqli_real_escape_string($conn, $_POST['cpassword']); if (!preg_match("/^[a-zA-Z ]+$/",$name)) < $name_error = "Name must contain only alphabets and space"; >if(!filter_var($email,FILTER_VALIDATE_EMAIL)) < $email_error = "Please Enter Valid Email ID"; >if(strlen($password) < 6) < $password_error = "Password must be minimum of 6 characters"; >if(strlen($mobile) < 10) < $mobile_error = "Mobile number must be minimum of 10 characters"; >if($password != $cpassword) < $cpassword_error = "Password and Confirm Password doesn't match"; >if(mysqli_query($conn, "INSERT INTO users(name, email, mobile_number ,password) VALUES('" . $name . "', '" . $email . "', '" . $mobile . "', '" . md5($password) . "')")) < header("location: login.php"); exit(); >else < echo "Error: " : "" . mysqli_error($conn); >mysqli_close($conn); > ?>       

Please fill all fields in the form

Already have a account?Login

Step 5 – Create Login Form In PHP with MySQL

Create login form, where you accept user email id and password and authenticate users from database. So you can create a login.php file and add the below code into your file:

 if (isset($_POST['login'])) < $email = mysqli_real_escape_string($conn, $_POST['email']); $password = mysqli_real_escape_string($conn, $_POST['password']); if(!filter_var($email,FILTER_VALIDATE_EMAIL)) < $email_error = "Please Enter Valid Email ID"; >if(strlen($password) < 6) < $password_error = "Password must be minimum of 6 characters"; >$result = mysqli_query($conn, "SELECT * FROM users WHERE email = '" . $email. "' and pass = '" . md5($password). "'"); if(!empty($result)) < if ($row = mysqli_fetch_array($result)) < $_SESSION['user_id'] = $row['uid']; $_SESSION['user_name'] = $row['name']; $_SESSION['user_email'] = $row['email']; $_SESSION['user_mobile'] = $row['mobile']; header("Location: dashboard.php"); >>else < $error_message = "Incorrect Email or Password. "; >> ?>       

Please fill all fields in the form


You don't have account?

Step 6 – Create User Profile and Fetch data From Database

Create a new file name dashboard.php and add the below code into your file.

The below code used to show logged in user data.

 ?>      Logout 

Step 7 – Create Logout.php file

Create logout.php file and update the below code into your file.

The below code is used to destroy login your data and logout.

Conclusion

Simple login and registration form in php with mysql database using xampp; In this tutorial, you have learned how to create a simple login, registration and logout system in PHP MySQL with validation. Also, you have learned how to authenticate and logout logged in users in PHP.

Источник

Xampp htdocs register php

Learn Latest Tutorials

Splunk tutorial

SPSS tutorial

Swagger tutorial

T-SQL tutorial

Tumblr tutorial

React tutorial

Regex tutorial

Reinforcement learning tutorial

R Programming tutorial

RxJS tutorial

React Native tutorial

Python Design Patterns

Python Pillow tutorial

Python Turtle tutorial

Keras tutorial

Preparation

Aptitude

Logical Reasoning

Verbal Ability

Company Interview Questions

Artificial Intelligence

AWS Tutorial

Selenium tutorial

Cloud Computing

Hadoop tutorial

ReactJS Tutorial

Data Science Tutorial

Angular 7 Tutorial

Blockchain Tutorial

Git Tutorial

Machine Learning Tutorial

DevOps Tutorial

B.Tech / MCA

DBMS tutorial

Data Structures tutorial

DAA tutorial

Operating System

Computer Network tutorial

Compiler Design tutorial

Computer Organization and Architecture

Discrete Mathematics Tutorial

Ethical Hacking

Computer Graphics Tutorial

Software Engineering

html tutorial

Cyber Security tutorial

Automata Tutorial

C Language tutorial

C++ tutorial

Java tutorial

.Net Framework tutorial

Python tutorial

List of Programs

Control Systems tutorial

Data Mining Tutorial

Data Warehouse Tutorial

Javatpoint Services

JavaTpoint offers too many high quality services. Mail us on h[email protected], to get more information about given services.

Training For College Campus

JavaTpoint offers college campus training on Core Java, Advance Java, .Net, Android, Hadoop, PHP, Web Technology and Python. Please mail your requirement at [email protected].
Duration: 1 week to 2 week

Like/Subscribe us for latest updates or newsletter RSS Feed Subscribe to Get Email Alerts Facebook Page Twitter Page YouTube Blog Page

Источник

Оцените статью