Fish Inurl GuestBook Php Form. Guestbook on PHP
In this lesson, we will create a guestbook on PHP using AJAX. Entries will be stored in the database. The table will contain the following information: the sender's name, email address, IP address and date-time of the last entry. JQuery will be used (for the implementation of AJAX). Easy spam protection will also be implemented - you can post no more than one record every 10 minutes.
Step 1. SQL
To work our application, you need to create a table:
Create Table If Not EXists `S178_Guestbook` (Int (10) unsigned not null auto_increment,` name` Varchar (255) Default "", `email` Varchar (255) Default", `Description` Varchar (255) default "", `When` Int (11) Not Null Default" 0 ",` IP` Varchar (20) Default Null, Primary Key (`ID`)) Engine \u003d Myisam Default Charset \u003d UTF8;
Step 2. PHP.
The main file will contain the following code:
guestBook.php.
\u003d ") \u003d\u003d 1) error_reporting (e_all & ~ e_notice & ~ e_deprecated); else error_reporting (e_all & ~ e_notice); Require_ONCE (" classes / cmysql.php "); // including service class to work with database // Get IP visitor function getvisitorip () ($ ip \u003d "0.0.0.0"; if ((iSset ($ _ server ["http_x_forwarded_for"])) && (! Empty ($ _ server ["http_x_forwarded_for"]))) ($ ip \u003d $ _Server ["http_x_forwarded_for"];) elseif ((ISSET ($ _ Server ["http_client_ip"])) && (! Empty ($ _ server ["http_client_ip"]))) ($ ip \u003d Explode (".", $ _ Server [ "Http_client_ip"]); $ ip \u003d $ ip. "." $ Ip. "." $ Ip. "." $ Ip;) elseif ((! Isset ($ _ Server ["http_x_forward_for"])) | | (Empty ($ _ server ["http_x_forwarded_for"]))) (if ((! isset ($ _ server ["http_client_ip"])) && (Empty ($ _ Server ["http_client_ip"]))) ($ ip \u003d $ _Server ["REMOTE_ADDR"];)) Return $ ip;) // Get the latest entries in the guest book Function GetLastRecords ($ ilimit \u003d 3) ($ SRECORDS \u003d ""; $ ARECORDS \u003d $ Globals ["MySQL"] -\u003e GetAll ( "SELECT * from` s178_guestbook` Order by ID` DESC L Imit ($ ilimit) "); Foreach ($ ARECORDS AS $ i \u003d\u003e $ Ainfo) ($ swhen \u003d date ("f j, y h: i", $ Ainfo ["WHEN"]); $ srecords. \u003d<< ($ Ainfo ["Description"])