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

learn more… | top users | synonyms

0
votes
0answers
6 views

Best way to use Data from Database (PHP, PDO, MySql)

I've been working in a small page with some easy CRUD. The data i get from the database is getting shown on the page. But the way how i show the data feels a bit off. I guess it can be done in a way ...
2
votes
3answers
36 views

Creating User objects

I'm creating a PHP object with an array of data: ...
3
votes
1answer
38 views

SQL result to JSON

I am trying to return a JSON object to an Ajax call. Is this the best way to build a JSON object with PHP JSON encode? ...
0
votes
1answer
41 views

Aliasing utility class method in extended class

Consider this setup: ...
1
vote
1answer
36 views

Obtaining weather station data from a MySQL database

I have a PHP page for a weather station that I'm trying to build. I run multiple queries to pull out data from a MySQL database for min/max/average values for temp, pressure, humidity etc. All of ...
3
votes
1answer
40 views

Authentication cookie handler class improvements

I just finished the following application service class that handles all my HTTP cookie authentication processes. It is the best I could come up with. Although I don't think I'm violating the SRP, ...
3
votes
1answer
31 views

PHP LDAP connection

I have this class, which helps me to connect to LDAP: ...
2
votes
1answer
22 views

SVG drawing code

How could I optimize this code / make it look better? Any advice on things I'm doing wrong? ...
4
votes
2answers
51 views

PHP Session Wrapper Class

I recently worked on a system for the company I work for and would love some feedback on the following class for managing sessions. I don't claim to be a PHP guru but I like to think I gave it a try! ...
3
votes
1answer
42 views

Function to count rows in a database query result

I have written this function that surprisingly works. (I didn't really know what I was doing; just a little experiment.) It is supposed to count rows selected by a PDO query. Is it well written? It ...
8
votes
3answers
322 views

Singleton Database wrapper

Before everybody yells at me about why I wrote a PDO wrapper class, it's to avoid writing try/catch, ...
2
votes
1answer
33 views

User entity of my domain v2

I would appreciate a thorough review of my updated User entity class. It's still an anemic domain model, but behavior (like ...
1
vote
1answer
28 views

Loop through post and use in query

so i'm using a foreach loop to loop through a form i've send with javascript. In this loop I use the keys(input fields names) and values(input values) and use them to build my query, I still check for ...
1
vote
1answer
51 views

Diving into PHP's MVC - the application's core

I recently started programming in php using the mvc-pattern, which resulted in one of best choices, I did so far, but I read through many articles showing "easy" examples and some of them were quite ...
2
votes
1answer
54 views

Encryption/decryption of a string with a salt

I have a new job coming up soon and want to increase my PHP knowledge. This is my first attempt at creating and using a class. I just want to know if it's the correct way to do things. It's very ...
-2
votes
0answers
18 views

Code to create addition and multiplication tables [closed]

I am creating multiplication tables and addition tables in php, but I am getting incorrect output when I try and run the program. It is supposed to just create a normal multiplication table, but ...
0
votes
0answers
30 views

creating addition and multiplication tables using user supplied data [closed]

I am creating my very first program in PHP and I need help making addition and multiplication tables. I have the HTML code that creates the table for the user to input data. I'm certain I have the ...
-1
votes
0answers
12 views

Making sure string doesn't contain http(s) nor doesn't start with a forward slash [closed]

I'm trying to append a root url to a redirect url, but ONLY if it doesn't contain http or https AND doesn't start with a ...
-2
votes
0answers
18 views

Are these the correct functions for creating a database connection,creating table,cleaning data for D.B and inserting the data in database in php? [duplicate]

Initialising variables Is this the correct code of the database connection function?( Assuming we have connected to the Database) ...
-1
votes
1answer
22 views
2
votes
1answer
35 views

Best practise way to handle array of pairs

I am trying to randomly select 4 items out of an array, each item has an index, a name and a price attached to it. Currently I have the following code segment to select 4 at random: ...
2
votes
2answers
87 views

Spreading MySQL query code over multiple lines - new lines vs concatenation

Is there any reason NOT to wrap a long query over multiple line via new lines vs using concatenation? For example, consider this: ...
0
votes
0answers
14 views

Undefined variable outside a foreach loop [migrated]

I've written code that grabs google fonts and adds them as an HTML body class. The code works fine but in my IDE, I am getting an undefined variable message. I can see why as the variable is outside ...
2
votes
0answers
48 views

PHP MySQLi database wrapper

I am developing a mysqli database wrapper. I've made an effort to make this as fast as possible and easy to use. However, now I want to start adding callbacks (for ...
5
votes
2answers
79 views

Average of averages

I need to get the average of multiple averages calculated basing on data contained on a sql database. To do that, I'm using this code: ...
2
votes
3answers
64 views

Including file based on user input: Efficiency and Security

Currently I'm using this code: ...
2
votes
0answers
67 views

Small PHP Router

I'm building a router for my MVC Framework. How can I make it better? What am I doing right/wrong? I have no idea about how best to handle errors. I would prefer to use exceptions - is this the right ...
1
vote
0answers
28 views

Is it long polling or short polling?

I wrote the following script and php code for long-polling architecture by googling references, I would like to know if this is long-polling or short-polling, ...because I am not sure: bc_test.js ...
2
votes
1answer
79 views

Any improvements for my LoginController class?

This is probably going to be my final question regarding controllers. I feel like I have a good enough understanding of them now and am able to write them cleanly. I've recently adapted a less error ...
1
vote
2answers
36 views

Reading certain values from an object

I'm trying to read certain values from an object. What would be the best practise to do so? ...
5
votes
1answer
37 views

Doing a roll back with multiple MySQLI prepared statement

This is my code for doing a roll back with multiple MySQLI prepared statement. I want to know if anything is wrong with the code. ...
1
vote
0answers
26 views

Fast implementation of SQL Queries in Key-Value Store

I have an existing MySQL schema without rows and have already made a list of all SQL queries I need. Now I know that Redis is a key-value store, so you can only fetch data by key and save for example ...
5
votes
0answers
109 views

Is my LoginView class valid?

I know the Model, Controller and View's purpose, but I have never really found a good concrete class example of a View class. Usually I see people having some small ...
8
votes
2answers
81 views

Improving performance of A* search in PHP

I need to figure out what can be done to improve the performance of a A* search algorithm in PHP. The idea is to look for the shortest path, in number of hops, between two points in a "map". Actual ...
1
vote
1answer
79 views

Structuring a user authentication system

I'm new to the MVC model. This is where I started: User authentication system. After questioning, reading and thinking a lot, I was able to write a small framework (don't know if 'framework' is the ...
2
votes
1answer
68 views

A wrapper class for Sessions in PHP

I have been using $_SESSION, $_POST, $_GET, $_SERVER ...
0
votes
0answers
11 views

Finding combinations of 3 numbers [duplicate]

What this code tries to do is find possible combinations of three numbers. eg. lets say the following numbers: 1, 2, 3, 4, 5, 6, 7 Some possible combinations of ...
2
votes
3answers
81 views

Finding combinations of 3 numbers

What this code tries to do is find possible combinations of three numbers. For example, let's say I have the following numbers: 1, 2, 3, 4, 5, 6, 7 Some ...
2
votes
2answers
62 views

Using jQuery and AJAX process a form with PHP

I'm looking to collect form input and pass it to a file called processing.php with AJAX JS: ...
2
votes
1answer
41 views

Create a state dropdown with an abbreviation option and a full option

I have this simple function here because I am too lazy to write out a state dropdown every time I need one. I already have an array with all the states set up, abbreviations as keys and names as ...
2
votes
0answers
44 views

Extracting data from an array of arrays, PHP style

I was browsing Stack Overflow recently and saw a PHP question about rearranging an array of arrays for printing. The initial data structure looked like this: ...
2
votes
1answer
67 views

Is my design achieving Separation of Concerns in this MVC implementation?

I've read lots about getters and setters being evil, unless there is good call for one, but I cannot figure out how to implement that knowledge into my Model layer. Say in my Model layer I have a ...
5
votes
2answers
58 views

Cron job that runs a few checks across different tables in database

I have been working on a cronjob that runs a few checks across different tables in my database. The issue is that although it works, I feel like I am doing something horribly wrong in terms of the ...
3
votes
1answer
39 views

Escaping photo caption to avoid cross site script attack

I am a PHP newbie and this is part of a gallery code. I recently read about SQL injection and cross site scripting attack, I am trying to avoid that by html escaping on dynamically produced data. I am ...
3
votes
2answers
99 views

Encryption-decryption method

My encryption algorithm I'm using this algorithm in order to encrypt notes users save on my site: ...
6
votes
2answers
240 views

User authentication system

I'm new to OO PHP and I'm trying to create a simple properly-designed user authentication system. What am I doing right and what not? Is this right according to the MVC model? ...
5
votes
1answer
128 views

Service class that handles form validations

I've made a (service) class to handle all form validation of my application. It contains a set of frequently used validation callables extracted into private methods that I use to build each ...
2
votes
1answer
15 views

Script for validating a booking form

This PHP script to validates a booking form. (There is also a JavaScript validation as well, but please ignore.). I want to know if there is a better/more efficient way of writing it? I have created ...
10
votes
1answer
187 views

Web application for a restaurant

I'm making a web application for a restaurant kind of type. The idea is to administrate the orders and customers. For selecting one of the orders and showing more specific data about it, I have this ...
6
votes
2answers
294 views

MD5 shuffling with a defined pattern of numbers

I've created a MD5 shuffler with a defined number pattern. Does this make sense? Will this make storing passwords more secure? Is it efficient? ...