Article Manager with Direct Links Using htaccess

Written by @m_k_amin 28 December 2012

To manage your site better, you must specify a link for each page. But it is exhausting to create separate pages for all articles. This script is an article managing system you can add your articles and it automatically creates a direct link for accessing to it using htaccess file. So the visitors and search engines can access to these areticle by something linke this: http://www.yourdomain.com/the_article_name It is just one page script that do all of these things with database automatic configuration function. It also shows the list of the current articles; so you can make your site more professional. Download the script with its htaccess file from attachment below and Enjoy!

Code Snippet:

                                                
                                                <!-- this script is provided by www.phpfreecode.com coded by: Kerixa Inc. -->
<!-- This Script is from www.phpfreecpde.com, Coded by: Kerixa Inc-->

<?php
	$host="localhost"; // Host name
	$username="root"; // Mysql username
	$password=""; // Mysql password

function setup(){
echo('
<p style="color: #008000;	text-align: left;	font-size: 15pt;"">-Automatic setup is started...</p>
');
global $host,$username,$password,$link;
//$link=mysql_connect($host, $username, $password);
$sql= 'CREATE DATABASE article';
if (!mysql_query ($sql, $link)) die('
<p style="text-align: center;	font-size: 20pt;"><span style="color: #FF0000;">Failed to 
create database! </span><br><span style="font-size: 12pt;">&gt;&gt;Please check the parameters and database server&lt;&lt;</span></p>
');
$sql = "CREATE TABLE `article`.`article` (
`ID` INT NOT NULL ,
`title` TEXT NOT NULL,
`body` TEXT NOT NULL
) ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci;";

mysql_query($sql) or die('Setup Failed');
echo('
<p style="color: #008000;	text-align: left;	font-size: 15pt;"">-Automatic setup completed successfully. Your Database is ready!</p>
');
}

$link=mysql_connect($host, $username, $password);
if(!$link) die('
<p style="text-align: center;	font-size: 20pt;"><span style="color: #FF0000;">Failed to connect to the database! </span>
<br><span style="font-size: 12pt;">&gt;&gt;Please check the parameters and database server&lt;&lt;</span></p>
');
$db_name="article"; 
$result=mysql_select_db($db_name);
if(!$result)
	setup();

$sql="SELECT * FROM article";
$result=mysql_query($sql);
@$cn=mysql_num_rows($result);
$cn++;
if (isset($_POST['add'])){
	$id=$cn;
	$title=$_POST['title'];
	$body=$_POST['body'];
	$body=str_replace("\n",'<br>',$body);
	//var_dump( $body);	
	$body=str_replace("<",'\r\n<',$body);
	$sql="INSERT INTO article(ID,title,body)VALUES('$id', '$title', '$body')";
	$result=mysql_query($sql);
	if (!$result) die (mysql_error());
}
if (isset($_GET['title'])){
	$title=str_replace('_',' ',$_GET['title']);
	$sql="SELECT * FROM article WHERE title='$title'";
	$result=mysql_query($sql);
	$rows=mysql_fetch_array($result);
?>
<table style="border: 1px solid #000000;width: 799px" align="center">
	<tr>
		<td style="padding:5px; font-family: 'Times New Roman', Times, serif;font-size: 17pt; color: #2214B9;border-style: solid;border-width: 1px; width: 435px; background-color: #E8FCDD;">
<?php
echo '<p align="center" ><b>'.$rows['title'].'</b></p><p align="left">'.$rows['body'].'</p>'; 
?>
		</td>
	</tr>
</table>
<?php } ?>
<br>
<form method="post">
<table style="border: 1px solid #000000;width: 799px" align="center">
	<tr>
		<td style="padding:5px; font-family: 'Times New Roman', Times, serif;font-size: 17pt;text-align: left; width: 144px; color: #2214B9;border-style: solid;border-width: 1px; background-color: #FFFFE3;">
		<strong>Title:</strong></td>
		<td style="padding:5px; font-family: 'Times New Roman', Times, serif;font-size: 17pt;text-align: left; color: #2214B9;border-style: solid;border-width: 1px; width: 435px; background-color: #FFFFE3;">&nbsp;<strong><input name="title" style="width: 427px; font-size: 15pt; font-family: 'Times New Roman', Times, serif; color: #770505"></strong></td>
		<td style="padding:5px; font-family: 'Times New Roman', Times, serif;font-size: 17pt;text-align: left; color: #77056A; border-style: solid;border-width: 1px; width: 235; background-color: #E3FFFC;" rowspan="2" valign="top">
		<strong>Existing Articles:</strong>
<?php
$sql="SELECT * FROM article";
$result=mysql_query($sql);
while(@$rows=mysql_fetch_array($result)){
	$title=$rows['title'];
	$link=$_SERVER['PHP_SELF'];
	$l=strrpos($link,'/');
	$link=substr($link,1,$l-1);
	$link=$_SERVER['HTTP_HOST'].'/'.$link.'/'.str_replace(' ','_',$title);
	echo"
	<br><a style='text-decoration:none;' href='http://$link'><span style='font-size: 14pt; color: #77056A;'>$title</span></a>
	";
} ?>
	</td></tr>
	<tr>
		<td style="padding:5px; width: 144px; border-style: solid;border-width: 1px;text-align: center; height: 39px; font-size: 14pt; background-color: #FFFFE3;">
		<strong>
		<span style="font-family: 'Times New Roman', Times, serif; font-size: 17pt; color: #2214B9">
		Article Body:<br></span>
		<span style="font-family: 'Times New Roman', Times, serif; color: #2214B9; font-size: 12pt">
		(HTML Supported)<br><br><br><br><br></span></strong>
		<input name="add" style="width: 114px; height: 53px; font-size: 25pt; font-family: 'Times New Roman', Times, serif; color: #119B23" type="submit" value="Add"></td>
		<td style="border-style: solid;border-width: 1px; height: 39px;padding-left: 8px; width: 435px; padding-right: 5px; padding-top: 5px; padding-bottom: 5px; background-color: #FFFFE3;">
		<textarea name="body" style="width: 427px; height: 186px; font-family: 'Times New Roman', Times, serif; font-size: 12pt; color: #770505;"></textarea></td>
	</tr>
</table>
</form>
<div style="text-align: center">
	<font face="Tahoma"><a target="_blank" href="http://www.phpfreecode.com/">
	<span style="font-size: 8pt; text-decoration: none">PHP Free Code</span></a></font></div>
</div>
<a target='_blank' href='www.phpfreecode.com' style='font-size: 8pt; text-decoration: none'>Php Best Codes</a>                                                
                                            

Example:


About @m_k_amin

This user is pending a biography.

M

Comments


Here you can leave us commments. Let us know what you think about this code tutorial!

0 / 300

TRENDING POST
1
2
3
4
5
VISITORS
Online Users: 12
Recent Members: grkkid, Manaakividuinfo.com, karticksv, sava, tinatina
advertisement 2