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
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
269 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 ...
3
votes
3answers
25k 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; ...
4
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: ...
5
votes
2answers
4k views

Writing a proper (and simple) auth/login class in PHP

How to write and design a simple (but still proper and secure) login class for PHP? Currently I'm checking whether there is a login request (user entered data into login form) or the session is ...
2
votes
1answer
756 views

mixed AJAX/Javascript form validation check

I've got a form, for which the "Send" button should only be available, upon each form field being validated. For most of my check, I call a function checkFormValue()...
7
votes
3answers
1k views

Payment function with too many parameters

I have a method with too many parameters. How would you refactor it? Things I considered so far: pass an array to the object and check for required keys (no code hint, phpdoc, programmer doesn't ...
0
votes
1answer
235 views

Help to Refactor PHP Flip Image Code to smallest size as possible

I have written this PHP function which will flip an image (horizontally, like looking in a mirror). It reads the file, flips it, and writes it to a new filed called filename"_flipped".ext. I would ...
1
vote
2answers
950 views

Efficiently working out the nearest weekend

Is this an efficient way to do this? the code is designed to find the nearest friday, without passing Sunday. If it is already past Friday, the start date should equal now. ...
2
votes
1answer
304 views

SQL Injection and php performance checking

I hope this is not a really bad question for a first time here beginner. This piece of code selects from the left table and will list the content in the right hand table. This is a working code but I ...
1
vote
1answer
303 views

please check my user session login system and tell me what can be done to make it better

There can be some errors in the script, if u find them thanks, but the main thing is to get useful suggestions about how can I do this better and secure. ...
2
votes
2answers
256 views

Am I over-reacting with my page SESSIONS security?

In order to secure my page SESSIONS I have the following pages. My questions are Am I over-reacting with this? Should I place the token in login.php instead of the loginForm.php ? When a user ...
1
vote
3answers
359 views

How could I make this PHP $_POST more secure? -Or is it secure already?

On most my $_post data inputted on my site I use the following php: ...
0
votes
2answers
166 views

Make two MySQL statements & loop quicker

Would a join be quicker here? I tested a join and it's almost the same time! Basically its a ray casting mechanism that finds all properties in a square on GMaps, and then there's a javascript ...
2
votes
1answer
199 views

Improving my user class

I am still uncomfortable and new with working with classes. I have made a User class that will return stuff about the user. ...
2
votes
1answer
166 views

PHP email selector class

I've only been writing php for a couple of months, and I've never really had anyone to look at any code I have written. I've written this class, that returns an email address from a database, based ...
2
votes
3answers
1k views

Is there any faster way instead of using preg_match in the following code?

this code finds if there is the string 2004 in <date_iso></date_iso> and if it is so, I echo some data from that specific element that the search string ...
3
votes
1answer
364 views

In need to speed up this code that filters the data of XML using XMLReader

I am using XMLReader and avoided SimpleXML because I must handle a huge file and for memory issues, SimpleXML is not the ideal solution. However, even I coded the below script in SimpleXML, it gives ...
5
votes
4answers
987 views

Best practice for lining up PHP syntax in HTML page

I'm using Codeigniter but this goes for any project in PHP. Let's say I have the following code in my view. I've been struggling, trying to figure out how best to indent and display PHP code within ...
4
votes
5answers
2k views

single array or many single argument to call a constructor with params?

I am seeing it more and more. Which do you think works best and why? This: $config = array( 'param1'=>'abc' 'param2'=>'dfg' ); new Class($config); Or: <...
4
votes
1answer
401 views

Accessing multiple schemas using singleton pattern

I have a situation where I have to connect to multiple schema to populate a single page. I altered our singleton db class in to help me do this. It will now destroy and re-declare itself whenever we ...
4
votes
1answer
106 views

Suggestions for improving collection of related PHP functions?

I am working on a Web chat application. In the app, users can run commands (such as /nick, /msg, etc) by starting with a / and then typing the command followed by parameters. For example, if someone ...
2
votes
2answers
220 views

Sanitisation function: any holes?

I've come up with this small function to make user submitted strings safe for MySQL. I'd be grateful if someone could point out any security holes in this. I've tested it out, and it happily replaces ...
2
votes
1answer
879 views

Polling script to determine the continuous time a user has been connected

I've been asked to keep track of how long a user has been connected to a site without interruption. So far the solution I've come up with is to use ajax to poll the site every now and then to check ...
4
votes
1answer
893 views

Wrap email quotes with html element

I'm wondering if I could handle the following situation with a single function or regex call. Given the folowing input: ...
4
votes
1answer
3k views

Copy a file, renaming it if the destination already exists.

I would love some feedback on this little utility function: ...
3
votes
1answer
472 views

Improve OOP code

I am learning OOP and have written a class for Likes. There is a load, add, delete method and I think this code can be improved since there is a lot of duplication. Please let me know how I can ...
4
votes
2answers
2k views

How can I improve this PHP MySql Rank generation function?

How can I improve this PHP MySql Rank generation function? (Mostly looking to improve speed, but any feedback is very welcome) Right now I keep stats and ranks in 2 separate tables. The only ...
2
votes
2answers
2k views

Event Registration

I am new to the world of coding, PHP as well as XHTML. As my first stab at object oriented coding, I put together a basic registration form that is meant to serve as a means to collect user details. ...
6
votes
3answers
1k views

PHP Table generation

I have been using the following function (in the kohana html class in a table) to generate tables. ...
7
votes
1answer
4k views

Workaround for overloaded constructor in PHP

I have a class whose purpose is to display a comment. I'd like to be able to instantiate it by passing a Comment object if I happen to have it available, or just ...
3
votes
2answers
1k views

PHP Output Block Defining and Best Practices

I've been rolling around several ideas or approaches in my head, and none seem any more useful or "right" than another. I'm sure this is extremely objective but I'm looking for a close-to-definitive ...
1
vote
1answer
228 views

Have I gone too far in factoring out repeated code in this example?

In a controller (PHP, CodeIgniter) I'm adding scripts & css to variables to be used in the view output. My initial coding looked like this: ...
3
votes
2answers
4k views

PHP Questionnaire Code Peer Review

I just started learning how to code PHP as well as HTML and as a challenge for myself I put together a questionnaire with what I have learnt so far which isn't as much as I would like to know e.g. ...
4
votes
1answer
729 views

Implementing PDO, code correct so far?

I have decided to go PDO and have started implementing it on one of my webprojects. I have limited programing skills but can usually pull it off with some tutorials and forums. Here is my code this ...
4
votes
3answers
1k views

73 Lines of Mayhem - Parse, Sort and Save to CSV in PHP CLI

Inside of a folder named txt I have 138 text files (totaling 349MB) full of email addresses. I have no idea (yet) how many addresses there are. They are separated ...
6
votes
5answers
430 views
3
votes
3answers
325 views

PHP, Is creating a class for templates to much?

I am new to using classes heavily, and was wondering if going so far as to create a class specifically for templates was going to far. Here is a simplified version of my class template. Yes, I know I ...