| | |
starting a website in PHP and My SQL
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
0
#11 Oct 20th, 2009
Sorry - that was a bit cryptic.
Your main html sections will probably be "static", e.g. navbars, sidebars, footers, banners etc etc
If you want to give total control - you'll probably need to created 'template' files to hold the various 'static' elements. You don't need a templating system - you can create your own. The following example is just that - not to be taken too seriously - just one way. There are far better ways of doing things I'm sure.
In /templates/main.php
Then in your actual displayed page, you could have something like:
And that's it. The static content (structural html and the odd piece of static text/logos etc) can be drawn from the individual include files AND/OR from a DB, which is handled by the include files.
The dynamic data from the DB can be placed into placeholder variables within the include files.
Your main html sections will probably be "static", e.g. navbars, sidebars, footers, banners etc etc
If you want to give total control - you'll probably need to created 'template' files to hold the various 'static' elements. You don't need a templating system - you can create your own. The following example is just that - not to be taken too seriously - just one way. There are far better ways of doing things I'm sure.
In /templates/main.php
PHP Syntax (Toggle Plain Text)
<?php include("{$_SERVER['DOCUMENT_ROOT']}/includes/config.php"); include("{$_SERVER['DOCUMENT_ROOT']}/includes/functions.php"); include("{$_SERVER['DOCUMENT_ROOT']}/includes/dtd.php"); include("{$_SERVER['DOCUMENT_ROOT']}/includes/head_n_body.php"); include("{$_SERVER['DOCUMENT_ROOT']}/includes/bannerarea.php"); include("{$_SERVER['DOCUMENT_ROOT']}/includes/nav.php"); include("{$_SERVER['DOCUMENT_ROOT']}/includes/side.php"); include("{$_SERVER['DOCUMENT_ROOT']}/includes/main_content.php"); include("{$_SERVER['DOCUMENT_ROOT']}/includes/footer_n_end.php"); ?>
Then in your actual displayed page, you could have something like:
PHP Syntax (Toggle Plain Text)
<?php include("{$_SERVER['DOCUMENT_ROOT']}/templates/main.php"); ?>
The dynamic data from the DB can be placed into placeholder variables within the include files.
PHP Syntax (Toggle Plain Text)
<?php $navlist = getNavItems($_SERVER['PHP_SELF']); //there are better ways of doing this - the function could spit out parsed html containing the navlist (from the DB) pertaining to that page ?> <ul id="nav"> <?php echo $navlist;?> </ul>
"...the woods would be a very silent place if no birds sang except for the best"
All opinions count.
F'enw i yw Mr. Blaidd. Byddwch yn ofalus - dwi'n cnoi.
All opinions count.
F'enw i yw Mr. Blaidd. Byddwch yn ofalus - dwi'n cnoi.
0
#13 Oct 21st, 2009
depends how deep you want to go.
A simple solution would be to login and use a $_SESSION variable to store the verified details.
Each page will have:
<?php
include('includes/login.php');
?>
The login.php file could have something like this:
The above is a very simple login form / logout link display based on $_SESSION variables. The authentication.php page accepts the data from the form and uses this (via $_POST variables) to check against users in the DB. If OK, set the session variables and kill the $_SESSION['login_error'] variable if set. If not OK, set the $_SESSION['login_error'] = 1.
Then return the user to the referring page with the header() command.
Please read up on php/mysql security BEFORE going live with an authentication script. Data validation/verification/sanitizing are essential.
A simple solution would be to login and use a $_SESSION variable to store the verified details.
Each page will have:
<?php
include('includes/login.php');
?>
The login.php file could have something like this:
PHP Syntax (Toggle Plain Text)
if(isset($_SESSION['username'])){ echo "<p>{$_SESSION['username']} logged in <a href='logout.php' title='log out from site'>[logout]</a></p>"; }else{ ?> <form action="includes/authenticate.php" method="post"> <label for="username">Username:</label> <input type="text" name="username" id="username" /> <label for="pw">Username:</label> <input type="password" name="pw" id="pw" /> <?php if(isset($_SESSION['login_error'])){ echo "<p class='beware'>Username and/or password not correct</p>"; } ?> <input type="submit" name="login" id="login" value="Login" /> </form> <?php } ?>
The above is a very simple login form / logout link display based on $_SESSION variables. The authentication.php page accepts the data from the form and uses this (via $_POST variables) to check against users in the DB. If OK, set the session variables and kill the $_SESSION['login_error'] variable if set. If not OK, set the $_SESSION['login_error'] = 1.
Then return the user to the referring page with the header() command.
Please read up on php/mysql security BEFORE going live with an authentication script. Data validation/verification/sanitizing are essential.
"...the woods would be a very silent place if no birds sang except for the best"
All opinions count.
F'enw i yw Mr. Blaidd. Byddwch yn ofalus - dwi'n cnoi.
All opinions count.
F'enw i yw Mr. Blaidd. Byddwch yn ofalus - dwi'n cnoi.
0
#15 Oct 21st, 2009
Easier, not necessarily better. Learning should be an active experience, rather than passive. If we take the 'classes is better' stance, we'd use Wordpress or similar. Of course some elements of app building will have to rely on ready-made scripts, e.g. wysiwyg editors.
"...the woods would be a very silent place if no birds sang except for the best"
All opinions count.
F'enw i yw Mr. Blaidd. Byddwch yn ofalus - dwi'n cnoi.
All opinions count.
F'enw i yw Mr. Blaidd. Byddwch yn ofalus - dwi'n cnoi.
0
#16 Oct 21st, 2009
I don't know about his Skills, but a starter can't Code everything from scratch! Classes are coded by more experienced coders, and they are provided with examples...
If he (phpangel) wants to learn php & mysql, i would suggest Lynda.com:
1. PHP with MySQL Essential Training (you will learn how to code a php/mysql a simple article site, form the scratch)
2. PHP with.MySQL Beyond the Basics (PHP gallery/OOP)
If he (phpangel) wants to learn php & mysql, i would suggest Lynda.com:
1. PHP with MySQL Essential Training (you will learn how to code a php/mysql a simple article site, form the scratch)
2. PHP with.MySQL Beyond the Basics (PHP gallery/OOP)
0
#17 Oct 21st, 2009
•
•
•
•
I don't know about his Skills, but a starter can't Code everything from scratch! Classes are coded by more experienced coders, and they are provided with examples...
If he (phpangel) wants to learn php & mysql, i would suggest Lynda.com:
1. PHP with MySQL Essential Training (you will learn how to code a php/mysql a simple article site, form the scratch)
2. PHP with.MySQL Beyond the Basics (PHP gallery/OOP)
Script bunnies can build decent sites, but if something goes wrong, they have little to no idea of how to fix it. As I mentioned a mix of ready-mades for things like wysiwyg editors and novel coding should be encouraged.
"...the woods would be a very silent place if no birds sang except for the best"
All opinions count.
F'enw i yw Mr. Blaidd. Byddwch yn ofalus - dwi'n cnoi.
All opinions count.
F'enw i yw Mr. Blaidd. Byddwch yn ofalus - dwi'n cnoi.
0
#19 Oct 21st, 2009
Croeso (you're welcome) - good hunting.
BTW - you can't go far wrong with a decent book on PHP5/MySQL5. I won't go on and on, but books are peer-reviewed and are usually full of good practice. O'Reilly and Wrox have good publications.
BTW - you can't go far wrong with a decent book on PHP5/MySQL5. I won't go on and on, but books are peer-reviewed and are usually full of good practice. O'Reilly and Wrox have good publications.
"...the woods would be a very silent place if no birds sang except for the best"
All opinions count.
F'enw i yw Mr. Blaidd. Byddwch yn ofalus - dwi'n cnoi.
All opinions count.
F'enw i yw Mr. Blaidd. Byddwch yn ofalus - dwi'n cnoi.
0
#20 Oct 21st, 2009
•
•
•
•
first of all, thank u all for the support, let me make life easy 4 u guyz, i'm beginner in PHP, and what i want from PHP now is:
to design a Web driven Database website and possibly with CMS, without having to use ready made open source CMS's.
thnax again
I'm doing the same!
Atheist: God is man made imagination, he doesn't exist!
Theist: It's okay, can you imagine anything else that doesn't exist?
Junior MD --- Python, C++ and PHP
Theist: It's okay, can you imagine anything else that doesn't exist?
Junior MD --- Python, C++ and PHP
![]() |
Similar Threads
- PHP and MS SQL Secure Authentication system (PHP)
- PHP and Sql question (PHP)
- php sql UPDATE problem (PHP)
- Problem with php and SQL (PHP)
- php / sql insert script error (PHP)
- PHP / My SQL Web developer (Web Development Job Offers)
- administratio activities!! (MySQL)
- PHP/SQL query help (PHP)
Other Threads in the PHP Forum
- Previous Thread: global variables in php
- Next Thread: Problem with login sessions... empty session variable (weird...)
| Thread Tools | Search this Thread |
apache api array beginner binary body broken buttons cakephp checkbox class cms code cron curl database date date/time display dynamic ebooks echo email error file files folder form forms function functions global google href htaccess html image include insert ip javascript joomla limit link list login mail mediawiki menu mlm msqli_multi_query multiple mycodeisbad mysql number oop parameter paypal pdf php phpincludeissue problem query radio random recourse recursion regex remote script search seo server sessions sms source sp space speed sql static subdomain syntax system table tag tutorial update upload url validator variable vbulletin video web webdesign white wordpress xml youtube






