Jul 26, 2008

Creating Your Own Php News System

Free Web Hosting, No Ads > CONTRIBUTE > Tutorials
Pages: 1, 2, 3

free web hosting

Creating Your Own Php News System

whyme
Hello, heres a simple tutorial from a script that I made to power my news system. It is written withthe PHP coding system and consists of 8 files using a flatfile based system, without MySQL databases. This should be usefull for those who want a simple little news manager and like to have simplcity without the fancy date strings and sutff. You can see a demo of it at my site @ http://www.xeek.trap17.com.

Let's Start!

First let's start with the easy stuff, making the directory first, first create a main directory to hold everything, call this folder "news", now you have a folder, and you're just one step closer to making a news system wink.gif.

STEP 1:
Now create a "edit" folder, now you should have two folders, like so:

news
...edit

now, let's start some PHP biggrin.gif

STEP 2:
Create a PHP page and put in the following code:

CODE
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Your News System</title>

</head>

<body>

<table style="height: 100%; text-align: center; width: 90%">
<tr>
 <td style="vertical-align: middle">
  <table>
   <form method="post" action="%3C? echo $PHP_SELF ?&gt;?action=login">
   <tr>
    <td><b>Login name:</b><br>
    <input type="text" size="30"

name="loginname" onfocus="this.style.borderColor='#0072BC';"

onblur="this.style.borderColor='silver';"></td>
    <td><br></td>
   </tr>
   <tr>
    <td><b>Password:</b><br>
    <input type="password" size="30"

name="password" onfocus="this.style.borderColor='#0072BC';"

onblur="this.style.borderColor='silver';"></td>
    <td><br></td>
   </tr>
   <tr>
    <td colspan="2"><p><? if (substr

($PHP_SELF,-9) == "login.php") { echo "<p>Never link directly to this file, always

link to the protected file!</p>"; } else { echo "<input class=send type=submit

value=\"Login!\">"; } ?></p></td>
   </tr>
   </form>
  </table>  
 </td>
</tr>
</table>

</body>
</html>


Now, what this is the login page for you to enter into your news system. You will notice the POST data on te beginging of the form, this will send the inofrmation of your login details to another page. Save this page to your "edit" folder and call it login.php

STEP 3:
Now, we will make the page where you have login details to, so you'll be able to get into the area where you'll edit your news.

CODE

<?

$user_passwords = array (
"this is your username" => "password"
);

// Designate the name of the "Logged Out" php page.
$logout_page = "logout.php";

// Designate the name of the "Login" php page.
$login_page = "login.php";

// Designate the name of the "Invalid Login Name or Password" php page. enters an
$invalidlogin_page = "invalidlogin.php";


if ($action == "logout")
{
Setcookie("logincookie[pwd]","",time() -86400);
Setcookie("logincookie[user]","",time() - 86400);
include($logout_page);
exit;
}
else if ($action == "login")
{
if (($loginname == "") || ($password == ""))
{
 include($invalidlogin_page);
 exit;
}
else if (strcmp($user_passwords[$loginname],$password) == 0)
{
 Setcookie("logincookie[pwd]",$password,time() + 86400);
 Setcookie("logincookie[user]",$loginname,time() + 86400);
}
else
{
 include($invalidlogin_page);
 exit;
}
}
else
{
if (($logincookie[pwd] == "") || ($logincookie[user] == ""))
{
 include($login_page);
 exit;
}
else if (strcmp($user_passwords[$logincookie[user]],$logincookie[pwd]) == 0)
{
 Setcookie("logincookie[pwd]",$logincookie[pwd],time() + 86400);
 Setcookie("logincookie[user]",$logincookie[user],time() + 86400);
}
else
{
 include($invalidlogin_page);
 exit;
}
}
?>



What this does is set a cookie that verfies for how long you wil be able to access the editing the page, as well as the password and username that you will use enter into the news section. You can see that I have the area for the password and username, simply change those values to the ones that you want. Also, if you want to say, have multple people that can access your page, just add another line of password and username, like so:

$user_passwords = array (
"this is your username" => "password"
"this is another username" => "anotherpassword"
);

Now, call this page protect.php and save it to your "edit "folder

STEP 4:
OK, now we have the page where we can login and a page where the script will know our password and username. Now, we need to add in a page where we'll redirect the user if they make an error in typing their user info: We will do the following coding:

CODE

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Login Error</title>
</head>

<body>

<table style="height: 100%; text-align: center; width: 90%">
<tr>
 <td style="height: 65px; padding: 10px 0px 0px 10px; text-align: left"></td>
</tr>
<tr>
 <td style="vertical-align: middle">
  <table>
   <form method="post" action="<? echo $PHP_SELF ?>?action=login">
   <tr>
    <td><b>Login name:</b><br>
    <input type="text" size="30" name="loginname" onfocus="this.style.borderColor='#0072BC';" onblur="this.style.borderColor='silver';"></td>
    <td><br></td>
   </tr>
   <tr>
    <td><b>Password:</b><br>
    <input type="password" size="30" name="password" onfocus="this.style.borderColor='#0072BC';" onblur="this.style.borderColor='silver';"></td>
    <td><br></td>
   </tr>
   <tr>
    <td colspan="2"><p><? if (substr($PHP_SELF,-9) == "login.php") { echo "<p>Never link directly to this file, always link to the protected file!</p>"; } else { echo "<input class=send type=submit value=\"Login!\">"; } ?></p>
    <p><span class="error"><b>Invalid login name or password!</b> &nbsp;Please try again.</span></p></td>
   </tr>
   </form>
  </table>  
 </td>
</tr>
</table>

</body>
</html>



This is simply an HTML page where the user will be recriected to if they type the incorrect password.

Now we will call this page invalidlogin.php and save it to the "edit folder" too

CHECK UP TIME!
Now, just to check that we are on track, you should have the following folders and files

>news
...edit
......login.php
......protect.php
......invalidlogin.php

If this is how your strcutrue looks like, you're on the right track! biggrin.gif

STEP 5:
Now, we will create a page that the user will be led to when they log out:

CODE


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Your news system</title>
</head>

<body>
 <p>You have logged out.<p>Click <a href="index.php">here</a> to login again.</p></td>
</body>
</html>



Again, this is just a simple HTML page which shows the user that they have logged out. Call this page [B]logout.php and save it to your "edit" folder.[/B]

STEP 6:
Now, here's an easy part, create a blank text file and call it "news.txt.", save this to your "edit folder". This textfile is the place where your news will be stored and saved to.

STEP 7:
Here begins where the news will come alive, use the following code:

CODE


<? include("protect.php"); ?>

<?php
$data_file='news.txt';
$changes='';

if(isset($contents)) {
     $archive=fopen($data_file,'r+');
     flock($archive,2);
     ftruncate($archive,0);
     fputs($archive,$contents);
     flock($archive,3);
     fclose($archive);
     unset($contents);
    $changes='<b style="color:#ff6600">Changes made!</b>&nbsp;&nbsp;&raquo;&nbsp;&nbsp;<a href="../">View Changes</a><br />';
}

function getfile($filename) {
  $fd = fopen($filename, "rb");
  $content = fread($fd, filesize($filename));
 fclose($fd);
  return $content;
}

$data=getfile($data_file);
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Your news system</title>

</head>

<body>

<table style="height: 100%; text-align: center; width: 90%">
<tr>
 
   <td style="height: 65px; padding: 10px 0px 0px 10px; text-align: left">Login
     succesful! - Please edit your news.</td>
</tr>
<script language="Javascript" type="text/javascript">
<!--
function view() {
q=open("","l"," status=0,toolbar=0,width=560,height=420,resizable=1,menubar=0,location=0");
q.document.open();
q.document.write('<html><head><title>News/Content Publisher - Preview Window</title>');fs
q.document.write('</head><body><table bgcolor="#ffffff" width="100%" height="100%"><tr valign="top"><td style="color: #666666; line-height: 16px; padding: 10px 20px 0px 20px;">');
q.document.write(document.forms[0].contents.value);
q.document.write('</td></tr>');
q.document.write('<tr valign="bottom"><td align="center" style="line-height: 16px;"><a href="javascript:window.close();"  onmouseover="window.status = \'Close Window\'; return true;" onmouseout="window.status = \'\'; return true;">Close Window</a>');
q.document.write('</td></tr></table>');
q.document.write('</body></html>');
q.document.close();
}

//-->
</script>
<form name="editform" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>" onsubmit="if(q&&!q.closed)q.close();return true">
<tr>
 <td style="vertical-align: middle">
 <div align="center"><fieldset style="border: 1px solid #CCC; width: 50%"><legend style="margin-left: 8px">&nbsp;Edit News/Events Information Here:&nbsp;</legend>
 <div style="padding: 20px">
 <div align="right"><a href="<? echo $PHP_SELF ?>?action=logout"><img src="/art/logout.gif" alt="Log Out" width="17" height="16" border="0" align="absmiddle"> Log Out</a></div>
 <?php echo $changes; ?>
 <p><input style="margin:0px;" type="button" value="Bold" onClick="editform.contents.value+='<b></b>'"> <input type="button" value="Italic" onClick="editform.contents.value+='<i></i>'"> <input type="button" value="Space" onClick="editform.contents.value+='<br>'"> <input type="button" value="Dbl Space" onClick="editform.contents.value+='<p>'"> <input type="button" value="Quote" onClick="editform.contents.value+='&acute;'"> <input type="button" value="Dbl Quote" onClick="editform.contents.value+='&ldquo;&rdquo;'"><br>
 <textarea name="contents" rows="20" cols="50" tabindex="2"><?php echo $data;?></textarea><br />
 <input class="send" style="margin:0px;" type="button" onClick="view()" value="Preview" />&nbsp; &nbsp;<input class="send" type="submit" name="submitdata" value="Submit" />&nbsp; &nbsp;<input class="reset" type="reset" name="resetdata" value="Erase Changed" /></p></div></fieldset></div></td>
</tr>
</form>
</table>

</body>
</html>




I know it's a mouth full, but i will do the best to explin it. At the very top, you see the protect.php include function, this means that only autoixed users which know the username and password can enter, otherwise, they will be recitected to the login page. This include function ensures that your news system is safe. The rest of the php tells the server to write and send the information to the news.txt file. Now, the rest of the HTML is the area that you will be able to edit your news.

Now, save this as index.php in the "edit folder"

We're almost done!

CHECK UP 2!
Just to see that you are on track, you should have the following files in your "edit "folder.

index.php
protect.php
login.php
invalidlogin.php
logout.php
news.txt

STEP 8:
We're now done the hardest part of the script, it's all smooth sailing from here. Moing away from the "edit" folder, we will now go to the root directory, meaning to the "news" folder. We will now create the page which will display all of the information that you have posted. Put in the following code.

CODE


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Your News Login system</title>
</head>

<body>

       <? include("edit/news.txt") ?>

</body>
</html>


All it is a simple HTML page that will do the PHP include function, which in turn places the information into an HTML page.

biggrin.gif YOU'RE FINISHED! biggrin.gif

Now uplaod all the files to your server, and go to http://yoursite.com/news/edit/index.php, this will lead you to the login page, login with your username and password, and bingo! you will get in. You will have a text box along with other functions that will let you add text to it, and it's also HTML compatible, so you can paste HTML and it will be rendered out as HTML. After you have posted, go to http://yoursite.com/news/index.php, and voila! your news!

If you want to have multiple pages display that informaiton, simply use the include function in PHP like so:

<? include("edit/news.txt") ?>

I highly recommend adding in sytle sheets to make it suit your taste.

I know it's a long tutorial, but hopefully, you've learned how to make a good sizeable news system, further more, you can enrich it by adding in CSS Style sheets, something that I haven't done here. feel free to modify this script, but give me some credit wink.gif.

- whyme (hands and fingers are sooooo tired)

If you have any questions problems or difficulite,s don't hesitate to PM me or poast of this thread

 

 

 


Reply

thugnature
damn i think i might use this for the site im building now because im trying fusion php and the it wont workk thanks for the tutorial.

Reply

Serious Gamer
QUOTE(whyme @ Feb 19 2005, 03:23 AM)
Hello, heres a simple tutorial from a script that I made to power my news system. It is written withthe PHP coding system and consists of 8 files using a flatfile based system, without MySQL databases. This should be usefull for those who want a simple little news manager and like to have simplcity without the fancy date strings and sutff. You can see a demo of it at my site @ http://www.xeek.trap17.com.

Let's Start!

First let's start with the easy stuff, making the directory first, first create a main directory to hold everything, call this folder "news", now you have a folder, and you're just one step closer to making a news system wink.gif.

STEP 1:
Now create a "edit" folder, now you should have two folders, like so:

news
...edit

now, let's start some PHP biggrin.gif

STEP 2:
Create a PHP page and put in the following code:

CODE
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Your News System</title>

</head>

<body>

<table style="height: 100%; text-align: center; width: 90%">
<tr>
 <td style="vertical-align: middle">
  <table>
   <form method="post" action="%3C? echo $PHP_SELF ?&gt;?action=login">
   <tr>
    <td><b>Login name:</b><br>
    <input type="text" size="30"

name="loginname" onfocus="this.style.borderColor='#0072BC';"

onblur="this.style.borderColor='silver';"></td>
    <td><br></td>
   </tr>
   <tr>
    <td><b>Password:</b><br>
    <input type="password" size="30"

name="password" onfocus="this.style.borderColor='#0072BC';"

onblur="this.style.borderColor='silver';"></td>
    <td><br></td>
   </tr>
   <tr>
    <td colspan="2"><p><? if (substr

($PHP_SELF,-9) == "login.php") { echo "<p>Never link directly to this file, always

link to the protected file!</p>"; } else { echo "<input class=send type=submit

value=\"Login!\">"; } ?></p></td>
   </tr>
   </form>
  </table>  
 </td>
</tr>
</table>

</body>
</html>


Now, what this is the login page for you to enter into your news system. You will notice the POST data on te beginging of the form, this will send the inofrmation of your login details to another page. Save this page to your "edit" folder and call it login.php

STEP 3:
Now, we will make the page where you have login details to, so you'll be able to get into the area where you'll edit your news.

CODE

<?

$user_passwords = array (
"this is your username" => "password"
);

// Designate the name of the "Logged Out" php page.
$logout_page = "logout.php";

// Designate the name of the "Login" php page.
$login_page = "login.php";

// Designate the name of the "Invalid Login Name or Password" php page. enters an
$invalidlogin_page = "invalidlogin.php";
if ($action == "logout")
{
Setcookie("logincookie[pwd]","",time() -86400);
Setcookie("logincookie[user]","",time() - 86400);
include($logout_page);
exit;
}
else if ($action == "login")
{
if (($loginname == "") || ($password == ""))
{
 include($invalidlogin_page);
 exit;
}
else if (strcmp($user_passwords[$loginname],$password) == 0)
{
 Setcookie("logincookie[pwd]",$password,time() + 86400);
 Setcookie("logincookie[user]",$loginname,time() + 86400);
}
else
{
 include($invalidlogin_page);
 exit;
}
}
else
{
if (($logincookie[pwd] == "") || ($logincookie[user] == ""))
{
 include($login_page);
 exit;
}
else if (strcmp($user_passwords[$logincookie[user]],$logincookie[pwd]) == 0)
{
 Setcookie("logincookie[pwd]",$logincookie[pwd],time() + 86400);
 Setcookie("logincookie[user]",$logincookie[user],time() + 86400);
}
else
{
 include($invalidlogin_page);
 exit;
}
}
?>



What this does is set a cookie that verfies for how long you wil be able to access the editing the page, as well as the password and username that you will use enter into the news section. You can see that I have the area for the password and username, simply change those values to the ones that you want. Also, if you want to say, have multple people that can access your page, just add another line of password and username, like so:

$user_passwords = array (
"this is your username" => "password"
        "this is another username" => "anotherpassword"
);

Now, call this page protect.php and save it to your "edit "folder

STEP 4:
OK, now we have the page where we can login and a page where the script will know our password and username. Now, we need to add in a page where we'll redirect the user if they make an error in typing their user info: We will do the following coding:

CODE

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Login Error</title>
</head>

<body>

<table style="height: 100%; text-align: center; width: 90%">
<tr>
 <td style="height: 65px; padding: 10px 0px 0px 10px; text-align: left"></td>
</tr>
<tr>
 <td style="vertical-align: middle">
  <table>
   <form method="post" action="<? echo $PHP_SELF ?>?action=login">
   <tr>
    <td><b>Login name:</b><br>
    <input type="text" size="30" name="loginname" onfocus="this.style.borderColor='#0072BC';" onblur="this.style.borderColor='silver';"></td>
    <td><br></td>
   </tr>
   <tr>
    <td><b>Password:</b><br>
    <input type="password" size="30" name="password" onfocus="this.style.borderColor='#0072BC';" onblur="this.style.borderColor='silver';"></td>
    <td><br></td>
   </tr>
   <tr>
    <td colspan="2"><p><? if (substr($PHP_SELF,-9) == "login.php") { echo "<p>Never link directly to this file, always link to the protected file!</p>"; } else { echo "<input class=send type=submit value=\"Login!\">"; } ?></p>
    <p><span class="error"><b>Invalid login name or password!</b> &nbsp;Please try again.</span></p></td>
   </tr>
   </form>
  </table>  
 </td>
</tr>
</table>

</body>
</html>



This is simply an HTML page where the user will be recriected to if they type the incorrect password.

Now we will call this page invalidlogin.php and save it to the "edit folder" too

CHECK UP TIME!
Now, just to check that we are on track, you should have the following folders and files

>news
...edit
......login.php
......protect.php
......invalidlogin.php

If this is how your strcutrue looks like, you're on the right track! biggrin.gif

STEP 5:
Now, we will create a page that the user will be led to when they log out:

CODE


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Your news system</title>
</head>

<body>
 <p>You have logged out.<p>Click <a href="index.php">here</a> to login again.</p></td>
</body>
</html>



Again, this is just a simple HTML page which shows the user that they have logged out. Call this page [B]logout.php and save it to your "edit" folder.[/B]

STEP 6:
Now, here's an easy part, create a blank text file and call it "news.txt.", save this to your "edit folder". This textfile is the place where your news will be stored and saved to.

STEP 7:
Here begins where the news will come alive, use the following code:

CODE


<? include("protect.php"); ?>

<?php
$data_file='news.txt';
$changes='';

if(isset($contents)) {
     $archive=fopen($data_file,'r+');
     flock($archive,2);
     ftruncate($archive,0);
     fputs($archive,$contents);
     flock($archive,3);
     fclose($archive);
     unset($contents);
    $changes='<b style="color:#ff6600">Changes made!</b>&nbsp;&nbsp;&raquo;&nbsp;&nbsp;<a href="../">View Changes</a><br />';
}

function getfile($filename) {
  $fd = fopen($filename, "rb");
  $content = fread($fd, filesize($filename));
 fclose($fd);
  return $content;
}

$data=getfile($data_file);
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Your news system</title>

</head>

<body>

<table style="height: 100%; text-align: center; width: 90%">
<tr>
 
   <td style="height: 65px; padding: 10px 0px 0px 10px; text-align: left">Login
     succesful! - Please edit your news.</td>
</tr>
<script language="Javascript" type="text/javascript">
<!--
function view() {
q=open("","l"," status=0,toolbar=0,width=560,height=420,resizable=1,menubar=0,location=0");
q.document.open();
q.document.write('<html><head><title>News/Content Publisher - Preview Window</title>');fs
q.document.write('</head><body><table bgcolor="#ffffff" width="100%" height="100%"><tr valign="top"><td style="color: #666666; line-height: 16px; padding: 10px 20px 0px 20px;">');
q.document.write(document.forms[0].contents.value);
q.document.write('</td></tr>');
q.document.write('<tr valign="bottom"><td align="center" style="line-height: 16px;"><a href="javascript:window.close();"  onmouseover="window.status = \'Close Window\'; return true;" onmouseout="window.status = \'\'; return true;">Close Window</a>');
q.document.write('</td></tr></table>');
q.document.write('</body></html>');
q.document.close();
}

//-->
</script>
<form name="editform" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>" onsubmit="if(q&&!q.closed)q.close();return true">
<tr>
 <td style="vertical-align: middle">
 <div align="center"><fieldset style="border: 1px solid #CCC; width: 50%"><legend style="margin-left: 8px">&nbsp;Edit News/Events Information Here:&nbsp;</legend>
 <div style="padding: 20px">
 <div align="right"><a href="<? echo $PHP_SELF ?>?action=logout"><img src="/art/logout.gif" alt="Log Out" width="17" height="16" border="0" align="absmiddle"> Log Out</a></div>
 <?php echo $changes; ?>
 <p><input style="margin:0px;" type="button" value="Bold" onClick="editform.contents.value+='<b></b>'"> <input type="button" value="Italic" onClick="editform.contents.value+='<i></i>'"> <input type="button" value="Space" onClick="editform.contents.value+='<br>'"> <input type="button" value="Dbl Space" onClick="editform.contents.value+='<p>'"> <input type="button" value="Quote" onClick="editform.contents.value+='&acute;'"> <input type="button" value="Dbl Quote" onClick="editform.contents.value+='&ldquo;&rdquo;'"><br>
 <textarea name="contents" rows="20" cols="50" tabindex="2"><?php echo $data;?></textarea><br />
 <input class="send" style="margin:0px;" type="button" onClick="view()" value="Preview" />&nbsp; &nbsp;<input class="send" type="submit" name="submitdata" value="Submit" />&nbsp; &nbsp;<input class="reset" type="reset" name="resetdata" value="Erase Changed" /></p></div></fieldset></div></td>
</tr>
</form>
</table>

</body>
</html>


I know it's a mouth full, but i will do the best to explin it. At the very top, you see the protect.php include function, this means that only autoixed users which know the username and password can enter, otherwise, they will be recitected to the login page. This include function ensures that your news system is safe. The rest of the php tells the server to write and send the information to the news.txt file. Now, the rest of the HTML is the area that you will be able to edit your news.

Now, save this as index.php in the "edit folder"

We're almost done!

CHECK UP 2!
Just to see that you are on track, you should have the following files in your "edit "folder.

index.php
protect.php
login.php
invalidlogin.php
logout.php
news.txt

STEP 8:
We're now done the hardest part of the script, it's all smooth sailing from here. Moing away from the "edit" folder, we will now go to the root directory, meaning to the "news" folder. We will now create the page which will display all of the information that you have posted. Put in the following code.

CODE


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Your News Login system</title>
</head>

<body>

       <? include("edit/news.txt") ?>

</body>
</html>


All it is a simple HTML page that will do the PHP include function, which in turn places the information into an HTML page.

biggrin.gif YOU'RE FINISHED! biggrin.gif

Now uplaod all the files to your server, and go to http://yoursite.com/news/edit/index.php, this will lead you to the login page, login with your username and password, and bingo! you will get in. You will have a text box along with other functions that will let you add text to it, and it's also HTML compatible, so you can paste HTML and it will be rendered out as HTML. After you have posted, go to http://yoursite.com/news/index.php, and voila! your news!

If you want to have multiple pages display that informaiton, simply use the include function in PHP like so:

<? include("edit/news.txt") ?>

I highly recommend adding in sytle sheets to make it suit your taste.

I know it's a long tutorial, but hopefully, you've learned how to make a good sizeable news system, further more, you can enrich it by adding in CSS Style sheets, something that I haven't done here. feel free to modify this script, but give me some credit wink.gif.

- whyme (hands and fingers are sooooo tired)

If you have any questions problems or difficulite,s don't hesitate to PM me or poast of this thread
*


wow it seems ur pretty good at this eh

 

 

 


Reply

chiclete
"wow it seems ur pretty good at this eh"...
I agree with you... I've just started my PHP development yesterday and I needed some news like this... I'll try to make some changes because I want it to something else too but thanks for this great tutorial... I'm going to change my website layout now because the one I've none is just too ugly hehehe... so I'm going to make some improvements on it biggrin.gif

Reply

karlo
QUOTE(whyme @ Feb 19 2005, 11:23 AM)
Hello, heres a simple tutorial from a script that I made to power my news system. It is written withthe PHP coding system and consists of 8 files using a flatfile based system, without MySQL databases. This should be usefull for those who want a simple little news manager and like to have simplcity without the fancy date strings and sutff. You can see a demo of it at my site @ http://www.xeek.trap17.com.

Let's Start!

First let's start with the easy stuff, making the directory first, first create a main directory to hold everything, call this folder "news", now you have a folder, and you're just one step closer to making a news system wink.gif.

STEP 1:
Now create a "edit" folder, now you should have two folders, like so:

news
...edit

now, let's start some PHP biggrin.gif

STEP 2:
Create a PHP page and put in the following code:

CODE
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Your News System</title>

</head>

<body>

<table style="height: 100%; text-align: center; width: 90%">
<tr>
 <td style="vertical-align: middle">
  <table>
   <form method="post" action="%3C? echo $PHP_SELF ?&gt;?action=login">
   <tr>
    <td><b>Login name:</b><br>
    <input type="text" size="30"

name="loginname" onfocus="this.style.borderColor='#0072BC';"

onblur="this.style.borderColor='silver';"></td>
    <td><br></td>
   </tr>
   <tr>
    <td><b>Password:</b><br>
    <input type="password" size="30"

name="password" onfocus="this.style.borderColor='#0072BC';"

onblur="this.style.borderColor='silver';"></td>
    <td><br></td>
   </tr>
   <tr>
    <td colspan="2"><p><? if (substr

($PHP_SELF,-9) == "login.php") { echo "<p>Never link directly to this file, always

link to the protected file!</p>"; } else { echo "<input class=send type=submit

value=\"Login!\">"; } ?></p></td>
   </tr>
   </form>
  </table>  
 </td>
</tr>
</table>

</body>
</html>


Now, what this is the login page for you to enter into your news system. You will notice the POST data on te beginging of the form, this will send the inofrmation of your login details to another page. Save this page to your "edit" folder and call it login.php

STEP 3:
Now, we will make the page where you have login details to, so you'll be able to get into the area where you'll edit your news.

CODE

<?

$user_passwords = array (
"this is your username" => "password"
);

// Designate the name of the "Logged Out" php page.
$logout_page = "logout.php";

// Designate the name of the "Login" php page.
$login_page = "login.php";

// Designate the name of the "Invalid Login Name or Password" php page. enters an
$invalidlogin_page = "invalidlogin.php";
if ($action == "logout")
{
Setcookie("logincookie[pwd]","",time() -86400);
Setcookie("logincookie[user]","",time() - 86400);
include($logout_page);
exit;
}
else if ($action == "login")
{
if (($loginname == "") || ($password == ""))
{
 include($invalidlogin_page);
 exit;
}
else if (strcmp($user_passwords[$loginname],$password) == 0)
{
 Setcookie("logincookie[pwd]",$password,time() + 86400);
 Setcookie("logincookie[user]",$loginname,time() + 86400);
}
else
{
 include($invalidlogin_page);
 exit;
}
}
else
{
if (($logincookie[pwd] == "") || ($logincookie[user] == ""))
{
 include($login_page);
 exit;
}
else if (strcmp($user_passwords[$logincookie[user]],$logincookie[pwd]) == 0)
{
 Setcookie("logincookie[pwd]",$logincookie[pwd],time() + 86400);
 Setcookie("logincookie[user]",$logincookie[user],time() + 86400);
}
else
{
 include($invalidlogin_page);
 exit;
}
}
?>



What this does is set a cookie that verfies for how long you wil be able to access the editing the page, as well as the password and username that you will use enter into the news section. You can see that I have the area for the password and username, simply change those values to the ones that you want. Also, if you want to say, have multple people that can access your page, just add another line of password and username, like so:

$user_passwords = array (
"this is your username" => "password"
        "this is another username" => "anotherpassword"
);

Now, call this page protect.php and save it to your "edit "folder

STEP 4:
OK, now we have the page where we can login and a page where the script will know our password and username. Now, we need to add in a page where we'll redirect the user if they make an error in typing their user info: We will do the following coding:

CODE

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Login Error</title>
</head>

<body>

<table style="height: 100%; text-align: center; width: 90%">
<tr>
 <td style="height: 65px; padding: 10px 0px 0px 10px; text-align: left"></td>
</tr>
<tr>
 <td style="vertical-align: middle">
  <table>
   <form method="post" action="<? echo $PHP_SELF ?>?action=login">
   <tr>
    <td><b>Login name:</b><br>
    <input type="text" size="30" name="loginname" onfocus="this.style.borderColor='#0072BC';" onblur="this.style.borderColor='silver';"></td>
    <td><br></td>
   </tr>
   <tr>
    <td><b>Password:</b><br>
    <input type="password" size="30" name="password" onfocus="this.style.borderColor='#0072BC';" onblur="this.style.borderColor='silver';"></td>
    <td><br></td>
   </tr>
   <tr>
    <td colspan="2"><p><? if (substr($PHP_SELF,-9) == "login.php") { echo "<p>Never link directly to this file, always link to the protected file!</p>"; } else { echo "<input class=send type=submit value=\"Login!\">"; } ?></p>
    <p><span class="error"><b>Invalid login name or password!</b> &nbsp;Please try again.</span></p></td>
   </tr>
   </form>
  </table>  
 </td>
</tr>
</table>

</body>
</html>



This is simply an HTML page where the user will be recriected to if they type the incorrect password.

Now we will call this page invalidlogin.php and save it to the "edit folder" too

CHECK UP TIME!
Now, just to check that we are on track, you should have the following folders and files

>news
...edit
......login.php
......protect.php
......invalidlogin.php

If this is how your strcutrue looks like, you're on the right track! biggrin.gif

STEP 5:
Now, we will create a page that the user will be led to when they log out:

CODE


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Your news system</title>
</head>

<body>
 <p>You have logged out.<p>Click <a href="index.php">here</a> to login again.</p></td>
</body>
</html>



Again, this is just a simple HTML page which shows the user that they have logged out. Call this page [B]logout.php and save it to your "edit" folder.[/B]

STEP 6:
Now, here's an easy part, create a blank text file and call it "news.txt.", save this to your "edit folder". This textfile is the place where your news will be stored and saved to.

STEP 7:
Here begins where the news will come alive, use the following code:

CODE


<? include("protect.php"); ?>

<?php
$data_file='news.txt';
$changes='';

if(isset($contents)) {
     $archive=fopen($data_file,'r+');
     flock($archive,2);
     ftruncate($archive,0);
     fputs($archive,$contents);
     flock($archive,3);
     fclose($archive);
     unset($contents);
    $changes='<b style="color:#ff6600">Changes made!</b>&nbsp;&nbsp;&raquo;&nbsp;&nbsp;<a href="../">View Changes</a><br />';
}

function getfile($filename) {
  $fd = fopen($filename, "rb");
  $content = fread($fd, filesize($filename));
 fclose($fd);
  return $content;
}

$data=getfile($data_file);
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Your news system</title>

</head>

<body>

<table style="height: 100%; text-align: center; width: 90%">
<tr>
 
   <td style="height: 65px; padding: 10px 0px 0px 10px; text-align: left">Login
     succesful! - Please edit your news.</td>
</tr>
<script language="Javascript" type="text/javascript">
<!--
function view() {
q=open("","l"," status=0,toolbar=0,width=560,height=420,resizable=1,menubar=0,location=0");
q.document.open();
q.document.write('<html><head><title>News/Content Publisher - Preview Window</title>');fs
q.document.write('</head><body><table bgcolor="#ffffff" width="100%" height="100%"><tr valign="top"><td style="color: #666666; line-height: 16px; padding: 10px 20px 0px 20px;">');
q.document.write(document.forms[0].contents.value);
q.document.write('</td></tr>');
q.document.write('<tr valign="bottom"><td align="center" style="line-height: 16px;"><a href="javascript:window.close();"  onmouseover="window.status = \'Close Window\'; return true;" onmouseout="window.status = \'\'; return true;">Close Window</a>');
q.document.write('</td></tr></table>');
q.document.write('</body></html>');
q.document.close();
}

//-->
</script>
<form name="editform" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>" onsubmit="if(q&&!q.closed)q.close();return true">
<tr>
 <td style="vertical-align: middle">
 <div align="center"><fieldset style="border: 1px solid #CCC; width: 50%"><legend style="margin-left: 8px">&nbsp;Edit News/Events Information Here:&nbsp;</legend>
 <div style="padding: 20px">
 <div align="right"><a href="<? echo $PHP_SELF ?>?action=logout"><img src="/art/logout.gif" alt="Log Out" width="17" height="16" border="0" align="absmiddle"> Log Out</a></div>
 <?php echo $changes; ?>
 <p><input style="margin:0px;" type="button" value="Bold" onClick="editform.contents.value+='<b></b>'"> <input type="button" value="Italic" onClick="editform.contents.value+='<i></i>'"> <input type="button" value="Space" onClick="editform.contents.value+='<br>'"> <input type="button" value="Dbl Space" onClick="editform.contents.value+='<p>'"> <input type="button" value="Quote" onClick="editform.contents.value+='&acute;'"> <input type="button" value="Dbl Quote" onClick="editform.contents.value+='&ldquo;&rdquo;'"><br>
 <textarea name="contents" rows="20" cols="50" tabindex="2"><?php echo $data;?></textarea><br />
 <input class="send" style="margin:0px;" type="button" onClick="view()" value="Preview" />&nbsp; &nbsp;<input class="send" type="submit" name="submitdata" value="Submit" />&nbsp; &nbsp;<input class="reset" type="reset" name="resetdata" value="Erase Changed" /></p></div></fieldset></div></td>
</tr>
</form>
</table>

</body>
</html>


I know it's a mouth full, but i will do the best to explin it. At the very top, you see the protect.php include function, this means that only autoixed users which know the username and password can enter, otherwise, they will be recitected to the login page. This include function ensures that your news system is safe. The rest of the php tells the server to write and send the information to the news.txt file. Now, the rest of the HTML is the area that you will be able to edit your news.

Now, save this as index.php in the "edit folder"

We're almost done!

CHECK UP 2!
Just to see that you are on track, you should have the following files in your "edit "folder.

index.php
protect.php
login.php
invalidlogin.php
logout.php
news.txt

STEP 8:
We're now done the hardest part of the script, it's all smooth sailing from here. Moing away from the "edit" folder, we will now go to the root directory, meaning to the "news" folder. We will now create the page which will display all of the information that you have posted. Put in the following code.

CODE


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Your News Login system</title>
</head>

<body>

       <? include("edit/news.txt") ?>

</body>
</html>


All it is a simple HTML page that will do the PHP include function, which in turn places the information into an HTML page.

biggrin.gif YOU'RE FINISHED! biggrin.gif

Now uplaod all the files to your server, and go to http://yoursite.com/news/edit/index.php, this will lead you to the login page, login with your username and password, and bingo! you will get in. You will have a text box along with other functions that will let you add text to it, and it's also HTML compatible, so you can paste HTML and it will be rendered out as HTML. After you have posted, go to http://yoursite.com/news/index.php, and voila! your news!

If you want to have multiple pages display that informaiton, simply use the include function in PHP like so:

<? include("edit/news.txt") ?>

I highly recommend adding in sytle sheets to make it suit your taste.

I know it's a long tutorial, but hopefully, you've learned how to make a good sizeable news system, further more, you can enrich it by adding in CSS Style sheets, something that I haven't done here. feel free to modify this script, but give me some credit wink.gif.

- whyme (hands and fingers are sooooo tired)

If you have any questions problems or difficulite,s don't hesitate to PM me or poast of this thread
*



I love the code. But can you please put some comments on your PHP Scripts. So PHP beginners like me, will be able to understand the code easily. Please.

Example, what is strcmp()? how do I check if I enter the right username and password from an array?

And also, recommend PHP tutorial website where user will be able to understand it easily.

On the code of your html, i think you used a WYSIWYG editor, right? Nvu perhaps?

Reply

mahesh2k
nice tutorial
well i guess i have to make my hands dirty with php now....
smile.gif
keep posting...

Reply

karlo
QUOTE(mahesh2k @ Feb 19 2005, 11:39 PM)
nice tutorial
well i guess i have to make my hands dirty with php now....
smile.gif
keep posting...
*



Make your hands dirty in PHP? How? Are you really a PHP expert?

Reply

whyme
I agree that I should have made comments along with the code so people would understand it more, dang, i'll do it next time i make another tutorial, also, the strcmp is just to check that the username and password is correct so the system can verfiy it and proccess a cookie, checking the password and username from an array is done through the script it self, see the index.php in the "edit" folder and you'll see what i mean.

Reply

eskick
hey seems prety gud but where did you get it from a modification or somthing?

Reply

shadow skazi
QUOTE(whyme @ Feb 18 2005, 10:23 PM)
Hello, heres a simple tutorial from a script that I made to power my news system. It is written withthe PHP coding system and consists of 8 files using a flatfile based system, without MySQL databases. This should be usefull for those who want a simple little news manager and like to have simplcity without the fancy date strings and sutff. You can see a demo of it at my site @ http://www.xeek.trap17.com.

Let's Start!

First let's start with the easy stuff, making the directory first, first create a main directory to hold everything, call this folder "news", now you have a folder, and you're just one step closer to making a news system wink.gif.

STEP 1:
Now create a "edit" folder, now you should have two folders, like so:

news
...edit

now, let's start some PHP biggrin.gif

STEP 2:
Create a PHP page and put in the following code:

CODE
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Your News System</title>

</head>

<body>

<table style="height: 100%; text-align: center; width: 90%">
<tr>
 <td style="vertical-align: middle">
  <table>
   <form method="post" action="%3C? echo $PHP_SELF ?&gt;?action=login">
   <tr>
    <td><b>Login name:</b><br>
    <input type="text" size="30"

name="loginname" onfocus="this.style.borderColor='#0072BC';"

onblur="this.style.borderColor='silver';"></td>
    <td><br></td>
   </tr>
   <tr>
    <td><b>Password:</b><br>
    <input type="password" size="30"

name="password" onfocus="this.style.borderColor='#0072BC';"

onblur="this.style.borderColor='silver';"></td>
    <td><br></td>
   </tr>
   <tr>
    <td colspan="2"><p><? if (substr

($PHP_SELF,-9) == "login.php") { echo "<p>Never link directly to this file, always

link to the protected file!</p>"; } else { echo "<input class=send type=submit

value=\"Login!\">"; } ?></p></td>
   </tr>
   </form>
  </table>  
 </td>
</tr>
</table>

</body>
</html>


Now, what this is the login page for you to enter into your news system. You will notice the POST data on te beginging of the form, this will send the inofrmation of your login details to another page. Save this page to your "edit" folder and call it login.php

STEP 3:
Now, we will make the page where you have login details to, so you'll be able to get into the area where you'll edit your news.

CODE

<?

$user_passwords = array (
"this is your username" => "password"
);

// Designate the name of the "Logged Out" php page.
$logout_page = "logout.php";

// Designate the name of the "Login" php page.
$login_page = "login.php";

// Designate the name of the "Invalid Login Name or Password" php page. enters an
$invalidlogin_page = "invalidlogin.php";
if ($action == "logout")
{
Setcookie("logincookie[pwd]","",time() -86400);
Setcookie("logincookie[user]","",time() - 86400);
include($logout_page);
exit;
}
else if ($action == "login")
{
if (($loginname == "") || ($password == ""))
{
 include($invalidlogin_page);
 exit;
}
else if (strcmp($user_passwords[$loginname],$password) == 0)
{
 Setcookie("logincookie[pwd]",$password,time() + 86400);
 Setcookie("logincookie[user]",$loginname,time() + 86400);
}
else
{
 include($invalidlogin_page);
 exit;
}
}
else
{
if (($logincookie[pwd] == "") || ($logincookie[user] == ""))
{
 include($login_page);
 exit;
}
else if (strcmp($user_passwords[$logincookie[user]],$logincookie[pwd]) == 0)
{
 Setcookie("logincookie[pwd]",$logincookie[pwd],time() + 86400);
 Setcookie("logincookie[user]",$logincookie[user],time() + 86400);
}
else
{
 include($invalidlogin_page);
 exit;
}
}
?>



What this does is set a cookie that verfies for how long you wil be able to access the editing the page, as well as the password and username that you will use enter into the news section. You can see that I have the area for the password and username, simply change those values to the ones that you want. Also, if you want to say, have multple people that can access your page, just add another line of password and username, like so:

$user_passwords = array (
"this is your username" => "password"
        "this is another username" => "anotherpassword"
);

Now, call this page protect.php and save it to your "edit "folder

STEP 4:
OK, now we have the page where we can login and a page where the script will know our password and username. Now, we need to add in a page where we'll redirect the user if they make an error in typing their user info: We will do the following coding:

CODE

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Login Error</title>
</head>

<body>

<table style="height: 100%; text-align: center; width: 90%">
<tr>
 <td style="height: 65px; padding: 10px 0px 0px 10px; text-align: left"></td>
</tr>
<tr>
 <td style="vertical-align: middle">
  <table>
   <form method="post" action="<? echo $PHP_SELF ?>?action=login">
   <tr>
    <td><b>Login name:</b><br>
    <input type="text" size="30" name="loginname" onfocus="this.style.borderColor='#0072BC';" onblur="this.style.borderColor='silver';"></td>
    <td><br></td>
   </tr>
   <tr>
    <td><b>Password:</b><br>
    <input type="password" size="30" name="password" onfocus="this.style.borderColor='#0072BC';" onblur="this.style.borderColor='silver';"></td>
    <td><br></td>
   </tr>
   <tr>
    <td colspan="2"><p><? if (substr($PHP_SELF,-9) == "login.php") { echo "<p>Never link directly to this file, always link to the protected file!</p>"; } else { echo "<input class=send type=submit value=\"Login!\">"; } ?></p>
    <p><span class="error"><b>Invalid login name or password!</b> &nbsp;Please try again.</span></p></td>
   </tr>
   </form>
  </table>  
 </td>
</tr>
</table>

</body>
</html>



This is simply an HTML page where the user will be recriected to if they type the incorrect password.

Now we will call this page invalidlogin.php and save it to the "edit folder" too

CHECK UP TIME!
Now, just to check that we are on track, you should have the following folders and files

>news
...edit
......login.php
......protect.php
......invalidlogin.php

If this is how your strcutrue looks like, you're on the right track! biggrin.gif

STEP 5:
Now, we will create a page that the user will be led to when they log out:

CODE


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Your news system</title>
</head>

<body>
 <p>You have logged out.<p>Click <a href="index.php">here</a> to login again.</p></td>
</body>
</html>



Again, this is just a simple HTML page which shows the user that they have logged out. Call this page [B]logout.php and save it to your "edit" folder.[/B]

STEP 6:
Now, here's an easy part, create a blank text file and call it "news.txt.", save this to your "edit folder". This textfile is the place where your news will be stored and saved to.

STEP 7:
Here begins where the news will come alive, use the following code:

CODE


<? include("protect.php"); ?>

<?php
$data_file='news.txt';
$changes='';

if(isset($contents)) {
     $archive=fopen($data_file,'r+');
     flock($archive,2);
     ftruncate($archive,0);
     fputs($archive,$contents);
     flock($archive,3);
     fclose($archive);
     unset($contents);
    $changes='<b style="color:#ff6600">Changes made!</b>&nbsp;&nbsp;&raquo;&nbsp;&nbsp;<a href="../">View Changes</a><br />';
}

function getfile($filename) {
  $fd = fopen($filename, "rb");
  $content = fread($fd, filesize($filename));
 fclose($fd);
  return $content;
}

$data=getfile($data_file);
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Your news system</title>

</head>

<body>

<table style="height: 100%; text-align: center; width: 90%">
<tr>
 
   <td style="height: 65px; padding: 10px 0px 0px 10px; text-align: left">Login
     succesful! - Please edit your news.</td>
</tr>
<script language="Javascript" type="text/javascript">
<!--
function view() {
q=open("","l"," status=0,toolbar=0,width=560,height=420,resizable=1,menubar=0,location=0");
q.document.open();
q.document.write('<html><head><title>News/Content Publisher - Preview Window</title>');fs
q.document.write('</head><body><table bgcolor="#ffffff" width="100%" height="100%"><tr valign="top"><td style="color: #666666; line-height: 16px; padding: 10px 20px 0px 20px;">');
q.document.write(document.forms[0].contents.value);
q.document.write('</td></tr>');
q.document.write('<tr valign="bottom"><td align="center" style="line-height: 16px;"><a href="javascript:window.close();"  onmouseover="window.status = \'Close Window\'; return true;" onmouseout="window.status = \'\'; return true;">Close Window</a>');
q.document.write('</td></tr></table>');
q.document.write('</body></html>');
q.document.close();
}

//-->
</script>
<form name="editform" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>" onsubmit="if(q&&!q.closed)q.close();return true">
<tr>
 <td style="vertical-align: middle">
 <div align="center"><fieldset style="border: 1px solid #CCC; width: 50%"><legend style="margin-left: 8px">&nbsp;Edit News/Events Information Here:&nbsp;</legend>
 <div style="padding: 20px">
 <div align="right"><a href="<? echo $PHP_SELF ?>?action=logout"><img src="/art/logout.gif" alt="Log Out" width="17" height="16" border="0" align="absmiddle"> Log Out</a></div>
 <?php echo $changes; ?>
 <p><input style="margin:0px;" type="button" value="Bold" onClick="editform.contents.value+='<b></b>'"> <input type="button" value="Italic" onClick="editform.contents.value+='<i></i>'"> <input type="button" value="Space" onClick="editform.contents.value+='<br>'"> <input type="button" value="Dbl Space" onClick="editform.contents.value+='<p>'"> <input type="button" value="Quote" onClick="editform.contents.value+='&acute;'"> <input type="button" value="Dbl Quote" onClick="editform.contents.value+='&ldquo;&rdquo;'"><br>
 <textarea name="contents" rows="20" cols="50" tabindex="2"><?php echo $data;?></textarea><br />
 <input class="send" style="margin:0px;" type="button" onClick="view()" value="Preview" />&nbsp; &nbsp;<input class="send" type="submit" name="submitdata" value="Submit" />&nbsp; &nbsp;<input class="reset" type="reset" name="resetdata" value="Erase Changed" /></p></div></fieldset></div></td>
</tr>
</form>
</table>

</body>
</html>


I know it's a mouth full, but i will do the best to explin it. At the very top, you see the protect.php include function, this means that only autoixed users which know the username and password can enter, otherwise, they will be recitected to the login page. This include function ensures that your news system is safe. The rest of the php tells the server to write and send the information to the news.txt file. Now, the rest of the HTML is the area that you will be able to edit your news.

Now, save this as index.php in the "edit folder"

We're almost done!

CHECK UP 2!
Just to see that you are on track, you should have the following files in your "edit "folder.

index.php
protect.php
login.php
invalidlogin.php
logout.php
news.txt

STEP 8:
We're now done the hardest part of the script, it's all smooth sailing from here. Moing away from the "edit" folder, we will now go to the root directory, meaning to the "news" folder. We will now create the page which will display all of the information that you have posted. Put in the following code.

CODE


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Your News Login system</title>
</head>

<body>

       <? include("edit/news.txt") ?>

</body>
</html>


All it is a simple HTML page that will do the PHP include function, which in turn places the information into an HTML page.

biggrin.gif YOU'RE FINISHED! biggrin.gif

Now uplaod all the files to your server, and go to http://yoursite.com/news/edit/index.php, this will lead you to the login page, login with your username and password, and bingo! you will get in. You will have a text box along with other functions that will let you add text to it, and it's also HTML compatible, so you can paste HTML and it will be rendered out as HTML. After you have posted, go to http://yoursite.com/news/index.php, and voila! your news!

If you want to have multiple pages display that informaiton, simply use the include function in PHP like so:

<? include("edit/news.txt") ?>

I highly recommend adding in sytle sheets to make it suit your taste.

I know it's a long tutorial, but hopefully, you've learned how to make a good sizeable news system, further more, you can enrich it by adding in CSS Style sheets, something that I haven't done here. feel free to modify this script, but give me some credit wink.gif.

- whyme (hands and fingers are sooooo tired)

If you have any questions problems or difficulite,s don't hesitate to PM me or poast of this thread
*




...Amazing. Though, I think I'll stick with cutenews since it has a commenting system. If you come up with one, maybe I'll use yours :>

Reply

Latest Entries

Joshthegreat
I think that would fix it yes. Must be what to do since I know thats how you fix something on this shoutbox. I'll try it on index.php too because the same propblem is happening to me.

Reply

chiclete
I've done all right (I guess) and I'm receiving this error while trying to log in:
CODE
Not Found
The requested URL /news/edit/< was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
Apache/1.3.33 Server at www.chicletedesign.trap17.com Port 80


I can accesse /edit/index.php and put in my username and password (I've already change to what I want) but when I click Login it gives me this error. What can I do?
P.S.:My CHMOD on this page is 777 should I go back to 755?

Reply

Joshthegreat
Read the the main tutorial and you should have seen This Link

So am I right in saying that no one knows how to sort out my problem?

Reply

NotoriousZach
STOP QUOTING THE CODE PART.........JESUS CHRIST LOL........Anyways, if anyone has used this post a link here id really like to check it out.

Reply

Joshthegreat
Ok, sorry. Right, I have uploaded all of the news files.
Now, when I open up index.php and type in my user name and pasword and click on login. It links me straight to a page the says, 'The page cannot be found'.
That's my problem.

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Pages: 1, 2, 3
Recent Queries:-
  1. news system php tutorial - 108.53 hr back. (2)
Similar Topics

Keywords : creating, php, news, system

  1. News System (cms)
    .::DeadMan::. Paraphrased by alex1985 (4)
  2. Getting Started With Mysql
    creating tables and insert data into them. (2)
    Hi in this tutorial you will learn how to create tables and insert items into them. First steps are
    to create the database - go into your cpanel and mysql databases, from there make an account and a
    database and then attach them together with all priviliges, call the database test and the account
    admin, with the pw as pass - or any other password. We need to connect to the database so first in
    your php file (probably named index.php) - this is how to do it. CODE
    mysql_connect("localhost", "admin", "pass") or
    die(mysql_error(&....
  3. Creating Navigation For Html Websites
    Have a common navigation menu for the whole website! (12)
    Pre-requisite: HTML, inline frame tags 1 Attachment(.zip) included. Updates : 29-12-07: Doctype
    added in example files (Advised by jlhaslip) Designing a whole website takes a lot of planning
    and organization. Designing a proper navigation system is a basic step in building your website. If
    you are developing webpages in html you would have observed that as you go on creating pages it
    becomes difficult to maintain the links to the pages. This article will guide you in developing a
    common navigation menu for your website. It describes three ways, so if you don'....
  4. Creating A Resume
    10 Tips For Making A Resume (1)
    I've been working on my Resume for months now. Here is a summary of what I've learned: 1.
    Avoid referring to yourself via 1st person or 3rd person terms. Rather than saying "I started this
    job in" just say "Began job in"... Employers expect Resumes to be professional and avoid reference
    to oneself; and instead speaking in an impersonal tone that presents
    achievements/skills/experience/education without personalization. Avoid words like "I", "my", "he",
    "she", etc. Leave out personal pronouns and only use the action words/verbs. This also includes
    your Ob....
  5. Programming In Glut (lesson 4)
    Creating 3D objects (0)
    Lesson 4 of 6. I hope you are enjoying them /laugh.gif" style="vertical-align:middle"
    emoid=":lol:" border="0" alt="laugh.gif" /> . QUOTE Hello, in this tutorial we will be creating
    a 3D pyramid. We are building this tutorial from Lesson 3, but I took out the 2D objects and placed
    a 3D pyramid in there instead. The 3rd axis for drawing can be a litle confusing, but after you get
    the hand of it you'll do fine. Now when you are setting a 3D vertex just remember that the
    camera is on the positive end of the z axis. So things that have a more positive z axis va....
  6. Programming In Glut (lesson 1)
    Creating a windwo (0)
    This is the first of six lessons I am transferring from Astahost for programming in GLUT, and after
    the six I hope to make more, I hope you enjoy. QUOTE Hello, I'm starting a series on how to
    program in OpenGL using the OpenGL Utility Toolkit, a.k.a. GLUT. I chose GLUT because it is quick
    and easy to write, and very easy to learn. In this tutorial I am going to teach you how to create a
    basic window which we will build off of in later tutorials. Throughout the tutorial I will leave
    notes to let you know what each command does, and how you can modify it to fit....
  7. Tutorial: Creating Custom Icons For Devices
    Give that device a great icon every time you plug it in! (0)
    Ok for this tutorial I will use the PSP as an example of the device, this should work for every
    device. (THIS WILL NOT HARM ANYTHING AT ALL!) First off, open notepad and type in:
    ICON=ICONE.ICO Save that as AUTORUN.inf Now, find a picture you like.. make sure its dimensions
    are 16X16 pixels. Put it in the main folder of the device, for example, my psp is located at
    F:\, i would type in F:\ to the adress bar and put the picture in that folder, as it is
    the folder your computer automatically reads, anyways, put your picture in there and name it: ICO....
  8. Creating A Timer Program
    Using Visual Basic 2005 (8)
    This tutorial will explain how to create a basic timer using Visual Basic Express 2005. If you
    don't have it, it's free and you can dowload it from Microsoft's website. All you need
    is a few minutes to sit down and read this and a version of Visual Basic. OK, so what will this
    timer actually do? Well, you are able to enter a number of minutes and a message, and then click a
    button. Once the timer is up, your message pops up and you are reminded! So, basically it's
    a little reminder system. I use it to remind me when TV programmes start, when I have to....
  9. Creating A Simple Image Viewer
    Using Visual Basic 2005 Express Edition (3)
    I downloaded Microsoft's Visual Studio Express suite a few months ago, but only recently got
    around to installing it. I have been practising with Visual Basic and making some rather basic
    programs and utilities, but they contain most of the basic concepts. This tutorial will explain how
    to create a basic image viewer, and I will try to explain each step from beginning to end as clear
    as I can. To start you will need: Microsoft Visual Studio About 10-20 minutes free time OK,
    first open up the Visual Basic part of the Studio. I am using the 2005 Express version, so....
  10. Fusion News Set-up/help If You Need It
    Fusion news set-up/help (0)
    Well this was my first choice..but i found a diff one..i had a bit of difficulty installing
    it..maybe it will help someone!! first off your site must be able to have PHP files 1) You
    should download the fusion news files located Here 2) extract all the files in it somwhere on
    your computer. 3) upload ONLY THE FILE CALLED "UPLOAD" to your site in a directory such as news
    etc.. 4) CHMOD ALL of the files to 777 ( if you do not know how to CHMOD please see the tutorial
    form for a tutorial on it or see the bottom of this post) 5) once everything is uploaded....
  11. Getting Started With Amfphp And Rias
    first steps in creating RIAs (0)
    AMFPHP in a short way is a library of php files that let u manage in JUST ONE FILE what u would do
    in many files like for example queries to mysql. So u can have tons of queries to mysql and all of
    them in just ONE FILE! so what is a RIA? a RIA is a Rich Internet Application commonly given
    to flash applications, not the animations or presentations we see daily on the internet but very
    useful and cool programs made in flash. the fisrt step u need to take is to download the AMFPHP
    library directly from its site at www.amfphp.org, in some free hosted sites the latest....
  12. Delete Files And Directories Using Php
    following up from creating and writing (7)
    How To Delete Files and Directories follow up from creating them Hello all and
    welcome to my second tutorial involving file management. In my previous tutorial , I explained how
    to create, write and read files. In this tutorial I'll explain how to remove the files and
    directories you took so long to create. I did not explain last time how to create directories as I
    did not know, now I do, you can use the mkdir() function. Now with this tutorial.... Removing
    Files Removing files can easily be done with the unlink() function: CODE <? un....
  13. Creating Rollovers With Buttons
    Short & simple javascript tutorial that shows you how. (2)
    Javascript in action can render some very neat visual effects, which can make your website more
    appealing, and sometimes even easier to navigate. Among the most common effects are the
    'button' effect, and the mouseover effect. The buttons are very common, of course; if
    nowhere else, most of us have seen them at the end of forms (Click the 'submit' button to
    proceed...). The basic idea is to have a 'depressible' object, which can give you the
    illusion that you're 'pressing' it when you click it. The rollover effect causes
    something to h....
  14. Creating Your Own Icon
    (23)
    It is easy to create your own icon, just pick a bitmap (.bmp) file and change its extension to .ico.
    To do so, open the Windows Explorer, click on the View menu (or Tools in WinMe), click Folder
    Options, click View tab, remove the check on the "Hide file extensions for known files types"
    option, and then click OK. Select a bitmap file, press F2 key, and then change its extension to
    .ico. Have fun learning:)....
  15. Creating Personal Alarm
    To remind you something (2)
    Creating Personal Alarm This personal alarm is very useful to remind you something or anything you
    would like it to do. Use Task Scheduler application to create your personal alarm. First, click on
    Start -> Settings -> Control Panel -> Scheduled Tasks. Now click on the Add Scheduled Task wizard
    in the Task Scheduler folder. Click Next, click the Browse button, and then select your favorite
    sound files (WAV/MP3/MIDI). Set the file to open as the task daily. Set it at the top of the hour
    every day, open up its advanced properties. On the Schedule tab press the Advance....
  16. A Guide To Css And Creating A Stylesheet
    (15)
    Table of Contents: I. Introduction II. Starting your stylesheet --A. Starting syntax with
    font-family --B. Defining classes --C. Using classes III. The STYLE tag IV. Comments in CSS V. The
    "a" tag VI. A quick list of common attributes VII. Notes --A. Universal classes --B. Grouping --C.
    Multiple instances VIII. Finding other attributes IX. Closing I. Introduction Firstly, to begin
    using a stylesheet, you must have one. Open up your text editor and save as (something).css. I know
    NotePad doesn't need quotes for a stylesheet, but I'm not sure about other progr....

    1. Looking for creating, php, news, system

Searching Video's for creating, php, news, system