
| Modding your wii console | Automatic Theme Changer in PHP |
| Submitted On: Tuesday, November 10, 2009 at 8:21:52 AM |
Toasty Please login to rate this submission. Link to this Submission Blog and Forum Link HTML link Facebook / Pagereaders
|
DO NOT ATTEMPT: Articles provided here are for INFORMATIONAL PURPOSES ONLY. DO NOT undertake any project based upon any information obtained on the internet, including this website. We are not responsible for, nor do we assume any liability for, damages resulting from the use of any information on this site. Please read the Legal page for more information. PHP Text Based Article System Contains complete comments. <?PHP /*-------------------------------------------------------------------------- | These lines will get the information from the URL, for handling the data. | | There is some filtering here to avoid some kinds of attacks. | | To reduce processing time, the POST variables are only handled when the | | script is in "post" mode. | --------------------------------------------------------------------------*/ $mode = $_GET['mode']; $articleID = preg_replace("/[^0-9]/i", "", $_GET['id']); /*-------------------------------------------------------------------------- | SWITCH selects the variable that CASE will use. Here, we're using CASE to | | determine what mode we're in. This allows us to use only one script to | | handle an entire system -- easy for updates, and cleaner for your htdocs | | folder. --------------------------------------------------------------------------*/ SWITCH ($mode) { CASE "add": { /*-------------------------------------------------------------------------- | Here, we'll generate the form that people will create an article in. | | The action= portion tells the script to point to itself, but in post mode | | This allows you to name your file whatever you like. | --------------------------------------------------------------------------*/ echo " <form action='" . $_SERVER['PHP_SELF'] . "?mode=post' method='post'> <label>Title:</label> <input type='text' name='title' /><br /> <label>Author:</label> <input type='text' name='author' /><br /> <label>Body:</label> <textarea cols='25' rows=20' name='body'></textarea><br /><br /> <input type='submit' value='Add Article' /> </form>"; break; } CASE "view": { /*-------------------------------------------------------------------------- | Here, the script will open the article, and do some basic formatting to | | the layout. Also convert the s to <br />s. | --------------------------------------------------------------------------*/ if (file_exists($articleID . ".txt")) { $file = fopen($articleID . ".txt","r"); $title = trim(fgets($file)); $author = trim(fgets($file)); $time = trim(fgets($file)); $body = str_ireplace(" ", "<br />", trim(fgets($file))); fclose($file); echo "<h1>" . $title . "</h1><hr />Posted By: " . $author . "<hr />" . $body; } else { echo "Oops! That article doesn't exist!"; } break; } CASE "post": { /*-------------------------------------------------------------------------- | This is where the code starts getting complex. Here, we're writting to a | | text file, but we have to make sure the data is safe to post. We'll start | | by cleaning out and formatting the variables first. | --------------------------------------------------------------------------*/ $title = strip_tags($_POST['title']); $author = strip_tags($_POST['author']); $body = str_replace("rn", "",str_ireplace("<br />", " ",nl2br(strip_tags($_POST['body'])))); /*-------------------------------------------------------------------------- | As you can see, the filtering for $body is the most complicated. What all | | those extra parts do, is convert "newlines" (or when you pressed enter in | | the textbox) to a pseudo-tag . This makes it safe to put into your | | text file database, because each field is seperated by an ENTER | --------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------- | Below, we're going to use a UNIX timestamp to name the text file, which | | will become the ID of the file, and help us assess the time it was posted | --------------------------------------------------------------------------*/ $posttime = time(); if (file_exists($posttime . ".txt")) { /*-------------------------------------------------------------------------- | Because we're using the timestamp as the filename, it is possible that | | two people could post at the same time. This is called a "race condition" | | and is quite a problem for programmers. You could use a random number, | | but then there's more of a risk of overwritting other files. This code | | checks to see if the file exists, and if it does, it asks the author to | | resubmit, thus giving it a new ID number due to the new timestamp. | --------------------------------------------------------------------------*/ echo "OOPS! Minor error, please hit back and try again!"; die; } /*-------------------------------------------------------------------------- | Okay, now we're going to actually write the file. As you can see, there's | | a rn at the end of each file. For Windows servers, this means "return | | carriage" and "new line"...Kinda like a typewritter. For Unix based | | servers, change it to r, and Macint...
|
||||
| Tags: PHP, Text-Based, article, system |
| Tuesday, November 10th, 2009 at 8:24:24 AM #23591 |
|
Toasty SysOp Level 40 Posts: 7,388 Submissions: 227 ![]() | Here's the source code since some BBCode here made it so this won't work correctly. |
![]() |
| Tuesday, April 27th, 2010 at 9:49:48 AM #41756 |
|
Source421 Member 'hnnggg' Level 19 Posts: 1,308 Submissions: 38 ![]() | Can you re-up that source code? Or does everything work now? |
| Tuesday, April 24th, 2012 at 7:35:46 AM #55161 |
|
ColinFiat Site Admin 'JavaScript' Level 26 Posts: 1,359 Submissions: 89 ![]() | The Year 2038 Problem is a programming error that may cause important computer software to fail before the year 2038. The event affects all software that store system time as a signed 32-bit integer. These systems interpret time as the number of seconds since Thursday January 1, 1970 and the furthest time that can be represented this way is 03:14:07 UTC on Tuesday, January 19, 2038. All times beyond this moment will wrap around and be stored internally as a negative number, which will cause these 32-bit integer systems to interpret the date as 1901, rather than 2038. This will create erroneous calculations and system failure. Most all 32-bit Unix-like systems store and manipulate time in this format, called Unix time. For this reason, the year 2038 problem is often referred to as the Unix Millennium Bug. |
![]() ![]() |