PHP is a widely-used, general-purpose server side scripting language that is especially suited for web development.
2
votes
1answer
24 views
PDO MySQL spaghetti coding
I'm new to this PDO PHP and I have coded this spaghetti style. I hope you can give me idea how to improve using prepared statements. I'm not a lazy person, but I really need your help to improve my ...
-1
votes
0answers
10 views
fputcsv is not working [on hold]
I have a html form which collects, name, place, email on submission it posts to csv file. But the php file creates a file without any data. Can any body help me in correcting the code. The full code ...
2
votes
1answer
85 views
Listing with JSON or plain HTML
I have a website which has reviews about games. Right now, to list the advantages (+) and disadvantages (-) of that game, there's a textarea in the admin panel with a WYSIWYG editor with only ...
1
vote
1answer
13 views
Loading Recent Posts In Session? [on hold]
I have a PHP code structure where I cash some pages in sessions.
Example:
I have a page which shows last 10 user posts, what I do is to load 10 posts and store then in session:
Page Class:
class ...
4
votes
2answers
45 views
Does this generic query follow good OOP standards?
I am trying to convert over to MySQLi and wanted expert advice. Is the enclosed code 100% OOP. Also, how secure is the code against attacks? I know nothing is 100% secure, but how good/safe is it? ...
2
votes
0answers
12 views
Updating number of article views - potential concurrent access issue?
I have articles on my website (built in PHP) and when an article is viewed the number of views is recorded back in the database. The SQL code snippet of my load method is:
SELECT *
FROM article
WHERE ...
2
votes
1answer
34 views
Best structure for a Person in PHP classes (and databse)
I am (in the process of) creating a system to store People and their details - names, date of birth (dob), addresses, phone numbers, etc. - and I'm curious how it is best achieved. Below is an an ...
1
vote
0answers
27 views
How to deal with some of the dependencies?
I am very beginning in PHP and Design Patterns. I have been studying the beautiful book "Head first: Design pattern" and I have been working in some of the codes originally presented in Java in order ...
3
votes
1answer
21 views
Display PHP Menu Stored in an Array and Looped
I'm creating a PHP website for a non-profit. They have some restrictions (no MySQL or pre-installed CMS) so I'm creating a CSS menu displayed by an unordered list where all of the elements are stored ...
5
votes
1answer
40 views
String concatenation of name parts
I have written the following function to concatenate the parts of a name to produce the full name:
/**
* Returns the full name of the Person.
* @param boolean $includeTitle Whether to include the ...
3
votes
0answers
44 views
Is this a good PHP strategy pattern?
I am a very beginning in PHP and Design Patterns. I have been studying the amazing Head First Design patterns. So, I have been trying to translate the original to PHP. The class is working well. ...
1
vote
1answer
44 views
Repository pattern with plain old PHP object
I've been reading a lot about repository patterns these days. At first, the pattern seemed easy.
Most of the examples I read over the web use an ORM like below.
interface MemberRepositoryInterface {
...
2
votes
0answers
29 views
Update PHP function GetSQLValueString
The old function was:
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : ...
3
votes
1answer
79 views
Is this contact form code breaking any rules?
Can you please review my PHP script below? It is for a contact form. Am I breaking any rules? Does it seem okay to you?
<?php
session_start();
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
...
6
votes
1answer
40 views
Bash script - automate an upload image + description process on a server
I was tasked at work to improve a system where through a web interface a client, which eventually became us, uploads a bunch of images with descriptions (latter coming from csv files), the images are ...
1
vote
1answer
72 views
Preventing email injection - Part 2
A day ago I have asked a question on here about Preventing email injection. I had some feedback and worked on it, and below is the latest update.
Could anyone please share their opinion? Is it ...
2
votes
0answers
51 views
Minecraft query tools
This is my first major PHP project and I haven't gotten much feedback and any feedback is appreciated! The quick rundown of the project is I wanted to learn how to use PHP and I wanted to learn about ...
0
votes
0answers
8 views
Convert numbers to words [migrated]
The following PHP code converts a number to written words. This works fine for an integer like 5250, however, when given a number with a decimal, it does not parse the number correctly.
450 would ...
3
votes
1answer
38 views
Best practice to create XML messages with DOMDocument class in PHP
I want to create XML messages for webservice communication. These messages should be created from a pool of reusable elements. Therefore I have created different classes. A "factory" class, that only ...
2
votes
2answers
83 views
Preventing email injection
I have asked a question on Stack Overflow and one of the guys actually managed to hack my contact form and inject a fake email into the $header of the PHP!
So after talking to him, he sent me a few ...
4
votes
1answer
53 views
Account-Creation form
How can I optimize the following PHP/JS code?
It works like a charm but I think it is too long and I'm sure it could be optimized. If I have another form, I'll need to copy paste some lines from my ...
4
votes
2answers
53 views
Parsing record-jar format in PHP 5.3
Here is a simple function I wrote to parse record-jar data. I need it in a php5.3 application to validate bcp47 language tags. It converts the language subtag registry among other things, into a ...
6
votes
3answers
97 views
JS validation and submission with AJAX
I've got an assignment to do pure JS validation as well as submit with AJAX. Here is the code I've got so far. I'm wondering if I can do away with the whole "reason" bit. That was because it was ...
-2
votes
1answer
32 views
pdo variable in select query [on hold]
i try change mysql code to pdo
and make this codes:
<?php
$jds="SELECT tc,tn,tb,tfz,tmz FROM teams WHERE leag='$lig' ORDER BY tmz DESC, tfz DESC, tzade DESC LIMIT 18";
$sth = ...
5
votes
1answer
62 views
Function that converts file eol's
I've been unable to find a PHP function that will convert eol in files. This is what I have so far. It works, no errors.
Your educated opinions, thoughts, improvements, potential bugs and ...
7
votes
4answers
1k views
Password checker in PHP
I have written a password checker using PHP, consisting of many if else statements. Is there any possible way to shorten this code?
function passtest($pass) {
if (!empty($pass)) { //check ...
3
votes
1answer
52 views
Best practice for generating jQuery dynamical content
I am new user of CodeIgniter and I am trying to build an application that there are lots of jQuery dynamical content.
Below I provide a code that I am using in order to be precise. The code below is ...
9
votes
1answer
93 views
Opinions on my HTML structure
I have spent the last 6 months as I am studying web development in college to build a website template that is responsive and accessible from as many devices and browsers as possible.
I would really ...
-1
votes
0answers
23 views
setting the right path for php command line scripting in windows [closed]
Good day I have been trying to set the right path for php in order to start new web applications in Yii.
My PHP is installed in the C:\xampp\php directory, but setting this path in my settings does ...
4
votes
1answer
43 views
A PHP Toolkit of some functions
Any major security risks? And please don't get angry over my novice log system.
<?php
function makesalt($lg)
{
$chars = ...
-2
votes
0answers
22 views
how can i add cache for pdo query? [closed]
i have this query but i dont update this table more than one time in week
how can i add cache to this query?
<?php
$jds="SELECT tc,tn,tb,tfz,tmz FROM teams WHERE leag='$lig' ORDER BY tmz DESC, ...
2
votes
0answers
24 views
Benchmarking PHP requests [closed]
I am using Apache ab to test one simple file and Zend application.
Zend application page is default page that comes with skeleton application.
And another file is show below:
$start = ...
2
votes
1answer
58 views
PHP session fixation
I'm trying to implement a system of restricted access. Right now I'm focusing on the "session fixation". I am concerned about the following aspects:
Control of a "fingerprint" of the user created by ...
5
votes
1answer
71 views
GIF to HTML5 video conversion
I'm still at a very beginner level and I'm constantly working on small things to try and develop my skills. I'm hoping someone could just give me a quick review if there's anything obviously horrible ...
9
votes
4answers
727 views
Human class implementation
I just want an indication as to whether or not I'm on the right track regarding PHP OOP, at least on a basic level. Positive criticism welcome.
P.S. Excuse the visuals of the code. This is how I ...
2
votes
1answer
99 views
How can I improve this PHP MySQL rank query?
In my db MySQL, I have a table ranks with many fields, one for each page I want limit access for the user in the menu application with PHP control:
<?php if ($row_ranks['padric'] == '1' ) {
...
-3
votes
1answer
49 views
Explain die() in PHP [closed]
die(json_encode($response -> RequestCallbackResult ? Vein::inst()->getWPPermalink(Vein::inst()->get('dialer_success_redirect')) : false));
What does this mean? Can somebody explain this to ...
4
votes
0answers
36 views
Is this a sensible way of using an IoC container?
I have a Factory class for a queuing system I'm playing around with.
Consuming classes only care that they get a particular interface (Job) as a result of calling the factory's load method.
Some ...
8
votes
3answers
545 views
Password hashing method
I am having some issue to use PHP5 password_hash() function. My server is not supporting it, so I am using a function to hash. Is this one secure?
public function Pass_Hash ($password) {
...
-1
votes
1answer
71 views
Is multiple return statements bad practice? [closed]
When learning computer science at university, I was told to only have one return statement in a method, and use a retval variable where necessary like this:
function foo()
{
$retval = false;
...
4
votes
2answers
48 views
Is there a way to shorten a set of conditionals like this?
I have a long set of IF statements that basically set a null object Value to 0, I feel that because i am doing the same action each time their has to be a simple way to make this allot shorter. It ...
3
votes
2answers
82 views
Parsing annotation
I have implemented code for parsing annotation:
/**
* @Route(path="sample \n test",code,value,boolean,test)
* @access(code=false)
* @sample as asdad asd
* asd
*/
function sample()
{
}
...
3
votes
1answer
107 views
Spam detection in PHP for comment system
I'am trying to build a PHP/MySQL/jQuery comment system. Off late I started to realize that manual spamming is a serious issue that need to be addressed carefully. So I thought of building a PHP ...
4
votes
1answer
60 views
PHP magic function for accessors and mutators
I have implemented the following PHP magic method behavior to save my time of creating accessor and mutators for properties of any class that extends this base class.
I am looking for suggesiongs on ...
5
votes
1answer
68 views
Best Practices concerning Includes and SQL Connect Strings
I'm just starting to learn PHP. I have three random questions about PHP and one question about Code Review. None of them are technical questions ("will this work?"); they're best practices questions ...
7
votes
2answers
119 views
Is this secure for a simple comment system?
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="style.css">
<?PHP
//Turn off error reporting (Not Necessary)
...
6
votes
2answers
67 views
Draw the table like 6³ = 3³ + 4³ + 5³ to 100³ = 35³ + 70³ + 85³
I want to draw the table like this:
6³ = 3³ + 4³ + 5³
9³ = 1³ + 6³ + 8³
12³ = 6³ + 8³ + 10³
18³ = 2³ + 12³ + 16³
18³ = 9³ + 12³ + 15³
19³ = 3³ + 10³ + 18³
20³ = 7³ + 14³ + 17³
.....
100³ = 35³ + 70³ ...
8
votes
1answer
199 views
PHP form review
I saw somewhere on here that it helps reduce spam by adding a dummy input field that you hide with display: none, and like if it's filled out, then it's obviously a bot sending the message. Well, I ...
4
votes
0answers
92 views
Codeigniter Login Controller
Instead of creating an Admin_Controller or MY_Controller I was going to try and just try out all my controllers on requirements that are needed per controller. I know this may seem like additional ...
4
votes
1answer
30 views
Simplifying an associative array()
Would it be better to convert the array in the following code to
$langs = array("en", "de", "fr");
and then reusing the values for both $folder and $flag? If so, how then would my foreach (or maybe ...