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

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

site


kizinho

I am a software developer, like meeting people and love blogging, that's why I developed naijacrawl because that's what I love doing.

Continue Reading
Click To Comment

BE First To Comment


    Leave a Reply

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

    Latest



    Face of Naijacrawl


    ChukwubuikemSunday ChukwubuikemSunday

    Sunday Chukwubuikem


    Higher - 09061773292

    Trending