PHP is a widely-used, general-purpose server side scripting language that is especially suited for web development.
1
vote
1answer
28 views
PHP generic array group by using lambda
K.I.S.S
But how about some error and misuse control? I am wishing it were .NET HAHA.
<?php
function array_group_by($arr, $key_selector) {
$result = array();
foreach($arr as $i){
...
-1
votes
1answer
33 views
PHP shopping cart [closed]
When i submit there is only one product from cart on mail, last one and total price is calculate all item but i cant see them on mail
function emailcartview() {
$total=0;
$totalvalue=0;
...
1
vote
1answer
82 views
Looking for architectural feedback on my PHP MVC Framework [closed]
I wrote this a while back:
https://github.com/chintanparikh/Serene
I'm looking for feedback on the architecture/Object Oriented Design of the framework.
What I thought was neat: In the COre folder, ...
1
vote
2answers
40 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:
function is_clean($string){
...
2
votes
1answer
34 views
Scope Resolution Operators and class variables in PHP OOP
I am new to this site, so I apologize if this question is not welcome. I am also new to OOP in PHP. I have done a lot of research on OOP and I keep seeming to read different opinions on several items, ...
3
votes
0answers
47 views
Optimizing PHP script fetching entire HTML pages
The following script should get links which are stored in a text file (line by line), then put them into an array and finally scan each links' source code for a certain line. If this line is found, it ...
1
vote
1answer
108 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 ...
1
vote
1answer
37 views
How to optimize the pagination query?
This is completely optimization question, I have a pagination query like that
$this->paginate = array(
'fields' => array(
'DISTINCT Contact.contact_id',
...
2
votes
2answers
91 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 ...
3
votes
1answer
72 views
Review my PHP login and register script, and profile page, and how to improve them
There are some things that I know that need to be fixed, such as mysql_* needing to be converted to PDO, and using a better hash. I am working on building a social networking site, and I've been ...
0
votes
0answers
16 views
Why would my CakePHP model not save to the DB [closed]
I added a custom function to my Model that would take a message and a user id and write the message to a table. It is a simple event logging procedure. I can confirm that the function gets called ...
6
votes
0answers
119 views
Thoughts on my brainfuck interpreter?
Had some free time this weekend and I hacked together a small Brainfuck interpreter, with the sole intention of explaining PHP's flavour of OO to a friend. This is a bit over-engineered on purpose, ...
2
votes
0answers
36 views
proper convensions in PHP - admin page example
I'm learning php. I've designed the basics of an admin page i'd like to use for a small web site. I'd like to know if I'm using the language properly. Please rip apart the code and tell me where I ...
-1
votes
0answers
25 views
A markdown syntax tester [closed]
I have created a Markdown tester, built on top of PHP, Yii Framework, Twitter's Bootstrap and Markdown-Pagedown JavaScript plugin used here on Stack Exchange Network sites.
My tester is a paste-bin ...
0
votes
2answers
54 views
Is there anything wrong with this string array creation in c#,php? [closed]
I think the method for building a string array in C# and PHP is a little to verbose.
C#
string[] my_string_array = new string[]{ "This", "is", "ugly" };
PHP
$my_string_array = array( 'PHP', 'is', ...
0
votes
1answer
43 views
php script to get field type from sql table
I have an sql table with multiple fields and 4 of them are enums. I wrote a script that runs thought the table and retrieve the enums and put them in a 2 dimension array.
Unfortunately this script is ...
1
vote
2answers
62 views
Small factory class
class ControllerFactory {
public function createController($controller)
{
if (file_exists($path = __DIR__ . 'app/controllers/' . $controller . '.php')) {
require_once ...
1
vote
1answer
23 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.
if(isset($this->params['url']['next'])) {
$url = ...
0
votes
0answers
34 views
Dealing with no value for 'date' type in MySQL and PHP
In previous projects I've stored non-values for the 'date' type field before as:
0000-00-00
However in a recent MVC based project I found this was causing issues, as I was creating an object in the ...
3
votes
2answers
55 views
Check if the shop is open or closed
The working hours are saved in Database like
{"1" : "11:00 - 14:30", "2" : "17:30 - 23:00"}
Now i wrote a function like, which test is the shop is opened or close at the moment. Can someone please ...
2
votes
0answers
28 views
Reduce size of multiple uploaded images
I am a young programmer with the ability to learn more. I created a public site where a user can upload multiple pictures at once. The code works successfully and inserts the images into a MySQL ...
1
vote
0answers
24 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 ...
0
votes
2answers
77 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 ...
0
votes
1answer
18 views
PHP recursive function running ever so slowly
Please consider the following PHP function. It's objective is simple: given an ASCII string, to replace all ASCII chars with their Cyrillic equivalents. As can be seen, certain ASCII chars have two ...
0
votes
2answers
52 views
PHP MVC simple sign up form review? Please be honest :)
I have tried to build my first MVC sign up form here is the code.
Here is the user controller method register.
public function register() {
if($this->isPost()) {
$user = new ...
4
votes
2answers
91 views
How can this PHP control structure be improved?
Is this an ideal use of if..else or can this code be simplified/beautified further?
// If any image found and bigger than thumbnail settings, get that one
if ( isset( $matches ) && ...
2
votes
0answers
77 views
Which of these OOP examples demonstrate proper OOP concepts? [migrated]
I'm still trying to wrap my head around OOP. All of the following examples work, of course, but is there one (or possibly another) that best exemplifies OOP concepts?
/**
* For the following ...
1
vote
2answers
23 views
MySQLi Code Review for methods and functions used
I made my first script of MySQLi. I have just learnt it from 3rd party website. So, I am not sure i am using functions which are not deprecated or outdated. I should start to practice good scripts to ...
1
vote
1answer
41 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?
<?php
// MOBILE
...
3
votes
2answers
44 views
Function that Loads a Random Image from an Array
I'm new to PHP and had to put together a function that loads a random image from an array (it works fine). Here's what I came up with. Could it be improved? Any feedback would be appreciated.
...
3
votes
1answer
29 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?
<?php if ( $user_ID ) : ?>
...
4
votes
2answers
146 views
class and object in php
i just wanted to confirm if my codes below is correct. Feel free to make corrections.
<?php
class createConnection
{
var $host="localhost";
var $username="root";
var $password="";
var ...
3
votes
0answers
30 views
Thoughts on organizing code for multiple mysql queries in php scripts
I have a web application where I connect with a MySQL database using PDO and in some scripts there are a lot of queries one after the other which don't necessarily concern the same tables. i.e I will ...
1
vote
0answers
41 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
30 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
33 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
31 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
64 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
42 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
61 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
58 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
81 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
83 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
61 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
51 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
87 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
54 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
69 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
49 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
91 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 ...