|
|
||||||
|
||||||
| Index Link To US Private Messages Archive FAQ RSS | ||||||
| Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome. |
Share Thread: & Tags
|
||||
|
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
||||
|
Why reinvent the wheel?
config.php <?php ini_set('include_path',ini_get('include_path') . '../SPLIB:' . '../pear:'); ?> location: ../config [*] Connection to the MySQL database. connection.php <?php require_once('../config/config.php'); // Configuration file // Include MySQL class require_once('Database/MySQL.php'); // In SPLIB $host='db.name.com'; // Hostname of MySQL server $dbUser='Your user name'; // Username for MySQL $dbPass='your password'; // Password for user $dbName='Name of SQL DB'; // Database name // Instantiate MySQL connection $db=& new MySQL($host,$dbUser,$dbPass,$dbName); ?> location: ../connection Only for testing. Hide it in your applications. [*] SQL text files imported to MySQL via phpMyAdmin. menu.sql # phpMyAdmin MySQL-Dump # version 2.3.0-rc3 # http://phpwizard.net/phpMyAdmin/ # http://www.phpmyadmin.net/ (download page) # # Host: localhost # Generation Time: Sep 21, 2003 at 11:43 AM # Server version: 4.00.00 # PHP Version: 4.3.2 # Database : `sitepoint` # -------------------------------------------------------- # # Table structure for table `menu` # CREATE TABLE menu ( menu_id int(11) NOT NULL auto_increment, parent_id int(11) NOT NULL default '0', name varchar(255) NOT NULL default '', description text NOT NULL, location varchar(255) NOT NULL default '', PRIMARY KEY (menu_id), UNIQUE KEY location (location) ) TYPE=MyISAM; # # Dumping data for table `menu` # INSERT INTO menu VALUES (1, 0, 'Home', 'Home', '/'); INSERT INTO menu VALUES (2, 1, 'News', 'Site news', '/news/'); INSERT INTO menu VALUES (3, 1, 'About', 'About us', '/about/'); INSERT INTO menu VALUES (4, 1, 'Contact', 'Contact Us', '/contact/'); INSERT INTO menu VALUES (5, 0, 'Products', 'Product Catalog', '/products/'); INSERT INTO menu VALUES (6, 5, 'Pets', 'The Petstore', '/products/pets/'); INSERT INTO menu VALUES (7, 6, 'Birds', 'The Aviary', '/products/pets/birds/'); INSERT INTO menu VALUES (8, 6, 'Cats', 'The Lions Den', '/products/pets/cats/'); INSERT INTO menu VALUES (9, 5, 'Books', 'The Bookstore', '/products/books/'); INSERT INTO menu VALUES (10, 9, 'Fiction', 'Fiction', '/products/books/fiction/'); INSERT INTO menu VALUES (11, 9, 'Biography', 'Biographies', '/products/books/biography/'); INSERT INTO menu VALUES (12, 3, 'Folio', 'Sites', '/about/folio/'); [*] Building a simple menu loaded from the Database. File 12.php chapter 9 Vol I Fuecks modified. <?php require_once('../config/config.php'); // Modified require_once('../connection/connection.php'); // Include MySQL class require_once('Database/MySQL.php'); // SPLIB // Include Menu class require_once('UI/Menu.php'); // SPLIB // Include BreadCrumb class require_once('UI/BreadCrumb.php'); // SPLIB // Set the base location for this page relative to web root - MODIFY THIS!!! // Something curious here. // http://www.kjellbleivik.com/WebPageElements/12.php/ OK // http://www.kjellbleivik.com/WebPageElements/12.php Not OK $baseUrl='/WebPageElements/12.php'; // Important modification from Fuecks code. // Fetch the location frameelement to match against menu table $location = str_replace ($baseUrl,'',$_SERVER['PHP_SELF']); // Instantiate new BreadCrumb menu passing the MySQL connection and location $crumbs=& new BreadCrumb($db,$location); ?> <!doctype html public "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> BreadCrumb Menu Example </title> <meta http-equiv="Content-type" content="text/html" charset="iso-8859-1" /> <style type="text/css"> body, a, li { font-family: verdana; font-size: 11px; } h1 { font-family: verdana; font-size: 15px; color: navy } .breadCrumbs { margin-bottom: 10px; border-style: dashed; border-width: 2px; padding: 4px; width: 400px; } </style> </head> <body> <h1>Bread Crumbs Menu</h1> <div class="breadCrumbs"> <?php // Display the breadcrumbs while ( $item = $crumbs->fetch() ) { if ( $item->isRoot() ) { echo ( "<a href=\"".$baseUrl.$item->location()."\">" .$item->name()."</a>" ); } else { echo ( " > <a href=\"".$baseUrl.$item->location()."\">" .$item->name()."</a>" ); } } ?> </div> Sample Urls: Contact Folio Products Fiction </body> </html> [*] Online Result [*] Have I forgotten something e.g. a .sql file? I have not checked that well enough. [/list:o:74611b87b2] |
|
|||
|
Quote:
Sorry to distract from the initial purpose of this thread, some great resources posted so far kgun |
|
||||
|
No problem. Discussion is very important. My remarks. Imagine 5 levels from basic to advanced.
Most webmasters should be able to manage the first three levels. The learning curve for OOP may seem steep, but once you grasp it, you will love it. <off topic> Favourite link? Borland Developer Network. When I studied Borland C++ Builder and C++ in the mid 90's, every serious developer knew that the Borland compiler was lightyears ahead of Microsoft's C++ compiler. You could even use the MS C++ class library in the Borland Compiler. That library naturally had its strenghts on MS operating system(s) classes. I think that Borland's C++ builder is still one of the best developement tools, but Borland is not that clever on marketing as for example Microsoft and Google. You do not need that for developing Web Applications. OOP in PHP becomes easy when you know C++. So if you are a young web developer, my advice is, take a course in C++ and learn to handle Borland's C++ Builder. When you handle it and understand the code, you can read OOP PHP code like others read a book. What has caused me most frustration in compiling code and putting code on the web / test server, is configuration, includes, libs, resources etc. etc. So start by studying the / your environments and learn to handle them, before you start on using third party libraries. I have tried to make that clear in my example above with the config.php file. </off topic> Back to topic? |
|
||||
|
Resources for this post.
|
|
||||
|
Don't submit the form with your credentials unless you want to register in my client database and get future OOP information. That is your responsibility.
As long as you do not use SSL it is not easy to make the registration more secure than this form. Features:
I had to rewrite a lot of code in 7.php. I could not find it at sitepoint. Here is the code: 7.php Fairly much rewrittin from 7.php that follows with the book. <?php require_once('../config/config.php'); // Include the MySQL class require_once('Database/MySQL.php'); // Include the Session class require_once('Session/Session.php'); // Include the SignUp class require_once('AccessControl/SignUp.php'); // Include the QuickForm class require_once ('HTML/QuickForm.php'); // Include the phpmailer class require_once ('ThirdParty/phpmailer/class.phpmailer.php'); // Settings for MySQL $host='db.yoursite.com'; // Hostname of MySQL server $dbUser='YourUserName'; // Username for MySQL $dbPass='YourPassword'; // Password for user $dbName='YourDatabaseName'; // Database name // Settings for SignUp class $listener='http://www.kjellbleivik.com/AccessControl/7.php'; $frmName='Kjell Bleivik'; $frmAddress='noreply@kjellbleivik.com'; $subj='Account Confirmation'; $msg=<<<EOD <h2>Thank you for registering!</h2> <div>The final step is to confirm your account by clicking on:</div> <div><confirm_url/></div> <div> Your Site Team </div> EOD; // Instantiate the MySQL class $db=& new MySQL($host,$dbUser,$dbPass,$dbName); // Instantiate the Session class $session=new Session(); // Instantiate the signup class $signUp=new SignUp($db,$listener,$frmName,$frmAddress,$subj,$m sg,TRUE); // Is this an account confirmation ? if ( isset ( $_GET['code'] ) ) { if ( $signUp->confirm($_GET['code']) ) { $display='Thank you. Your account has now been confirmed. '. 'You can now login'; } else { $display='There was a problem confirming your account. '. 'Please try again or contact the site administrators'; } // Otherwise display the form } else { // Register a session variable for use in the image if ( !$session->get('randomString') ) $session->set('randomString',$signUp->createRandString()); // A function for comparing password function cmpPass($element, $confirmPass) { global $form; $password = $form->getElementValue('password'); return ($password == $confirmPass); } // A function to encrypt the password function encryptValue($value) { return md5($value); } // Instantiate the QuickForm class $form =& new HTML_QuickForm('regForm', 'POST'); $renderer =& $form->defaultRenderer(); // Clear the default HTML templates $renderer->clearAllTemplates(); // Define new templates $renderer->setFormTemplate(' <table class="registration"> <form{attributes}>{content} </form> </table>'); $renderer->setHeaderTemplate(' <tr> <td class="header" colspan="2">{header}</td> </tr>'); $renderer->setElementTemplate(' <tr valign="top"> <td class="label"> {label} </td> <td class="field"> <span class="error">{error}</span> {element} <span class="required">*</span> </td> </tr>'); $renderer->setRequiredNoteTemplate(' <tr> <td></td> <td class="requiredNote">{requiredNote}</td> </tr>'); // Add a header to the form $form->addElement('header', 'header', 'Registration Form'); // Register the compare function $form->registerRule('compare', 'function', 'cmpPass'); // The login field $form->addElement('text','login','Desired Username:','class="signupData"'); $form->addRule('login','Please provide a username','required',false,'client'); $form->addRule('login','Username must be at least 6 characters','minlength',6,'client'); $form->addRule('login','Username cannot be more than 50 characters','maxlength',50,'client'); $form->addRule('login','Username can only contain letters and numbers','alphanumeric',NULL,'client'); // The password field $form->addElement('password','password','Password:','cla ss="signupData"'); $form->addRule('password','Please provide a password','required',false,'client'); $form->addRule('password','Password must be at least 6 characters','minlength',6,'client'); $form->addRule('password','Password cannot be more than 12 characters','maxlength',50,'client'); $form->addRule('password','Password can only contain letters and numbers','alphanumeric',NULL,'client'); // The field for confirming the password $form->addElement('password','confirmPass','Confirm:','c lass="signupData"'); $form->addRule('confirmPass','Please confirm password','required',false,'client'); $form->addRule('confirmPass','Passwords must match','compare','function'); // The email field $form->addElement('text','email','Email Address:','class="signupData"'); $form->addRule('email','Please an email address','required',false,'client'); $form->addRule('email','Please enter a valid email address','email',false,'client'); $form->addRule('email','Email cannot be more than 50 characters','maxlength',50,'client'); // The first name field $form->addElement('text','firstName','First Name:','class="signupData"'); $form->addRule('firstName','Please enter your first name','required',false,'client'); $form->addRule('firstName','First name cannot be more than 50 characters','maxlength',50,'client'); // The last name field $form->addElement('text','lastName','Last Name:','class="signupData"'); $form->addRule('lastName','Please enter your last name','required',false,'client'); $form->addRule('lastName','Last name cannot be more than 50 characters','maxlength',50,'client'); // The signature field $form->addElement('textarea','signature','Signature:','c lass="signature"'); // The image check field for "humanness" $form->addElement('text','imageCheck','Image Text:', 'class="signupData"'); $form->addRule('imageCheck','Please enter text from image', 'required',false,'client'); // Server side validation! Don't give away random string in JavaScript $form->addRule('imageCheck','Please confirm the text in the image', 'regex','/^'.$session->get('randomString').'$/', 'server'); // The image check field // Changed $form->addElement('image', ' ', '8.php', 'class="image"'); // Add a submit button called submit and "Send" as the text for the button $form->addElement('submit','submit','Register','class="c reateAccount"'); // Specify the "required field" note for the bottom of the form $form->setRequiredNote('<span class="required">*</span> required'); // If the form is submitted... if ( $form->validate() ) { // Apply the encryption filter to the password $form->applyFilter('password', 'encryptValue'); // Build an array from the submitted form values $submitVars=array ( 'login'=>$form->getSubmitValue('login'), 'password'=>$form->getSubmitValue('password'), 'email'=>$form->getSubmitValue('email'), 'firstName'=>$form->getSubmitValue('firstName'), 'lastName'=>$form->getSubmitValue('lastName'), 'signature'=>$form->getSubmitValue('signature') ); // Create signup if ( $signUp->createSignup($submitVars) ) { // Send confirmation email if ( $signUp->sendConfirmation() ) { $display='Thank you. Please check your email to '. 'confirm your account'; } else { $display='Unable to send confirmation email. '. 'Please contact the site administrators'; } } else { $display='There was an error creating your account. '. 'Please try again later or '. 'contact the site administrators'; } } else { // If not submitted, display the form $display=$form->toHtml(); } } ?> <!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title> Sign Up </title> <style type="text/css"> body, a, td, input, textarea { font-family: verdana; font-size: 11px; } .registration { width: 400px; } .header { color: navy; text-align: center; font-variant: small-caps; font-size: 15px; font-weight: bold; border-color: navy; border-style: dashed; border-width: 1px; background-color: #f6f7f8; } .label { color: navy; text-align: right; width: 40%; font-weight: bold; padding: 3px; } .info { color: navy; text-align: right; width: 40%; padding: 3px; } .required { color: red; } .field { width: 60%; padding: 3px; } .error { color: red; } .requiredNote { font-size: 9px; text-align: right; } .signupData { width: 200px; background-color: #f6f7f8; font-weight: bold; } .signature { background-color: #f6f7f8; font-weight: bold; width: 200px; height: 100px; } .createAccount { background-color: #f6f7f8; color: navy; font-weight: bold; } </style> </head> <body> <?php echo ( $display );?> </body> </html> 8.php <?php require_once('../config/config.php'); // Include Session class require_once ('Session/Session.php'); // Include RandomImageText class require_once ('Images/RandomImageText.php'); // Instantiate the Session class $session=new Session; // Instantiate RandomImageText giving the background image $imageText=new RandomImageText ('reg_image/reg_image.jpg'); // Add the text from the session $imageText->addText($session->get('randomString')); // Send the right mime type header ( 'Content-type: image/jpeg' ); // Display the image ImageJpeg($imageText->getImage()); ?> You also need the image File: reg_image/reg_image.jpg |
|
||||
|
I do not like to be responsible for broken links, but my example links in this post will be deleted because of changing the site.
Main reason for links: Example. |
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
|
WebProWorld |
Advertise |
Contact Us |
About |
Forum Rules |
MVP's |
Archive |
Newsletter Archive |
Top |
WebProNews
WebProWorld is an iEntry, Inc. ® site - © 2009 All Rights Reserved Privacy Policy and Legal iEntry, Inc. 2549 Richmond Rd. Lexington KY, 40509 |