GithubHelp home page GithubHelp logo

lab4web's Introduction

Tugas Pemograman Web 2

Profil

# Biodata
Nama Bilal AlHafidz
NIM 312110397
Kelas TI.21.A.1
Mata Kuliah Pemrograman Web 2

Persiapan

  1. Persiapkan Text Editor misalnya VSCode.
  2. Buat folder baru dengan nama Lab4Web pada root Web Server (htdocs).
  3. Ikuti langkah-langkah praktikum yang akan dijelaskan berikutnya.

Langkah-langkah Praktikum

  • Melanjutkan pertemuan 3 atau praktikum sebelumnya, namun disini kita akan menambahkan/membuat Routing.
  • Pertama, rename index.php menjadi view.php di pertemuan sebelumnya.
  • Kemudian buat file baru dengan nama index.php, lalu masukan kode berikut.
<?php
$mod = @$_REQUEST['mod'];
switch ($mod) {
  case "view":
    require("view.php");
    break;
  case "tambah":
    require("tambah.php");
    break;
 default:
 require("error.php");
}
?>
  • Tambahkan simbol @ sebelum method $_REQUEST untuk menghilangkan Undefined array key error.

Aktifasi mod_rewrite (.htaccess)

Mod_rewrite digunakan untuk mengubah URL dari query string menjadi SEO Friendly.

  • Langkah awal yang harus disiapkan adalah aktivasi mod_rewrite pada Web Server Apache2 pada configurasi httpd.conf.

Aktifasi

  • Aktifkan LoadModule mod_rewrite dengan cara melakukan un-comment pada baris tersebut, kemudian restart Apache2.
  • Langkah berikutnya adalah membuat file baru dalam folder Lab4Web dengan nama .htaccess, kemudian masukan kode berikut.
<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /LabWeb/Lab4Web
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?mod=$1 [L]
</IfModule>

Sekarang cara mengaksesnya menjadi:

View

Tambahan (+)

  • Buat file baru dengan nama error.php, kemudian tambahkan kode berikut.
<!DOCTYPE html>
<html>
  <head>
    <title>CRUD Sederhana</title>
    <style>
      body {
        font-family: Arial, sans-serif;
        background-color: #f2f2f2;
        display: flex;
        align-items: center;
        justify-content: center;
        height: 100vh;
        flex-direction: column;
      }
      h1 {
        font-size: 36px;
        color: #333;
        margin-top: 50px;
      }
      p {
        font-size: 24px;
        color: #666;
      }
    </style>
  </head>
  <body>
    <h1>Error 404 - Page Not Found</h1>
    <p>Maaf, halaman yang Anda minta tidak dapat ditemukan.</p>
  </body>
</html>
  • File tersebut berfungsi untuk menampilkan halaman error ketika pengguna salah memasukan query string.

Error

Terima Kasih!

lab4web's People

Contributors

kyuurazz avatar

Watchers

 avatar

Forkers

farhanz17

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.