whyme 0 Report post Posted February 19, 2005 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://forums.xisto.com/no_longer_exists/. 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 . STEP 1: Now create a "edit" folder, now you should have two folders, like so: news ...edit now, let's start some PHP STEP 2: Create a PHP page and put in the following 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 ?>?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. <?$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: <!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> 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! STEP 5: Now, we will create a page that the user will be led to when they log out: <!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 logout.php and save it to your "edit" folder. 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: <? 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> » <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"> Edit News/Events Information Here: </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+='´'"> <input type="button" value="Dbl Quote" onClick="editform.contents.value+='“”'"><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" /> <input class="send" type="submit" name="submitdata" value="Submit" /> <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. <!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. YOU'RE FINISHED! Now uplaod all the files to your server, and go to http://ww38.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://ww38.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 . - 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 Share this post Link to post Share on other sites
thugnature 0 Report post Posted February 19, 2005 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. Share this post Link to post Share on other sites
Serious Gamer 0 Report post Posted February 19, 2005 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://forums.xisto.com/no_longer_exists/. 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 . STEP 1: Now create a "edit" folder, now you should have two folders, like so: news ...edit now, let's start some PHP STEP 2: Create a PHP page and put in the following 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 ?>?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. <?$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: <!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> 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! STEP 5: Now, we will create a page that the user will be led to when they log out: <!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 logout.php and save it to your "edit" folder. 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: <? 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> » <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"> Edit News/Events Information Here: </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+='´'"> <input type="button" value="Dbl Quote" onClick="editform.contents.value+='“”'"><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" /> <input class="send" type="submit" name="submitdata" value="Submit" /> <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. <!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. YOU'RE FINISHED! Now uplaod all the files to your server, and go to http://ww38.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://ww38.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 . - 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 51880[/snapback] wow it seems ur pretty good at this eh Share this post Link to post Share on other sites
chiclete 0 Report post Posted February 19, 2005 "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 Share this post Link to post Share on other sites
karlo 0 Report post Posted February 19, 2005 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://forums.xisto.com/no_longer_exists/. 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 . STEP 1: Now create a "edit" folder, now you should have two folders, like so: news ...edit now, let's start some PHP STEP 2: Create a PHP page and put in the following 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 ?>?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. <?$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: <!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> 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! STEP 5: Now, we will create a page that the user will be led to when they log out: <!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 logout.php and save it to your "edit" folder. 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: <? 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> » <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"> Edit News/Events Information Here: </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+='´'"> <input type="button" value="Dbl Quote" onClick="editform.contents.value+='“”'"><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" /> <input class="send" type="submit" name="submitdata" value="Submit" /> <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. <!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. YOU'RE FINISHED! Now uplaod all the files to your server, and go to http://ww38.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://ww38.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 . - 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 51880[/snapback] 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? Share this post Link to post Share on other sites
mahesh2k 0 Report post Posted February 19, 2005 nice tutorial well i guess i have to make my hands dirty with php now....;)keep posting... Share this post Link to post Share on other sites
karlo 0 Report post Posted February 19, 2005 nice tutorial well i guess i have to make my hands dirty with php now.... keep posting... 51998[/snapback] Make your hands dirty in PHP? How? Are you really a PHP expert? Share this post Link to post Share on other sites
whyme 0 Report post Posted February 19, 2005 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. Share this post Link to post Share on other sites
eskick 0 Report post Posted February 19, 2005 hey seems prety gud but where did you get it from a modification or somthing? Share this post Link to post Share on other sites
shadow skazi 0 Report post Posted February 20, 2005 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://forums.xisto.com/no_longer_exists/. 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 . STEP 1: Now create a "edit" folder, now you should have two folders, like so: news ...edit now, let's start some PHP STEP 2: Create a PHP page and put in the following 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 ?>?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. <?$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: <!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> 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! STEP 5: Now, we will create a page that the user will be led to when they log out: <!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 logout.php and save it to your "edit" folder. 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: <? 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> » <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"> Edit News/Events Information Here: </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+='´'"> <input type="button" value="Dbl Quote" onClick="editform.contents.value+='“”'"><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" /> <input class="send" type="submit" name="submitdata" value="Submit" /> <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. <!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. YOU'RE FINISHED! Now uplaod all the files to your server, and go to http://ww38.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://ww38.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 . - 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 51880[/snapback] ...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 :> Share this post Link to post Share on other sites
thebluekirby 0 Report post Posted February 24, 2005 i don't mean to barge in, but don't do quotes of the first post because the scrolling can get annoying >.<that's a really good script, I was looking for something like that Share this post Link to post Share on other sites
Joshthegreat 0 Report post Posted March 2, 2005 I wonder if anyone can explain to me why when I upload index.php and I try to access it, it just comes up with a download box of the index.php file? Share this post Link to post Share on other sites
Joshthegreat 0 Report post Posted March 2, 2005 Really sorry about the double post but I this alos happens with protect.php. I really don't have much knowledge of php at all, forgive me for the double post. There doesnt seem to be an edit tag on previous posts.Thanks, Share this post Link to post Share on other sites
HmmZ 0 Report post Posted March 2, 2005 Great tutorial, just what I was looking for, but I do have 1 question, is the news/edit/index.php safe enough to let other users use it? If it is, I can turn it easily into a review submission system, wich would be great I'm asking this since you point out that you (the admin) can go there and easily submit news, not clearly stating that users could go there too (of course, news is usually not formatted by users themself, would be a chaos ) Share this post Link to post Share on other sites
Oblivion 9999 0 Report post Posted March 2, 2005 Quite a lot of people decided to quote the first post, that was a lotta scrolling...anyway, that was amaxzing! Thats a pretty good tutorial, from just that I know quite a bit now, it's not too hard when you get used to it and it seem rather easy after a while, sorta like when I was learning html. I've been searching for a php tutorial for ages now and you just put any info I wanted to know as a beginner right in front of me. Thanks Share this post Link to post Share on other sites