Pilih Laman

sumber: https://www.niagahoster.co.id/blog/cara-membuat-website-php/

To create a website, you need to master basic HTML and CSS to build a good structure and an attractive appearance. Well, how to create a website with PHP from scratch can be done with the following steps:

  1. Prepare the software used
  2. Create an index.php file
  3. Create a style.css file
  4. Create a home.php file
  5. Create a file about.php
  6. Create a contact.php file
  7. Try the website in the browser

 

Step 1: Preparation

Here are the various tools you need to prepare before creating a PHP website:

PHP Editor – Used to create website files and write code. This time we are using Sublime Text.

Web Browser – Useful for checking the appearance of the website. We are using Google Chrome in this tutorial.

Web Server – As a place to store website folders. Here we use XAMPP and then create a folder called websitephp in c:\xampp\htdocs.

Step 2: Creating the index.php File

Open Sublime Text, then click File > New File. Then, enter the source code in the following example or your own source code as desired:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<!DOCTYPE html>
<html lang="en">
<head>
    <title>Membuat Website dengan PHP | Niagahoster</title>
    <meta charset="UTF-8">
    <meta name="description" contents="Niagahoster">
    <link rel="stylesheet" href="style.css" type="text/css">
</head>
<body>
    <header>
        <h1 class="title">Niagahoster</h1>
        <h3 class="desc">Membuat Website dengan PHP dari Awal</h3>
        <nav id="navigation">
            <ul>
                <li><a href="index.php?page=home">Home</a></li>
                <li><a href="index.php?page=about">About</a></li>
                <li><a href="index.php?page=contact">Contact</a></li>
            </ul>
        </nav>
    </header>
    <div id="contents">
        <?php
        if(isset($_GET['page'])){
            $page = $_GET['page'];
            switch ($page) {
                case 'home':
                include "home.php";
                break;
                case 'about':
                include "about.php";
                break;
                case 'contact':
                include "contact.php";
                break;         
            }
        }
else{
            include "home.php";
        }
        ?>
    </div>
    <footer>
        &copy Copyright Niagahoster 2021 | Web Hosting Terbaik Indonesia
    </footer>
</body>
</html>

If so, save the file with the name index.php in the websitephp folder.

The explanation of the code above is as follows:
<a href=” … ”</a> is used to enter the navigation menu.
$_GET[‘…’] is used to call the GET method.
PHP, the GET method is used to retrieve data from a variable to another page. For that, we need a new variable named page. The GET method will later call the data entry of the page variable. Then, the data entry will be displayed according to the intended menu page.
switch (…) {case ‘…’} is used to switch pages.
include “home.php”; used to set the home.php file as the default page.
Step 3: Creating the style.css File File
How to make a PHP website is not complete without the steps of adding a CSS file. The goal is to make the website look more attractive. For that, create a new file, then write the following source code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
header h1.title,
header h3.desc{
text-align: center;
}
body {
width: 70%;
margin: auto;
}
a:link {
color: gray;
}
a:visited {
color: green;
}
a:hover {
color: rebeccapurple;
}
a:active {
color: teal;
}
#navigation { 
}
p {
font-size: 110%;
color: black;
}
#contents {
float: center;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: black;
font-family: sans-serif;
}
li {
float: left;
}
li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover {
background-color: #fff;
}
footer {
text-align: center;
}

Save with the name style.css.

Step 4: Creating Home.php File File
The next way to create a website using PHP is to create a Home page. This is the first page that appears when opening the website. To do this, create a new file, then type:
1
2
3
4
<div class="page">
    <h2>Website Hebat Berawal dari Unlimited Hosting</h2>
    <p>Kami berikan penawaran terbaik unlimited web hosting. Fitur terlengkap, harga terjangkau, dan dukungan teknis 24/7 telah tersedia untuk Anda.</p>
</div>

Next, save it with the name home.php.

Step 5: Create File about.php
You also need to create an About page. The method is still the same, click File > New File then write the source code below:
1
2
3
4
<div class="page">
    <h2>Tentang Niagahoster</h2>
    <p>Telah dipercaya lebih dari 500.000 klien yang terdaftar dari seluruh Indonesia, Niagahoster selalu berkomitmen menyajikan teknologi terbaik untuk kesuksesan online Anda. Bergabunglah dan temukan kemudahan menciptakan website impian Anda bersama Niagahoster!</p>
</div>

Save the file with the name about.php.

Step 6: Creating the Contact.php File
Finally, create a Contact page by selecting the File menu and then clicking New File. Then copy the following source code:
1
2
3
4
5
6
7
8
9
10
11
12
<div class="page">
    <h2>Hubungi Kami</h2>
    <p>Telp: 0274-2885822
        <br>WA: 0895395186038
        <br>Senin - Minggu
    24 Jam Non Stop</p>
    <p>Jl. Palagan Tentara Pelajar
        No 81 Jongkang, Sariharjo, Ngaglik, Sleman
        Daerah Istimewa Yogyakarta
    55581</p>
</div>

If so, save the file with the name contact.php.

Step 7: Trying Website in Browser
Well, all the coding process has been completed and the website is ready. But, can the website be accessed smoothly? Let’s do a check. To do this, open the XAMPP Control Panel, then click Start on the Apache and MySQL modules.
cara membuat website php langkah 7
Then open a browser, then type localhost/websitephp. If successful, this is how it looks:
cara membuat website menggunakan php langkah 7.1
By default, the website will display the Home page like the script you have written in the index.php file.
Now try to open the About page by clicking the About navigation menu. This is roughly the result:
cara membuat website php langkah 7.2
As for the Contact page, the resulting display looks like this:
cara membuat website dengan php dari awal langkah 7.3
done