starting a website in PHP and My SQL

Reply

Join Date: Oct 2006
Posts: 954
Reputation: ardav will become famous soon enough ardav will become famous soon enough 
Solved Threads: 126
ardav's Avatar
ardav ardav is offline Offline
Posting Shark
 
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

  1. <?php
  2. include("{$_SERVER['DOCUMENT_ROOT']}/includes/config.php");
  3. include("{$_SERVER['DOCUMENT_ROOT']}/includes/functions.php");
  4. include("{$_SERVER['DOCUMENT_ROOT']}/includes/dtd.php");
  5. include("{$_SERVER['DOCUMENT_ROOT']}/includes/head_n_body.php");
  6. include("{$_SERVER['DOCUMENT_ROOT']}/includes/bannerarea.php");
  7. include("{$_SERVER['DOCUMENT_ROOT']}/includes/nav.php");
  8. include("{$_SERVER['DOCUMENT_ROOT']}/includes/side.php");
  9. include("{$_SERVER['DOCUMENT_ROOT']}/includes/main_content.php");
  10. include("{$_SERVER['DOCUMENT_ROOT']}/includes/footer_n_end.php");
  11. ?>

Then in your actual displayed page, you could have something like:

  1. <?php
  2. include("{$_SERVER['DOCUMENT_ROOT']}/templates/main.php");
  3. ?>
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.

  1. <?php
  2. $navlist = getNavItems($_SERVER['PHP_SELF']);
  3. //there are better ways of doing this - the function could spit out parsed html containing the navlist (from the DB) pertaining to that page
  4. ?>
  5. <ul id="nav">
  6. <?php echo $navlist;?>
  7. </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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 7
Reputation: phpangel is an unknown quantity at this point 
Solved Threads: 0
phpangel phpangel is offline Offline
Newbie Poster
 
0
  #12
Oct 21st, 2009
thank u that was really helpful, one more ques plz, how can make my login script appear in index page (i mean the the user area in home page) in other words how to include, so that the member can login and how can i show the status in index page as well?

thanx in advance
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 954
Reputation: ardav will become famous soon enough ardav will become famous soon enough 
Solved Threads: 126
ardav's Avatar
ardav ardav is offline Offline
Posting Shark
 
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:

  1. if(isset($_SESSION['username'])){
  2. echo "<p>{$_SESSION['username']} logged in <a href='logout.php' title='log out from site'>[logout]</a></p>";
  3. }else{
  4. ?>
  5. <form action="includes/authenticate.php" method="post">
  6. <label for="username">Username:</label>
  7. <input type="text" name="username" id="username" />
  8. <label for="pw">Username:</label>
  9. <input type="password" name="pw" id="pw" />
  10. <?php
  11. if(isset($_SESSION['login_error'])){
  12. echo "<p class='beware'>Username and/or password not correct</p>";
  13. }
  14. ?>
  15. <input type="submit" name="login" id="login" value="Login" />
  16. </form>
  17. <?php
  18. }
  19. ?>

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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 72
Reputation: smartness is an unknown quantity at this point 
Solved Threads: 10
smartness's Avatar
smartness smartness is offline Offline
Junior Poster in Training
 
0
  #14
Oct 21st, 2009
It's better if you use ready classes... try: phpclasses.org
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 954
Reputation: ardav will become famous soon enough ardav will become famous soon enough 
Solved Threads: 126
ardav's Avatar
ardav ardav is offline Offline
Posting Shark
 
0
  #15
Oct 21st, 2009
Originally Posted by smartness View Post
It's better if you use ready classes... try: phpclasses.org
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 72
Reputation: smartness is an unknown quantity at this point 
Solved Threads: 10
smartness's Avatar
smartness smartness is offline Offline
Junior Poster in Training
 
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)
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 954
Reputation: ardav will become famous soon enough ardav will become famous soon enough 
Solved Threads: 126
ardav's Avatar
ardav ardav is offline Offline
Posting Shark
 
0
  #17
Oct 21st, 2009
Originally Posted by smartness View Post
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)
I agree - you can't do everything from scratch - the above links you note are good places to do some effective learning. My quibble is that a beginner will get very little from professional-level classes as they are usually OOPed and use the most efficient way of presenting conditionals (e.g. ternaries) - this is baffling for many!

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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 7
Reputation: phpangel is an unknown quantity at this point 
Solved Threads: 0
phpangel phpangel is offline Offline
Newbie Poster
 
0
  #18
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
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 954
Reputation: ardav will become famous soon enough ardav will become famous soon enough 
Solved Threads: 126
ardav's Avatar
ardav ardav is offline Offline
Posting Shark
 
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.
"...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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,357
Reputation: evstevemd has a spectacular aura about evstevemd has a spectacular aura about evstevemd has a spectacular aura about 
Solved Threads: 127
evstevemd's Avatar
evstevemd evstevemd is offline Offline
Nearly a Posting Virtuoso
 
0
  #20
Oct 21st, 2009
Originally Posted by phpangel View Post
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
Hi,
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
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC