Connect with us

How to create clean url in PHP (part 1)

kizinho

Published

on

Follow
NEWS: How to create clean url in PHP (part 1) [New  Developer] » Naijacrawl
Photo: Naijacrawl
site

Hi Folks, today share with you on how to write a clean URL in PHP, we all know while clean URL is very important for SEO for easy ranking of an article.

Will share my experience on how I was able to write a clean URL in PHP with you guys.

Requirements 

Will make use of PHP and my SQL no framework, we are using plain PHP, you can choose to do the same thing with PDO, MYSQLI depends on your codebase.

  1. PHP
  2. MYSQL DATABASE
  3. CONNECTION TO DATABASE
  4. HTACCES
  5. POST TABLE
  6. DISPLAY POST PAGE
  7. DISPLAY PAGE FOR THE POST ARTICLE


Let's begin with those requirements above.


Database Struture

  1. title ->(text)
  2. slug ->(string)->unique
  3. content ->(longtext)
  4. created_at ->(timestamp)

Database Connection

filename -> dbconection.php

$dbhost_name = "localhost";
$database = "naijacrawl"; // Change your database nae
$username = "root"// Your database user id 
$password = "";     // Your password//////// Do not Edit below /////////try {
$dbo = new PDO('mysql:host=localhost;dbname='.$database, $username, $password, array(PDO::ATTR_PERSISTENT => true));
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "
"
; die(); }


Creating Post so that it can be inserted to the database

filename-> create_post.php

<html lang="en"><head><title> - Create Post title>
head><body><form method="post" action=""><input name="title"><input name="content"><button name="upload"> Upload button>
form>
body>html>


The upload page is now completed, it remains to write the PHP code that will process it.

Catch up to Part 11 on writing clean URL in PHP

Click Here To Comment


site


kizinho

Adike Kizito is a top-rated software developer, blogger, sports, and entertainment lover. He is the CEO of these popular websites Naijacrawl.com and Mp3ager.com. He operates his software developing task through Kizzsoft.com,... Read More

Continue Reading
1 Comment

1 Comment

  1.   David

    Please I need the part of this... Thanks sir


Leave a Reply

Your email address will not be published. Required fields are marked *

Latest


Download Naijacrawl App today

Fastest way to read on the go

Download the Naijacrawl App.