Tagged Questions

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

learn more… | top users | synonyms

1
vote
0answers
20 views

File uploader in php

I can't get a peer review where I work, I was wondering how my code was and how could it be improved. https://github.com/lamondea/uploader Is it a good practice to use functions in classes or should ...
1
vote
1answer
14 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: $id = $this->input->post('id'); $query = ...
1
vote
0answers
19 views

mvc example: form post

I try to improve my code: separate html/php, much clear, next time change will be easier. After do research about MVC/OOP, I made below code for example to learn, I understand this is not the MVC ...
-1
votes
1answer
28 views

What are these bitwise operations doing? [closed]

I found a snippet of code on the PHP manual which packs 64 bit integers. APparently this is necessary because pack() always treats numbers as 32 bit integers even on 64 bit architectures. I don't ...
4
votes
1answer
55 views

Array find min value with user-defined comparison compare function

My user defined comparison compare function is defined with an array: $boardkey_to_values=Array(19=>2601248,23=>2601248,39=>2603445, ...
3
votes
1answer
32 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 ...
2
votes
1answer
52 views

How to fork with PHP (4 different approaches)

I thought about three (now four) different ways how to execute forks with PHP. What is the faster, maybe better solution and why? PHP script included foreach($tasks as $task) { $pid = ...
1
vote
2answers
54 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
75 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 ...
2
votes
1answer
77 views

How to properly store error messages and display them with OOP?

I have a class that I am using to initialize a form for editing. Once the form is submitted, data validation is done through the setters of my class. Good or bad input will be set in order to ...
2
votes
0answers
50 views

Instantiating objects in a MVC in PHP

I am working on converting a PHP application to MVC, and have a couple questions! 1) I have a main Model object, that I require a database connection for, as well as a User object that uses a ...
3
votes
1answer
47 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. ...
4
votes
1answer
71 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 ...
0
votes
2answers
49 views

PHP PDO Custom class ple

i created a database class from a good tutorial and wanted to put it up here so it would get in some search results. it took me about 2 days to find it. also i added a few custom functions to it.. ...
1
vote
3answers
65 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? function url_clean($str){ $str = iconv('utf-8', 'us-ascii//TRANSLIT', $str); $clean_str = ...
1
vote
0answers
46 views

Simple event mediator

I was trying to explain the mediator pattern to a new developer, and ended up writing a simple event mediator. Thoughts? EventMediator class EventMediator { private $events = array(); ...
3
votes
2answers
71 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 ...
-2
votes
1answer
54 views

PHP: what does this code do? [closed]

can somebody please explain this code for me in simple steps. thanks in advance $text = 'we need to send products ACE66765, ACE33453, and ace72345 back to the customer.'; $regex = ...
0
votes
0answers
50 views

hooks class trying to understand them

I built a small "hooks" class for adding some capabilities of basic plug-in functionality. Is it room for improvement?I am just beginng learning oop so don't be to harsh :D I got 2 method's for ...
1
vote
2answers
81 views

PHP Class Inheritance / Object Instantiation / Object / Property Scope w/ Child / Parent Classes & Dependency Container Class

In PHP, I have a parent/child class and am using dependency container to load them. I am trying to use the same database connection on all of them without duplicating the object. CLARIFICATION: MY ...
0
votes
1answer
42 views

PDO connection / prep and execute in there own functions

Currently changing some legacy code over to PDO, below works but not 100% if its best practice or if anything can be done better Cheers //Database Array $config['db'] = array( 'host' => ...
1
vote
2answers
48 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
2answers
35 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: <% label ...
1
vote
1answer
34 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: $user = new ...
1
vote
1answer
36 views

form validation php

i have a simple form validation script. Could you tell me how i can improve this script(mainly regarding security)? Html Page <form name="input_form" action="process_form.php" method="post"> ...
2
votes
1answer
61 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
114 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 ...
0
votes
0answers
21 views

get data from fullcalendar under fullcalendar in codeigniter

I want to ask, how to display data in fullcalendar plugin http://arshaw.com/fullcalendar/ in codeigniter view, so that when I click on the change month in fullcalendar data displayed below with the ...
0
votes
1answer
36 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 : class SessionManager{ static function sessionStart($name, $limit = 0, $path = '/', ...
0
votes
2answers
127 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 ...
0
votes
1answer
55 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 ...
3
votes
1answer
75 views

Breakable MVC framework written in PHP

I've written a framework in MVC, I call it Midget MVC, as it's so darn small. The reason I wrote it is because I wanted a lightweight and extendible framework to use in projects. It eventually got ...
1
vote
0answers
35 views

Performance improvements PHP GD resize and trim image background keeping the correct ratio

I developed an image resizing & trimming class using PHP GD library. I used skibulks image trim script from here (thank you guy!) to trim the image background in the first step and scale the image ...
1
vote
1answer
32 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 are the corresponding UNIX timestamps: <span class='icon-time' ...
2
votes
1answer
55 views

Trying to understand appropriate routing in MVC

I am learning MVC, and trying to understand routing. I understand that if I want to show an individual blog post for site.com/54, my route would be something like //index.php $controller = new ...
2
votes
4answers
141 views

Is there a way to remove this switch case?

I'm building a symfony project and at some point I've come up with a switch case to manage the acl rights. I would prefer using a dynamic access to the constant but havn't find a good solution. I've ...
-1
votes
1answer
38 views

Optimisation for random generator code in PHP [closed]

I'm really confused about combining MySQL queries and please could you lend me a hand? Please explain in simple English. The code is: $result1 = mysql_fetch_assoc(mysql_query("SELECT COUNT( * ) ...
2
votes
1answer
72 views

Routing, Navigation and State in MVC

I am attempting to refactor my app using the MVC paradigm. My site displays charts. The URLs are of the form app.com/category1/chart1 app.com/category1/chart2 app.com/category2/chart1 ...
1
vote
1answer
40 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 ...
0
votes
1answer
57 views

Cleaner more efficient way of multiple database queries

I have the code below I probably did not need to post the entirety of it but you can see in the code that I make multiple data base queries to generate each of the multiple tables. I am curious if ...
1
vote
2answers
70 views

Basic PHP comment form: what ways can I improve security, efficiency/cleanliness, or conventionality?

I am a programming novice. I've written this simple PHP script to run a very basic comment form and would appreciate any feedback, especially on these three topics: Efficiency (not sure the right ...
2
votes
1answer
47 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 ...
1
vote
1answer
163 views

Is this PHP class good enough for CRUD

I wrote this class to make it reusable in any project. It uses PDO as the MySQL connection. Beside not using Setters and Getters, is this code secure and good practice for CRUD ? Thanks for further ...
0
votes
1answer
85 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 ...
0
votes
2answers
121 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
1answer
97 views

PHP, cleaner way to determine and load page template

I feel that my current business view logic is not efficient or very clean.. the trouble is building the right output, but with less code and more DRY. I have 3 'static' links, as in, direct tags: ...
0
votes
1answer
43 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
65 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 ...
1
vote
1answer
94 views

PHP - is my code efficient?

I am basically getting data from various APIs and using PHP to put them together - like a web mashup. I am currently using 4 foreeach statements to insert the gathered data into their individual ...
0
votes
2answers
54 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 2 3 4 5 16