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
1
vote
2answers
8k views

php most efficient way to check if a variable contains only certain chars

I have a small function which I regularly use to check if a variable contains only [a-z][0-9] and the special chars '-' and '_'. Currently I'm using the following: ...
10
votes
3answers
652 views

Is this correct factory method pattern?

I know that there are many similar questions, but I don't understand most of those questions because I'm not sure if I know what a factory method pattern is. So, after reading many examples over the ...
3
votes
2answers
151 views

How can this this URL Checker be made cleaner?

I have a table full of URLs, some of which will occasionally become invalid. As part of a system I'm writing to go through the links periodically, and test if they are valid (or redirect to valid ...
1
vote
1answer
220 views

Getting familiar with OOP - Factories

I have no idea if I'm doing this efficiently, or ideally, but I've written what I think is a factory. Please help me understand if this is good practice, or if there is another direction I should take ...
2
votes
1answer
163 views

How secure is this PDO Portfolio Script?

I was wondering if someone could take some time to look over my portfolio script and see let me know if it's secure enough to be uploaded live and connected to my database. My previous mySQL script ...
1
vote
2answers
140 views

Small factory class

...
2
votes
1answer
1k views

CakePHP return url validator

I have the following snippet of code that redirects a user to a specific page on successful login to the application. ...
2
votes
2answers
2k views

Filter Class to sanitize and transform input data - Improvements?

I have an upload form on my site and I'm trying to sanitize and transform input data. I will be straight forward to you - this is my first object-oriented style code! The reason I don't just want to ...
2
votes
1answer
257 views

class and object in php

i just wanted to confirm if my codes below is correct. Feel free to make corrections. ...
3
votes
0answers
655 views

CakePHP Best strategy for getting HABTM data in multiple ways within the same tool

School HABTM AthleticDirector I am building a tool for assigning athletic directors (ADs) to schools. The tool has a school menu/filter which, when selected, shows a list of ADs already assigned to ...
1
vote
1answer
1k views

PHP - Redirect based on OS optimization

I'm new to PHP and I would like to redirect the visitors of my website based on their operating system. Below is my solution. Is there anything that needs to be optimized? ...
3
votes
1answer
61 views

User Registration compress to use less querry, CPU posible

I want to find out if there are any improvements I can make to this code. How can I make it better, faster and use less queries? Or is it fine the way I wrote it? ...
0
votes
1answer
3k views

A good example of codeigniter MVC?

What is the difference between this two way and Which one is best? What do you suggest? 1. Use of query (db) directly in CI_Controller. as: ...
3
votes
1answer
770 views

PHP form XSS vulnerability

I'd like to ask if this PHP/HTML code has any flaws which can be exploited by the potential aggressor: ...
3
votes
1answer
835 views

Converting from MySQLi to PDO account activation

I had been working on a project for some time, and then it went on the way back burner after my daughter was born. I'm back to it, and now I discover that I'm best off using PDO over MySQLi. So, I'm ...
6
votes
1answer
7k views

PHP Extending PDO Class

I am trying to convert myself from using mysql extension to using PDO, with that being said I was curious if I am going about this the right way. I have a custom logging system that I built I am ...
1
vote
2answers
295 views

Looking For a More Efficient/Elegant Way To Write a MySQL Query

I'm querying a MySQL database and displaying the info in order of timestamp (DESC). Essentially, I'm grabbing the last record in the database, displaying it's date and year as the header of it's ...
1
vote
2answers
3k views

Insert, update and get in the same php file?

I'm creating a CRUD page. My first approach was use the same class editCategory.php for doing these actions: If this file is called via GET and categoryId parameter doesn't exist -> shall show a ...
1
vote
3answers
109 views

Ideas for simplificaton - Logic to choose which view to load

I have a situation where depending on what the value of a uri segment is, my controller will load a different view. Here's what the code looks like in part: ...
2
votes
2answers
2k views

PHP creating slugify (clean URL) links in simple way?

I think this is the simplest way to slugify urls. You have any contra-indication? ...
2
votes
1answer
263 views

Concept for PHP Controlled, Privileged Execution (for a cPanel knockoff on Ubuntu Server)

I was thinking of building a F/OSS project as a cPanel for Ubuntu Server, since Ubuntu doesn't have this, and yet making it easy for a hosting company to use this, where users will find it just as ...
7
votes
1answer
2k views

MySQLi DB library - quality/security review?

This libray was written quite some time ago, and it has so far been used in all sorts of small-ish projects. I'm about to base a more complex, security (Access Control) related, open-source project ...
4
votes
1answer
238 views

How to properly make a user class with a session

So I am working on a LMS project and I have a User class that will handle everything about the user such as registration, login, showing list of courses that they are subscribed to, etc. User.class....
1
vote
3answers
231 views

Trying to Find a Loop to use for a specific MySQL query

I'm trying to see if there is a loop I can use in order to pull off this code a little more elegantly. I was previously using a foreach($row as $cell) with ...
9
votes
1answer
27k views

Browser and OS detection script

I understand not to rely on user agent information for anything detrimental towards the site since it can be faked or hidden etc, it's more of just an extra feature for something. Is there anyway ...
4
votes
2answers
3k views

PHP PDO Factory Classes

So, my question is more of a 'best practices' question rather than a question with a particular aim. This is my current understanding of PHP factories and how to incorporate them into a project using ...
8
votes
1answer
435 views

Large Zend_Db query

Is there a better way to accomplish the following? ...
2
votes
1answer
194 views

Could really use some feedback on this registration code in php

I was hoping someone could give me some feedback on my code. I am still new to php and I'm sure I have messed up somewhere. The code pasted is for a registration page where users will submit their ...
0
votes
1answer
370 views

Object Orientated PHP, what's wrong with this implementation of OOPHP and how might it be improved?

I need some advice off the back of a question I posted on StackOverflow. I'm a procedural PHP programmer and I'm looking to make the move into object oriented PHP. I have started a small project that ...
3
votes
2answers
4k views

How to implement Publish-subscribe pattern in PHP?

I have two classes, Database and Logger. Database is responsible for handling SQL queries, and Logger logs messages to an external file. Whenever the database executes an SQL query, I want Logger to ...
1
vote
1answer
754 views

How to implement HasMany() relationship with PHP?

Suppose User and Item are two models, and User has many Item. Both models are derived from the parent Model class. In order to retrieve the list of all items a particular user has: ...
1
vote
2answers
66 views

How to make this Regex more flexible?

I am creating a simple template engine that uses Regex to find special expressions, which are parsed and processed. They are enclosed in Ruby-style opening tags and have the format: ...
4
votes
5answers
2k views

User register script PHP

So, I needed to make me a register script for my website so pepole can register, and just wanted to know if It's okey. So, is there any vulns in this script i made?It works perfectly, just that i ...
1
vote
0answers
109 views

Few concerns about specific session class

I am having a few issues about a session class that I found after reading it a lots of times, Here is the class : ...
1
vote
2answers
315 views

A better way of writing a PHP function

As the title says, I'm looking for a better way of writing the following PHP function as it's a very very long one. It's part of a bigger class and I'm trying to keep the amount of code as little as ...
2
votes
1answer
318 views

Twitter Bootstrap CMS

Ok, so I started to build my own CMS. You can see Aleksandar Golubovic's Blog,and I need your help. Please, look at my code, and tell me is that safe? You can download current version from Twitter ...
2
votes
1answer
181 views

Optimize Clock Update Code To Prevent Bottleneck Resulting In Time Lost

I use the following PHP Code to output the user's local time and the servers time (office time). $local_time and $remote_time ...
-1
votes
1answer
130 views

(Procedural)(Snippet) MySQL to MySQLi. Any advice?

This is what i had before (using the MySQL api) ...
0
votes
1answer
167 views

Create loop to shorten this code up

I am new to programming as you can probably tell from the code below I am curious if there is a way to create a loop so I don't have so many copy's of the same code with only different variable names. ...
1
vote
2answers
4k views

echoing html tags in php

I have the following code below I was wondering if there is a way to clean it up/improve it especially near the if statements. I am new to programming and this is what I came up with and its working ...
1
vote
1answer
328 views

PHP File Serving code

I've been writing a small site which is essentially just a service API for other applications but deals with the caching and serving of files. In an effort to make the site as scalable and ...
3
votes
1answer
162 views

PHP First Friday Display Improvement?

I have an event recurring on the first friday of the month (at 7pm), and I need to output the date of the next first friday coming up. This is the first bit of PHP I've written, and I was wondering ...
0
votes
2answers
293 views

Submit function For Login

Trying to see if anyone sees any potential flaws with this submit function. One concern is this line: ...
5
votes
3answers
2k views

Storage class, dependency injection and singletons

In re-writing my PHP framework vervPHP, I've created the following class: ...
2
votes
1answer
245 views

Am I missing any security loopholes in this php script that reads and outputs directory/file from $_GET variable

Due to a weird server setup on one of my client's websites, I needed to setup a script to load referenced pdf files through a case-insensitive lookup. We originally looked into mod_speling, but it ...
2
votes
1answer
134 views

I've embedded several PHP/HTML/Javascript in one page. How can I improve on the efficiency/performance?

Just a quick preface, I'm not a web developer. I'm simply doing this as a favor for a friend. My goal is to be done with it as quickly as possible, but still not have the coding be horrendous. With ...
0
votes
1answer
2k views

Authentication system using AJAX

I'm building an authentication system using a combination of PHP, MySQL, jQuery, and AJAX. The way I'm doing it right now is I have a form that takes in a username and password. When the user clicks ...
-1
votes
1answer
72 views

Is declaring a property as `public` insecure?

I posted a question few weeks back, on making a PHP Login Script. Most of you guys told me not to use global variables and especially for something like MySQLi ...
1
vote
1answer
103 views

Suggestions for improvement of HTML table building function

User specification "var_dump($GLOBALS) is ugly as ... without wamp" General specification Produce a PHP function to display ...

1
76 77
78
79 80
85