Archive for January, 2008

817Chapter 43Weblogs$title_msg = $entry_date; $header_msg = Weblog entry (Web host 4 life)

Thursday, January 31st, 2008

817Chapter 43Weblogs$title_msg = $entry_date; $header_msg = Weblog entry for $entry_date ; include_once( header.inc ); echo $flipbar; // Include the specified entry textecho $entry; echo $flipbar; include_once( footer.inc ); ?> Changes and AdditionsThings you might want to immediately change, add, or alter in this codebase include: .Alter colors, styles, layout. .Change frequency of expected update (weekly, monthly). .Change to calendar-based navigation rather than Next/Previous links. .Change to topic-based rather than date-based navigation. .Stop automatic entry changeover by date. .Allow future entries in database. .Allow multiple authors/editors with different permissions. Besides a personal Weblog, you could use this code for any simple, chronological note taking, such as: .A vacation journal .A project log .The story of your vast weight loss through heroic diet and exercise .A chronicle of your pregnancy and baby s developmentSummaryAlthough it s handy for small, standalone projects such as polls, PHP s most impressive use isin developing complete data-driven content sites. The easiest such site to develop is the per- sonal Weblog. We encourage every PHP user to keep one, if only as a handy testbed for newideas and techniques. If you wish, you can store your data in ordinary text files, using PHP to plug these files into atemplate based on a criterion such as date. This will save a certain amount of formatting- related repetition at the cost of somewhat decreased security. Far better in every way is tokeep the data in a database.
Looking for affordable and reliable webhost to host and run your business application? Then look no more and go to servlet web hosting services.

816Part VCase StudiesListing (Web hosting support) 43-16(continued) $query2 = SELECT date

Wednesday, January 30th, 2008

816Part VCase StudiesListing 43-16(continued) $query2 = SELECT date FROM mylog WHERE ID = $prev_ID ; $result2 = mysql_query($query2); $prevdate_row = mysql_fetch_array($result2); $prev_date = $prevdate_row[0]; } else { $prev_date = ; } // Get next date for Cases 2 and 3if ($entry_ID != $last_ID) { $next_ID = $entry_ID + 1; $query3 = SELECT date FROM mylog WHERE ID = $next_ID ; $result3 = mysql_query($query3); $nextdate_row = mysql_fetch_array($result3); $next_date = $nextdate_row[0]; } else { $next_date = ; } // Assemble the Previous/Next links// Case 2if ($next_date != && $prev_date != ) { $flipbar = n

<– Previous Next –>
n ; } // Case 3elseif ($next_date != && $prev_date == ) { $flipbar = n

Next –>

n ; } // Case 4elseif($next_date == && $prev_date != ) { $flipbar = n

<– Previous

n ; } // ——————— // NOW ASSEMBLE THE PAGE// ———————
Searching for affordable and reliable webhost to host and run your web applications? Go to our java web server services and you will be pleased.

815Chapter 43WeblogsListing 43-16: Main database Weblog (Web host forum) template (db_weblog.php)

Wednesday, January 30th, 2008

815Chapter 43WeblogsListing 43-16: Main database Weblog template (db_weblog.php) 0) { $entry_row = mysql_fetch_array($result1); $entry_ID = $entry_row[0]; $entry_date = $entry_row[1]; $entry = stripslashes($entry_row[2]); } else { // If someone enters a bad date, redirect to homepageheader( Location: /index.php ); } // Get previous date for Cases 2 and 4if ($entry_ID > 1) { $prev_ID = $entry_ID - 1; Continued49
Note: If you are looking for cheap and reliable webhost to host and run your mysql application check mysql web server services.

Web hosting control panel - 814Part VCase StudiesListing 43-15(continued) } else { echo

Tuesday, January 29th, 2008

814Part VCase StudiesListing 43-15(continued) } else { echo There was a problem inserting your text. ; exit; } } else { // Show the form with the appropriate entry filled in$php_self = $_SERVER[ PHP_SELF ]; $test_password = $_POST[ test_password ]; $edit_date = $_POST[ edit_date ]; $query = SELECT blogtext FROM mylogWHERE date = $edit_date ; $result = mysql_query($query); if (mysql_num_rows($result) == 0) { echo No entry matches that date ; exit; } $entry_row = mysql_fetch_array($result); // When you get text from a SQL database, // you may need to strip backslashes from single-quotes. $blogtext = stripslashes($entry_row[0]); $form_str = <<< EOFORMSTR Weblog data edit screen

Text:

EOFORMSTR; echo $form_str; } } else { mail( me@localhost , Weblog snoop , Someone from$REMOTE_ADDR is trying to get into your weblog entry screen. ); } ?>
We highly recommend you visit web and email hosting services if you need stable and cheap web hosting platform for your web applications.

813Chapter 43WeblogsVALUE= $test_username > EOFORMSTR; echo $form_str; } } else (Web hosting account)

Monday, January 28th, 2008

813Chapter 43WeblogsVALUE= $test_username >

EOFORMSTR; echo $form_str; } } else { mail( me@localhost , Weblog snoop , Someone from$REMOTE_ADDR is trying to get into your weblog entry screen. ); } ?> Listing 43-15:Database Weblog data edit screen (db_logedit.php) We recommend cheap and reliable webhost to host and run your web applications: Coldfusion Web Hosting services.

812Part VCase StudiesListing 43-14:Database Weblog data (Cheapest web hosting) entry screen

Sunday, January 27th, 2008

812Part VCase StudiesListing 43-14:Database Weblog data entry screen (db_logentry.php) Weblog data entry screen

Text:

In case you need quality webspace to host and run your web applications, try our personal web hosting services.

811Chapter 43Weblogs$result = mysql_query($query); // Since we re not (Web site templates)

Sunday, January 27th, 2008

811Chapter 43Weblogs$result = mysql_query($query); // Since we re not using the standard MySQL// date format, store date as an integer$query2 = CREATE TABLE mylog (ID SMALLINT NOT NULLAUTO_INCREMENT PRIMARY KEY, date INT(8), blogtext TEXT) ; $result2 = mysql_query($query2); mysql_close(); if ($result > 0 && $result2 > 0) { echo ( Successfully created tables
n ); } else { echo ( Unable to create tables. ); } } else { echo ( Unable to create database ); } ?> After creating the database as the MySQL root user, you can grant a more restrictive permis- sions package to some other MySQL user and then run the following scripts as that user. Listing 43-13: Database Weblog login screen (db_login.php) Weblog login screen

Use this login to add a new entry.

USERNAME:

PASSWORD:

Use this login to edit a previous entry.

USERNAME:

PASSWORD:

EDIT DATE:


Visit our web design programs services for an affordable and reliable webhost to suit all your needs.

Fedora web server - 810Part VCase Studiesevery day now you can do it

Saturday, January 26th, 2008

810Part VCase Studiesevery day now you can do it as frequently or infrequently as you want without having abunch of blank pages. Although they have similar names and functions, the files shown in the following listings are somewhat different from the preceding set. You also need a script called weblog_db_ create.phpto create the database (unless you d rather do it using the MySQL command-linetool); if you want to edit previous entries, you have to add a script called db_logedit.php. Most of these scripts will not fail gracefully if the database has no data in it, particularly user- names and passwords in the logintable. Because the whole thing is designed to be non- functional until you enter at least one entry into these tables, and we want you to focus onthe main functionality rather than error-checking, there didn t seem to be a lot of point intesting for empty tables. If it s important to you, feel free to alter the code that follows. Listings 43-11 through 43-16 are the files you need for a database-enabled Weblog. Listing 43-11:Included database password file (db_password.inc) Put db_password.incsomewhere outside your Web tree, such as in your home directory. This will prevent your database passwords from being visible in a Web page or available toanyone who can get into your Web directory. Listing 43-12:Database creation script (weblog_db_create.php) 0) { echo ( Successfully created database.
n ); mysql_select_db( weblogs ); $query = CREATE TABLE login (ID SMALLINT NOT NULLAUTO_INCREMENT PRIMARY KEY, username VARCHAR(20), passwordVARCHAR(20)) ; Caution49
We recommend you use shared web hosting services, because many users agree that it is cheap, reliable and customer-satisfying webhost.

Web hosting resellers - 809Chapter 43Weblogs Listing 43-9:Included password file (password.inc) Listing

Saturday, January 26th, 2008

809Chapter 43Weblogs

Listing 43-9:Included password file (password.inc) Listing 43-10:Weblog data entry script (logentry.php) -1) { print( Weblog entry for $date written to disk. ); } elseif ($try_entry == -1) { print( Weblog entry write failed. ); } } else { mail( me@localhost , Weblog snoop alert , Someone from$REMOTE_ADDR is trying to get into your weblog entryhandler. ); } ?> Adding Database ConnectivityOnce you see how HTTP data entry is effected using the PHP file writing function, it s a shortstep to keeping your entries in a database rather than in discrete text files. This is neater important as your site grows and considerably more secure. Furthermore, you can give dif- ferent database permissions to different users, enabling multiple content developers to workon the site safely. By using a database, you get three more bonuses. First, you can write a script to edit yourprevious journal entries using a Web form, as well as just enter them. Even better, you cannow classify and search your entries. And finally, you are no longer required to have entries49
Looking for affordable and reliable webhost to host and run your business application? Then look no more and go to servlet web hosting services.

Affordable web hosting - 808Part VCase StudiesAdding an HTML Editing ToolThis simple

Friday, January 25th, 2008

808Part VCase StudiesAdding an HTML Editing ToolThis simple Weblog is quite adequate for many purposes, but it has one big disadvantage: You can t write up your daily entries using the Web itself. Instead, you must create each entryusing a text editor like emacsor Notepad and save it to your Web server s docroot. This canbe a significant issue over time, especially if you are not allowed telnet/ssh/FTP access toyour server or aren t comfortable with the process. HTTP is the next logical step for manyusers, and is probably no less unsafe than using FTP. This process has one big problem: You need to give read/write permissions to the HTTP user(usually Nobody) in a particular directory. This is an inherently insecure process, and we donot recommend it in the long run. We ll describe the HTTP tools here so that you can becomecomfortable with the new aspects before moving on to a better solution, which is using adatabase instead of separate include()files for each entry. We ll also try to keep the secu- rity problems to a minimum, employing a password and letting you send mail to yourself if an unauthorized person tries to log in. The files you need for an HTML-based file-writing tool are: .login.php .logentry.php .logentry_handler.php .password.incPut password.incin a directory outside the Web tree, such as /home/htmluser. This willensure that your passwords cannot be read via the Web without being processed by PHPfirst. The directory must be world-executable and the document must be readable by thehttpduser (Nobody). If you have root access on this server, you could chownit to belong tothe httpduser; if not, you may have to make the file world-readable, which is a securitybreach. Be sure to use a password different from your system user password, just in case it s compromised. Listings 43-8 through 43-10 are the files you need for an HTML form to edit Weblog entries. Listing 43-8:Weblog entry login screen (login.php) Weblog login screen

Supply a username and password.

USERNAME:

PASSWORD:

BLOG ENTRY: