Page 3 of 3 FirstFirst 123
Results 51 to 73 of 73
  1. #51
    I guess it's a matter of preference, but I think that if you work with scripts that include a douzen pages and thousands of lines it's easy to loose track of what variable does what, and with clear naming and stating the type of variable that becomes more clear. For me the capitalized first letters make it easy to read the variables on a page when scanning trough a script that needs to be altered.

    Also the heredoc can indeed be used for that purpose, again it's a matter of preference.
      0 Not allowed!

  2. #52
    Join Date
    Jan 2005
    Location
    Leeds, England
    Posts
    187
    i use dreamweaver to code my PHP. it has colour highlighting automatic indentation. and has a built in ftp. i always upload my entire site to a test folder before showing it publicly.
      0 Not allowed!

  3. #53
    Very Helpful, Thanks
      0 Not allowed!

  4. #54
    thanks for the sweet post, because of this ive realised loads of mistakes in my programming and have sorted them out!! thanks once again
      0 Not allowed!

  5. #55
    very helpful. Thank you all for all the good tips.
    One thing I would like to know though..... with sessionstart, how can I have it where it is not in the first thing in the page, I would like to include it in a header but always got errors. any ideas would be great
    Web Hosting Review - Real Reviews by Real People Submit your company and get a link to your site, Read Reviews GET YOUR Voice HEARD and REVIEW your HOST NOW!!! Check out our IT Blog Tips & Tricks
      0 Not allowed!

  6. #56
    Join Date
    Feb 2006
    Location
    Buffalo, NY
    Posts
    1,501
    I think you should mention use of variables, don't declare them unless you're going to use it a few times throughout your script.

    Also protecting yourself from SQL injections, when / should you cache your work, memcached, etc..

    I recommend new coders read these Zend tutorial(s) (There are three parts) for a good primer.

    Aside from that nice little writeup, easy to read and informative.

    Also I would usually use the following for a include.

    PHP Code:
    <?php
       
    include_once('config.php') or die('Error!');
    ?>
    *Note*
    Keep in mind the difference between include(), include_once(), require_once(), etc.
    Cody R.
    Hawk Host Inc. Proudly Serving websites since 2004.
    Official Let's Encrypt Sponsor
      0 Not allowed!

  7. #57
    Join Date
    Nov 2007
    Location
    England
    Posts
    13
    Very nice, Especially for PHP learners
      0 Not allowed!

  8. #58
    Join Date
    Feb 2007
    Posts
    185
    Make sure you optimize your database structure and use indexes. Cache data in memory as much as possible, however this would only be useful if you're website is very inversive with queries. If it is an average site then use a opt cacher, such as XCache. Preform a crap load of benchmarks to help you eliminate most of the bottlenecks. Google can find you a lot of good tips.
      0 Not allowed!

  9. #59
    Combining lines is not necessarily a good idea. Some people get annoyed reading scripts containing combined lines.
      0 Not allowed!

  10. #60
    Programming is all about making your own style. Some people use all the PHP rules others just put something together and don't care. Still nice tutorial for people that just began programming PHP
      0 Not allowed!

  11. #61
    I agree, however everyone has their own style of programming.
      0 Not allowed!

  12. #62
    Very nice post, i like how good people are really dedicated to their craft.
      0 Not allowed!

  13. #63
    Nice stuff.It's for beginners.

    After working hours and hours with programming and php your biggest problem will be some stupid mistake you made And you will spend next whole day trying to find out what's wrong, then you will give up.Next day in the morning while you are drinking coffee - bang, you nailed the error.The problem was YOU.It's always your mistake
      0 Not allowed!

  14. #64
    Join Date
    Mar 2010
    Posts
    89
    Thanks man this tutorial was a little over my head, do you know of any more basic tutorials out there I can start with?
      0 Not allowed!

  15. #65
    Join Date
    Sep 2004
    Location
    Cluj-Napoca, Romania
    Posts
    504
    Move to Python and Django! Sorry, just joking .

    I think the best advice is to use a PHP Framework, like Zend.
      0 Not allowed!

  16. #66
    Frameworks do help a lot. They have power and flexibility. As well as giving you the ability to replicate things fairly easily for additional sites. Zend is a good one.
      0 Not allowed!

  17. #67
    Join Date
    Aug 2010
    Location
    Somerset, UK
    Posts
    62
    Quote Originally Posted by giropets View Post
    5 - Indenting Your PHP Codes
    I don't personally like to indent my PHP codes, but it helps when reading it. When I do have to, I use the tab key to accomplish this. Example :
    PHP Code:
    <?php
    // Settings //
        
    $var1 "This";

    // Showing Variables //
        
    if($var1 == "This"){
            echo
    "You said This";
        }else{
            echo
    "You said That";
        }
    ?>
    I would add that a lot of people I know tend to use line breaks to seperate blocks of code and have all elements within the block all on the same line. I guess thats a matter of preference though. Myself I like both depending on the type of script and what makes it easier and faster to edit / update.

    Quote Originally Posted by giropets View Post
    7 - Your MySQL Queries
    Sometimes when you're writing a PHP script that includes connections to your MySQL database, you may run into a few problems. Most everyone that had MySQL problems ran a command like this one :
    PHP Code:
    <?php
    mysql_query
    ("INSERT INTO tableName ('id','name') VALUES('1','Mike')");
    ?>
    ..and they figure out that it's not inserting into their database. Here's the solution to this :
    PHP Code:
    <?php
    mysql_query
    ("INSERT INTO tableName ('id','name') VALUES('1','Mike')") or exit("MySQL Error :  " mysql_error());
    ?>
    Another way you can do this is:
    PHP Code:
    <?php
    mysql_query
    ("INSERT INTO `tableName` SET `id` = '1', `name` = 'Mike'") or die(mysql_error());
    ?>

    Quote Originally Posted by giropets View Post
    10 - Printing out a Huge Chunk of HTML at a Time
    Well, I'm sure that many of us found a way to get around this, but I'd like to share with you a few of the ways you can do it.

    1 - Break off your PHP-code, print the HTML, and start your PHP-code up again. (I don't prefer doing this as it looks pretty unprofessional to me).
    2 - Adding backslashes to each HTML tag. (It works, but takes forever to do).
    3 - Using the echo/print command, but without having to do much work. (I recommend) :
    PHP Code:
    <?php
    // Showing a huge chunk of HTML at a time //
    echo<<<END
    <font face="Verdana" color="Orange" size="3">Large, Orange Text in Font Size 3</font>
    <br><br>
    More HTML down here..
    <br><br>
    <div align="Center">Centered text</div>
    END;
    ?>
    I have to say this is a great way to do it!

    Thanks for sharing, very good yet brief overview!
      0 Not allowed!

  18. #68
    Join Date
    Nov 2010
    Location
    USA
    Posts
    51
    wow this was very informative, and bookmarked it for future reference. Nice work on the tutorial man.
      0 Not allowed!

  19. #69
    Another great tip: always use PDO instead of mysql API, it is much easier to code and safer.
      0 Not allowed!

  20. #70
    Use HTML Purifier if you want to filter out any XSS, code injection, fixed improper HTML syntax or malicious code. It's so simple to filter out all bad codes with just a line of PHP code.
      0 Not allowed!

  21. #71
    To save time benchmarking,
    http: / / net-beta.net / ubench
      0 Not allowed!

  22. #72
    Great simple tips that can save you hours of debugging because theres less chance of you missing a microscopic flaw because your code is neat.
      0 Not allowed!

  23. #73
    Including files in your scripts. Apparently using single quotes and include is faster:

    include 'my_file.php';
      0 Not allowed!

Page 3 of 3 FirstFirst 123

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •