944,103 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 1161
  • PHP RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Oct 20th, 2009
-1
Re: starting a website in PHP and My SQL
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

PHP Syntax (Toggle Plain Text)
  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:

PHP Syntax (Toggle Plain Text)
  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.

PHP Syntax (Toggle Plain Text)
  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>
Sponsor
Featured Poster
Reputation Points: 1067
Solved Threads: 954
Disgraced Poster
ardav is offline Offline
6,726 posts
since Oct 2006
Oct 21st, 2009
0
Re: starting a website in PHP and My SQL
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
Reputation Points: 8
Solved Threads: 0
Light Poster
phpangel is offline Offline
31 posts
since Oct 2009
Oct 21st, 2009
-1
Re: starting a website in PHP and My SQL
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:

PHP Syntax (Toggle Plain Text)
  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.
Sponsor
Featured Poster
Reputation Points: 1067
Solved Threads: 954
Disgraced Poster
ardav is offline Offline
6,726 posts
since Oct 2006
Oct 21st, 2009
0
Re: starting a website in PHP and My SQL
It's better if you use ready classes... try: phpclasses.org
Reputation Points: 7
Solved Threads: 14
Junior Poster
smartness is offline Offline
103 posts
since Aug 2007
Oct 21st, 2009
-1
Re: starting a website in PHP and My SQL
Click to Expand / Collapse  Quote originally posted by smartness ...
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.
Sponsor
Featured Poster
Reputation Points: 1067
Solved Threads: 954
Disgraced Poster
ardav is offline Offline
6,726 posts
since Oct 2006
Oct 21st, 2009
0
Re: starting a website in PHP and My SQL
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)
Reputation Points: 7
Solved Threads: 14
Junior Poster
smartness is offline Offline
103 posts
since Aug 2007
Oct 21st, 2009
-1
Re: starting a website in PHP and My SQL
Click to Expand / Collapse  Quote originally posted by smartness ...
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.
Sponsor
Featured Poster
Reputation Points: 1067
Solved Threads: 954
Disgraced Poster
ardav is offline Offline
6,726 posts
since Oct 2006
Oct 21st, 2009
0
Re: starting a website in PHP and My SQL
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
Reputation Points: 8
Solved Threads: 0
Light Poster
phpangel is offline Offline
31 posts
since Oct 2009
Oct 21st, 2009
-1
Re: starting a website in PHP and My SQL
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.
Sponsor
Featured Poster
Reputation Points: 1067
Solved Threads: 954
Disgraced Poster
ardav is offline Offline
6,726 posts
since Oct 2006
Oct 21st, 2009
0
Re: starting a website in PHP and My SQL
Click to Expand / Collapse  Quote originally posted by phpangel ...
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!
Reputation Points: 462
Solved Threads: 392
Senior Poster
evstevemd is offline Offline
3,681 posts
since Jun 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: global variables in php
Next Thread in PHP Forum Timeline: Problem with login sessions... empty session variable (weird...)





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC