Questions tagged [php]

PHP is a widely-used, general-purpose scripting language that is especially suited for web development.

Filter by
Sorted by
Tagged with
3
votes
3answers
2k views

Login Validation

I'm hoping someone is willing and can take a minute to look over this function and tell me what they think of it, if it can be improved or what not. I tried commenting out what the purpose of ...
8
votes
1answer
6k views

Small PHP MVC Template

The following is a new question based on answers from here: Small PHP Viewer/Controller template I have written a small MVC template library that I would like some critiques on. The library is ...
3
votes
1answer
617 views

Image Upload Class

This file takes a user picture upload and converts two pictures which are named according to the Session ID. Right now he biggest drawback is that you cannot crop the image at upload time like you ...
2
votes
2answers
180 views

Refactoring Logger interface to open and close logs

I asked a question about an implementation of a logger using syslog and error_log as fallback that made me re-evaluate my ...
0
votes
2answers
307 views

I want to improve my overall PHP

I've taken criticism before on my PHP and have since then taken the improvements into my routine. However, I still believe that I can improve. I believe that SE is the best place for the best ...
2
votes
1answer
738 views

Logger to syslog with error_log fallback

Below is an implementation of a typical Logger interface that uses syslog() as the default means to store messages and falls ...
1
vote
1answer
168 views

My web project security

I started a web project. Now I was wondering if it is secure enough. I followed some tutorials on HTS, but I can't see all holes (if there are any). Can you check my pages and if you can find any hole ...
1
vote
2answers
243 views

function to append “a” or “an” to the front of a number as appropriate

Input: any integer Output: that integer in number format (commas) with a leading a or an as appropriate with the rules of ...
2
votes
2answers
536 views

PHP: Learning OOP

Below is one of the first classes I've built. I started creating my functions like so: public function getCourseInfoByID($id) { } Requiring the user to pass a ...
2
votes
1answer
3k views

PHP DAO classes inherit from a generic DAO classes and only change the table name

I am building a web app that needs to access various tables in a given MySQL db. To do that, I have created a generic class, see DAO_DBRecord.php below, and I ...
5
votes
1answer
736 views

How should I efficiently delete elements from a PHP array?

In this case I have an array that is parsed from a JSON file. Normally I use all the elements in the array, but for AJAX crawling I only show the parts the search engine asked for: ...
3
votes
1answer
1k views

Zend Bootstrap code review

I've been working on putting a new app up against Zend. In my admin section, I want the nav links to only show if the user has rights to see the page. So I set up some Acls. But this doesn't seem like ...
4
votes
2answers
265 views

If statement with 2 conditions

On my webform, there are two kinds of address-fields a user can give. But since it's a complex webform (Drupal) it's kind of hard to achieve. Every time a user adds an extra address, the form is ...
2
votes
3answers
2k views

A simple php Session class, is the layout/design correct?

Basically I'm writing a simple framework in php in order to learn more. This session class is extremely rudimentary. At this point I'm not even checking ip/user_agent to prevent session hijacking, it'...
2
votes
2answers
96 views

Shell script: is it doing what I think it's doing

I've not written many shell scripts and cobbled this together from examples. The 'if' condition should check if this is already running and quite if so. The 'wget' call should trigger the php page and ...
2
votes
4answers
913 views

optimize my foreach

I have the following script and I think it's a bit inefficient. With a array from 1 to 3, this isn't a real problem, but this array can get way bigger. So how to boost it's performance/optimize this ...
1
vote
2answers
2k views

JSON for one column of a csv file?

I wrote this to pull one column of data from a csv file, divide each of the results in 2, and then format it as JSON so I can do stuff with it in a web app. It works, but it feels wonky and weird. ...
6
votes
1answer
6k views

Combining 3 or more arrays in php

Assuming I have 5 arrays, all just indexed arrays, and I would like to combine them, this is the best way I can figure, has anyone found a more efficient solution? ...
5
votes
1answer
377 views

PHP data structure review and critique

I have been working lately on an educational framework project to learn more about web development and problems that arise in more complex applications. Part of the framework's principles is to be as ...
1
vote
1answer
151 views

<select> has extra blank <option>'s and I have no idea why. please help me get them out [closed]

This is the result of the code it has extra option tags no idea why. I have no idea why It produces the extra option box. Below is the result of the query. Correct number of rows correct response......
2
votes
1answer
90 views

is there a better and short way to getting that array from joined sql query and converting it to superfish dropdown menu?

I'm trying to build a superfish dropdown menu from a sql query. Working example is can be seen from here check the "emlak bul" category: http://www.bedavaemlaksitesi.com/mersinemlakrehberi210/sayfalar/...
1
vote
1answer
183 views

Am I headed in the right direction with PHP?

I have been doing PHP for about three years now, with little direction other than the books I read and trial and error. I am currently coding what I hope to be a pretty nice application and I have ...
1
vote
1answer
147 views

Refactoring a loop with many boolean conditions

I usually spent more time on refactoring than in developing itself. But this little piece of code is really hard to refactor. I'd like to keep it as short as possible, but it's quite undarstandable: <...
1
vote
1answer
131 views
1
vote
1answer
211 views

Review on my current structure and tips on improvement

I would like tips on my CODE, map structure (How I should seperate the code, more files, etc). What I can do about the func.php file as a file with just a bunch of functions, doesn't seem to be the ...
3
votes
3answers
2k views

Simple text diff function

I've put together this extremely simple text diff function a while ago: ...
0
votes
1answer
125 views

class Database extends OneDatabase

I'm trying to conform to the Zend Coding Standard as well. ...
3
votes
2answers
92 views

Please help and improve this script for displaying search results

I wrote a search script, now I want a more efficient way of finding the keywords used for the search and make them bold. I used this code but it I feel it could be greatly improved on. Thanks for any ...
1
vote
1answer
213 views

PHP MYSQL loop to check if LicenseID Values are contained in mysql DB

I have some troubles to find the right loop to check if some values are contained in mysql DB. I'm making a software and I want to add license ID. Each user has x keys to use. Now when the user ...
1
vote
2answers
259 views

mvc improvment - 0 - to_do

Here are the 3 files that make up my MVC. The two view files containing the HTML are not included. Any advice on how to improve this so it is usable by others. It is meant to be a light-weight ...
5
votes
3answers
1k views

Simple PHP Auth Class feedback

this is a basic PHP auth class I've put together for use with simple sites I do from time to time which don't warrant using a framework. I'm wondering if i'm separating out responsibilities all that ...
6
votes
2answers
373 views

PHP Debugger Object needs review

I'm a pretty visual person and I like to see all the cool information about objects, arrays and different variables in PHP. In the beginning I would just ...
4
votes
1answer
3k views

Detect locale with PHP

I am developing a multilingual site, so i needed some sort of a function to detect user locale, as well as not to scare away search engines, so I wrote this kind of a method to detect locale. The ...
3
votes
2answers
223 views

PHP Validation with functions and list()

I have multiple form validation checks around my site so I decided to write them as functions to simplify the process of creating the validation pages, here is a snippet for an understanding of what I'...
3
votes
2answers
122 views

Keeping track of user role's

I created this class to keep track of a user's role: ...
2
votes
2answers
128 views

MVC Improvement - The View Module - 0 *

This simply pulls data from mysql and creates the html to be sent to the page. ...
4
votes
1answer
272 views

Are my Unit Tests any good?

This is the first time I have written Unit Tests. I am testing code that I have already written and would like to move to TDD once I have managed to get units written for everything that is already in ...
4
votes
3answers
26k views

PHP: checking for $_GET variables with if statements

This code gets me where I need to be, but my word it is ugly. I am checking for the existence of two $_GET variables with if() statements. I am setting the variables to empty strings first so I do ...
4
votes
1answer
2k views

PDO wrapper class

Connection stored in the xml config file. ...
3
votes
1answer
4k views

Login and signup validation php critique

Please critique my login and signup validation php files.. login.php; ...
5
votes
1answer
2k views

PHP Config file loader class

I know this is a pretty simple class for loading a config file into an object, and then accessing it's properties. I think config options should be lightweight and a class like this seems to adds a ...
0
votes
1answer
137 views

Is this IF ok? Or is there a better way?

So, I wanted to avoid an if (...) { } else if (...) { } else { } scenario to avoid duplicating code. After a little playing, I got the following working (works ...
4
votes
1answer
176 views

Reviewing my unit testing (in PHP)

This week-end, I finally found some time to learn unit testing (it's about time, I know). So I've tried to do this in PHP, with PHPUnit 3.6. I've wrote a small, simple and useless class wrapper for ...
5
votes
3answers
2k views

Simple DI container

I'm building a web application and is trying to make my code reusable. I've decided to create components that can be used outside this project. Now I'm trying to create a simple DI container, one ...
3
votes
1answer
552 views

Getting an array from one property of an associative array best practice

I have an array of objects eg. [ array( 'id' => 1, 'name' => "simon" ), ... ] and I need to get an array of IDs eg. [1,2,3,4,5]; Currently I'm doing this: ...
1
vote
2answers
4k views

Php INSERT class function

This is a INSERT function. It's working... I just pulled out the function from the class, atm to try it out. And improve. I think the code is a bit messy, And I am pretty sure I can improve the code, ...
2
votes
2answers
99 views

Filtered log reader

I've developed a log reader which can filter it's output following a few criteria: errorlevel, product, category, id. It is functioning, but when the log file is really big, it becomes very slow, to ...
1
vote
4answers
450 views

How Can I Improve/Secure My Login Script?

This is a simple login script. Thought I'm not sure when it's appropriate to use includes over just embedding the code. I'm also not sure if I should make cookies, but I guess I don't really need to ...
2
votes
1answer
460 views

Which way is better for db handler?

Is it a bad idea for a model class hold the db handler as a property? Example code are as below. I think the second is better, but the first is not so bad in my opinion. First: ...