General OOP Practices..
I'm newer to the OOP in php world, but my questions revolve around good practices when programming OO in PHP rather than can this be done. So, I have a class with 7 functions in it, and I set in my constructor 7 variables. Is it better to pass the variables as needed through the functions for example:
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
PHP Best Practices
I have a basic design question, in terms of what is "better" programming. I have a web site, and am using php pages as includes. some of the php pages have php tags, and "echo" or "print" the php variables and html. Like this: <div id="body"> <?php include("phpincludes/server-nav.php"); ?> </div> the php page has code like this: <div id="header"> <ul> <li class="tab" <?php if ($thisPage=="Home") echo " id="currentpage""; ?>> <a href="http://abf966/LBA/index.php">Home</a> </li> <li class="tab" <?php if ($thisPage=="Introduction") echo " id="currentpage""; ?>> <a href="http://abf966/LBA/intro.php">Introduction</a></li... etc
Some PHP Best Practices
I'm starting a new project, and I was wondering what is considered best practise in the following cases: * Connecting to multiple databases using the PEAR library. * Triggering your archive script from within the project without cron on the server It doesn't looks right to start archiving each time a user visits a page. * Providing some sort of login authorization over XML-RPC. If you work on a user-based permissions site, how do you continue that to XML-RPC.
Bad PHP Coding Practices?
I'm just wondering what are some bad (inefficient / resource intensive) PHP coding practices. For example, in Visual Basic string concatenation in a loop can really slow things down since a new string is created each time. Object creation has overhead and only so many objects can be created before it bogs down. Any significant problems with $a .= $a + "text" or objects in PHP? Any other bottlenecks?
Best Practices - GUI Standards
I hope this is on topic this looks like a pretty generic PHP group. If not I'm a nooB so be gentle. Question: Could anyone recommend a "best practice" for maintaining commonality of what the user sees on a medium scale PHP application? For example: button size, color, font, alignment, labels, etc. My intent is to build an application that has been pre-designed in phases, piece by piece and outsource most of the coding. There must be a common look and feel. Is there a better way then me simply listing them out? Ex: all buttons are 10px by 20px, all font arial 10pt, etc.
Programming Practices
Which are considered to be the best programming practices? for example i prefer to not store sessions into files (as done by default by php), but in a database as this gives me the possibility to use the same session on multiple servers, this is possible because of the session_set_save_handler() function! So which do you use (non-oop)? To enlarge the topic a bit: which threads are all out there and how do you solve them (e.g.: cross site scripting)?
Best Practices For Sortable Columns
I have several forms that display information from the database after users log in. I would like the column titles to be sortable so that when the user clicks on a column heading, the data re-displays in sorted order of that column. Next time they click on it, it toggles the order from ascending to descending, and then back to ascending again. Since I have many forms and each form has different columns, I was wondering if there was a method that would be better than a brute force approach. What are the best practices for this functionality?
Include() & Paths - Best Practices
I have a question regarding paths and the include() statement in PHP. I develop in a Windows environment and will be publishing to a Linux server. I would like to do the following: 1. Setup my include references in such a way that I don't have to change them all every time I have to publish to the production server 2. Setup above in such a way that won't involve php.ini (& LInux equivalent), as I have access to edit this file locally, but won't be able to do so in the production environment My file structure is such: wwwroot subdir global inc I tried Windows-styled virtual references such as "/" to refer to the wwwroot, but that didn't work in the production evironment. I switched to relative paths (eg include("global/inc/config.inc") or include ("../global/inc/config"). I guess what I'm looking for here is a best practice for how to set the includes up for maximum portability across servers with different file systems as well as different platforms. Can you, for instance, incorporate a variable that defines the root path into the include statement above? If so, where do you define this variable globally without having to add to every file? (b/c you can't use an include statement if you haven't gotten the includes to work) Is there an equivalent of global.asa for the PHP world? I'm just raising some issues with my experience thus far. I know there's a solution and a best practice that I'm just missing to the point--I would appreciate any wisdom that could be shared.
PHP Default Host Best Practices
I've got my dev and production environments all setup, and the mysql DBs working fine. What need to do is set the mysql.default_host option in php.ini to be one thing on dev, and something different on production. Unfortunately, my web host doesn't allow me to mess with php.ini. So, what's the best way to specify a different host to mysql_connect() on dev and production. Yes, I could manually edit the variable everything I FTP, but I'd rather not. Should I use a global variable in a separate include file? Other options?
Best Practices For Bundling PHP Runtime Libs?
My company makes a tool which generates (among other things) PHP client-side bindings to WebServices. We have also implemented a collection of PHP-code required by these bindings ("runtime libraries"). Our tool creates a file containing the PHP-bindings, but the runtime libraries should also be placed somewhere where it will be picked up by the PHP-engine. Is there a common/standard way or to do this in the PHP-community? I do not like the idea of installing the runtime libraries in system-folders or something like that. Would someone offer their recommendations?
General Security
I'm still somewhat new with php, only able to play with it now and again. Anyway, I was recently sent an email about poss security flaws, not in php itself but in my code on a site that I am working on. Here is a list of security issues that poss exist and I'm just looking for other ways to improve the overall security of the site. *transactions this site accepts transactions through IBILL. I need a way to validate that after the client goes to ibill's site and gets sent to back to my site, that it really is coming from Ibill. I hear that 'http_referrer' can be spoofed and should therefore not be trusted, at least not by itself. Right now I am just using a hidden form field and passing through a var from my site, to ibill, and back to my site. Problem is of course that someone could just copy and paste my source and change the action of the form to just bypass ibill and go directly to the processing page after ibill, should they find a way to know what it is. This is all assuming they know how of course. I just need a good way of validating that they actually payed through ibill and did not get a free account. I thought about registering that hidden form field var within the session and comparing it to the returned var from ibill, if that makes any sense to you guys..any idea's here? *file uploads after paying, clients can upload images via thier personal control panel. I perform a mime check only at this time. I recently found: is_uploaded_file() and move_uploaded_file() and will incorparate them into the code rather than just using copy. Should I also set permissions, or will they be set correctly after the move allready. The uploads are just images. I am also thinking of setting file set checks also. *client supplied text I am also worried about "sql injection" and things of that nature. I found add_slashes(), strip_tags(), htmlspeacialchars() and will start to use those on user supplied text. Any other functions that I might want to include and run my text vars through.
General Search
I'm using the latest generally available mysql, and i need just some general help on searching. I would like it to be the best possible and i would like the best query to handle a search, what functions would help me the most?
General Parser + Compiler
Currently my homepage uses XHTML+CSS purely. However that code is not very readable nor nice to create. A wiki is a much nicer approach but the syntax is too limited. So I would like to have some commands that are replaced by defined HTML+CSS Code. However I do not want to use XML for that but rather a LaTeX related syntax (to be able to share code for PDF and WEB more or less) Now I do not want to write the 117th Parser, but would rather want to use one where I only define environments and there replacements and PHP Code to be called. Is there something like that availabe?
A General Buffering Function
I've been trying to write a general buffer function that looks something like this: function buffer($arg){ ob_start(); $arg; return ob_get_clean(); } Note that the intention is for this to be used with functions that produce output. If $arg is a function like, function a(){ echo "this is a"; } and passed to the buffer function, it will be evaluated (pass by value) and echo its output. I'd like to supress the output. Passing by reference like .... buffer(&$arg) .... still causes an evaluation of the function, and output being spit out. Is there a way functions which produce output can be passed to another function without being evaluated and emitting output?
General Guidelines For Quotes ?
I haven't done that much research on this topic but it seems I can use either the single quotes or the double quotes. SInce I am so used to C(++) I prefer the double quotes and am wondering if they could possible be less efficient. Maybe I should get in the habit of using single quotes with Php instead ? I like my code to be consistent, so in two very similar circumstances I don't want one set of code using single quotes and the other double (I'm kinda anal, what can I say ?) Here are some simple and very common usages: $fullname="Satan"; // regular assignment that may of may not get passed to function $match="/[0-9]/"; // same but will definitely get passed to a function preg_match($match,$string); $formdata=$_POST["formData"]; // for arrays I have lots of similar code all throughout my Php programs. So what do you think, should I be using the single of double quotes in those situations ? I want to get into a good habbit now so I can write some solid stuff that I don't have to go back and change.
General Sessions Question
Every example I find on the web, and in the books I've purchased, clearly explains how to setup a session handler for MySql, and usually provides a very clear example of a main page that checks to see if a particular $_SESSION value exists, and if not redirects to a login page where the session is started, and the $_SESSION value is set. This is great, makes perfect sense. But what about after that? What happens on the next page the person goes to? What happens to the $_SESSION values? Mine go away. Is there somewhere to find what to do so that I can access the $_SESSION values, and continue to validate this user is really allowed into the next page? I have in my php.ini the following: session.save_handler="user" session.use_only_cookies="1" session.gc_maxlifetime="3600" Then, I have an include file with this: session_set_save_handler("sess_open", "sess_close", "sess_read", "sess_write", "sess_destroy", "sess_gc"); session_start(); $sessid = session_id(); if(!$sessid) die("Failed to start session"); The handlers are from one of my books and do make the entry into the database when I login. After successful login, I am redirected to a subdirectory to the index.php file there. That file includes my database connection variables, and the sessions include file described above. The $sessid variable has a value in it - it doesn't die. But my $_SESSION object has no values in it at all. I'm obviously missing something, but none of the instructors explain how to go beyond the login page!
Is General Property Class Useful?
Do you think this kind of "property class" is useful or not? I have bee bored to the way I've been coding earlier. because: - often i have database-oriented classes like product, category, news etc. - often i have fex. load, request, insert, update and delete functions for them - often problems are the same ones: - which member variables are expected from the form, which ones are not - which form fields are obligatory to fill , which ones are not - which form fields go directly to database, which ones do not So i was thinking that maybe "property class" could make this easier. But I am still afraid of changing the current application to this ideology! What do You think? Is my code gonna get messier and longer or cleaner and shorter? NOTE 1: "product class" is just a minimal example, don't think too much about that. NOTE 2: somebody possibly would dare to include property class into property class (if that is even possible) but I am afraid of recursive things little bit. Flags here are simple and safe sub-properties. Perttu Pulkkinen, Finland <? class prop { var $value; var $flags = array(); function prop($value=null) { $this->value = $value; } function set($value) { $this->value = $value; } function get() { return $this->value; }
General Good Coding Practise
Although I have no specific problems, I would like some insight into good coding in PHP, Things like, when you are printing alot of HTML with PHP code in the middle what is the best/effecient way: PHP Code:
Speed Of PHP5, Making PHP Faster In General
The people I was working with have a site that uses lots of php objects. They are having problems with speed. They had a vague idea that PHP5 has improved handling of objects over PHP4, so it would probably be faster also. In fact it seems slower. We did a few timing loops, in which a a number of objects were created and and members were accessed, and php 5 seemed to run about half the speed of php 4. Is this in line with what other people are seeing ? Is this an artifact of the beta -- that some debugging or logging is being turned on by default which won't be when the real release comes out ? In general, what tricks can I do to make either PHP faster ? I thought of compiling php with higher optimization flags, for instance. Are there tweaks I can do to the php.ini file ? I'm interested in anything, for any version of php.
General Question About Sessions Being Sticky And Closing Properly
I have some complex scripts that work fine. I have a system where sessions are validated on every page of my application to keep them secure. Everything runs fine when I test and code things. But I am also fanatical about updating the browser for security patches and remove all spyware, virues etc.. But some of my clients are not that savy and that leads me to my first question. Occasionally I have a client complain that when they are filling in a long form by the time they get to submit they've lost their session connection and are forced to log in again and start over. I can maintain a session connection for a long time and can't figure out why some people get booted off and some don't. it's randon can't find a pattern. I suspect it has something to do with browser refresh or popups or whatever... Anyway I'm looking for ideas how to maintain or increase "stickyness" with sessions? Second question. When clients use my application I do provide links they can use to "log out" but what happens to sessions when they just close the browser without logging out first? The system seems to operate fine, but should I be concerned or not? Is there some method to clear away old session data when the browser is just shut down without the client loggin off correctly, or should I
Recommendation For General Enterprise Programming Books - Not Language Specific?
I'm looking for recommendations for programming in the enterprise - multi-procedure/OO/function - that is not language specific. Rather I need some guidance about ho to break LARGE problems down in to smaller ones for programming. I've been a programmer for many years but never on a really large one. And the medium size ones don't even come along very often so I deal a lot with smaller database and programming.
I Need Help With A General Flash ".swf" Question
problem with a .swf file header I know that the .swf files are defined in size while we build them and so when we put .swf file in any web page we have to set the size but I have noticed that the .swf files if we opened them directly in our browser are stretched to the size of the browser so is there any way to do this by making the swf file get bigger or smaller according to the size of the browser.
|