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

learn more… | top users | synonyms

-4
votes
0answers
22 views

how to create subdomain using php [on hold]

I have hosting with a cpanel accelerated 2 panel here I can manually create a sub domain but is there a way to create a sub domain with a php script so they input the sub domain they like then click ...
3
votes
1answer
43 views

Help me shorten my URL shortener

I am working on a website, and due to some reasons, they want my code to be as short as possible. I have, from my side, tried everything to shorten this code. So if possible, can you all also help me ...
0
votes
0answers
46 views

Reach memory limit with nested loops and dates query [on hold]

Disclaimer: I am aware that I have in my code deprecated MySQL functions. That is on my todo list. I have a database table with seasons for bookings. The data is like: ID House ...
1
vote
1answer
40 views

image rate system

I'm developing a site, which has an image upload section, and members and like the image, but a member can like it only once.. I have a table, named uploads which has columns id, ...{more ...
0
votes
1answer
49 views

Writing a static Log class for PHP

I wanted to write a simple Log class for PHP, I use ajax calls with AngularJS and often return the log in an array Example: $return['data'] = $returnedDataArray; $return['log'] = $logDataArray; ...
0
votes
1answer
25 views

Need review on concatenation [closed]

I am trying to concatenate the echo statements but I am failing. Also any other tips are appreciated in your review. <?php // load all 'category' terms for the post $terms = ...
4
votes
1answer
46 views

Optimize MySQL double select inside for-loop

I want to get the number if items with state 4 and 1 from my database for each day between a certain date. Is there a smarter and more performative way than this one? I am aware that I should use ...
0
votes
1answer
81 views

Understanding Dependency Injection and Inversion of Control

I have recently been looking into the concepts/patterns behind dependency injection, inversion of control, and registries/service locators. I have searched about the internet on the subjects and have ...
3
votes
2answers
92 views

My API Keygen: Is it secure?

Below is an api key gen script for a cryptocurrency trading platform i am building. first it checks to see if a key exists in the db for the user id. if it does exist it displays the key. if it ...
0
votes
1answer
36 views

Evaluating a hashing function used to create secure API key

What are your thoughts on the following code? is it secure enough? Note: $password is used to represent the secret, which would essentially be a SHA512 hash of username . password . ...
5
votes
2answers
68 views

Do you see any flaws in these prepared statements to avoid SQL injection?

I have used this guide to implement prepared statements in order to avoid SQL Injection. I made some tests and no error was shown. However, I would like to ask you if you see any flaw in the code, so ...
0
votes
0answers
18 views

I don't know if my database is updating correctly with affiliate cookies [closed]

I want to know if this PHP page is set right to update the database and also to store the affiliates details as a cookie that sent them to the program. <? require("config.php"); $today = ...
1
vote
0answers
38 views

PDO Login/Register system review

I wrote my very first login/register PDO system today. I know there is still a lot of flaws, but I was wondering what tips and advice you have to help me improve this. I know that PDO is much more ...
0
votes
2answers
28 views

Codeigniter - in the view or in the controller?

Is this correct? Or am I overloading the responsibilities of the view? <table class="table table-striped table-hover"> <thead> <tr> ...
1
vote
1answer
60 views

Display the relative time difference between two dates

Goal: To create a function that returns the relative time difference between two given timestamps, using the DateTime class. Current approach: function time_elapsed($date1, $date2) { $dt1 = new ...
3
votes
1answer
57 views

Possible improvements on admin login area?

I've created an admin login area for an application I am planning to code, and I've used the following login.html page to let the user type in his data (I left out parts like "id", "placeholder" etc. ...
3
votes
1answer
47 views

Need Loops for PHP Username/Pass Encryption Script

I've created this PHP script to print a batch of usernames with encrypted passwords locally on my computer because the user/pass format is always the same. username = username password = ...
0
votes
2answers
59 views

Remove a parameter and its value from URL's query string

I'm coding an algorithm to remove a parameter (let's call it foo) from URL strings. Of course, after the foo parameter removal, the query string should remain valid (with a leading ? and remaining ...
0
votes
1answer
38 views

How to put a lot of information in the class?

I have such a problem: I'm parsing a lot of HTML files with Simple HTML DOM Parser, that's why I need to use three foreachs to parse the necessary information from it -> I am getting a lot of ...
0
votes
2answers
48 views

Dumping a MySQL database to a file using a PHP script

I know there are countless questions on SO, and several articles on the web regarding this subject, but after looking at all the options, I was moved to write my own code to address my own ...
1
vote
2answers
81 views

Is calling a function from within another to alleviate code duplication the best solution?

I am writing up a class to handle various templates to be used in a web application. Each template contains various placeholders which will need to be replaced at the time of the build. I a wondering ...
3
votes
1answer
43 views

Escaped explode/implode function

I had a somewhat interesting issue. I had to take an array and turn it into a string with a set of delimiters; then later on take that string and turn it back into an array, splitting at the same ...
2
votes
1answer
59 views

Codeigniter: loading content in page via jQuery

Hi I'm doing a web site in codeigniter and I'm loading the content page via jQuery, but I don't know if this is a good practice or not. Could I improve it? Thanks. jQuery // Another question here, ...
2
votes
2answers
82 views

How safe is my encrypt/decrypt PHP function?

I have to protect really sensitive information and I have to do it both ways: encryption and decryption. I'll be using this PHP code: function encrypt($mprhase) { $MASTERKEY = "KEY PHRASE!"; ...
0
votes
0answers
18 views

Should I pass an object or values? [migrated]

Let's say I have a model that has 'purchase' method. The purchase method should take care of purchasing a product. Signature of purchase public function purchase($token, Model_Member $member, ...
2
votes
0answers
73 views

How to improve this code for testability?

I'm trying to improve the following code for testability. public function can_apply_extension() { $search_dates = [ ...
3
votes
2answers
56 views

Structure of API wrapper

I'm building an API wrapper for a bookkeeping SOAP API. I have some questions regarding bast practice for structure of the wrapper and for error handling. For now i've structured it like this: ...
0
votes
0answers
32 views

How can I automate the process of code review [migrated]

I have a team that works on multiple technologies. I want to know how can I automate the process of code review for .Net, .Net MVC, Python, PHP, Drupal and HTML5/CSS with JavaScript. I have read ...
2
votes
1answer
58 views

Review my PHP class?

I've inherited a class in a project which is purposed to execute a function that exists in POST data from a specified class. I've tried to clean this up as much as possible as well as secure it ...
4
votes
1answer
60 views

Need help optimizing PHP/MySQL code snippet

I am sorry for the simple request, but I'm trying to figure out the best way to optimizing the following bit of code. I hate using 20 lines of code when 12-15 will suffice. I also don't like having ...
4
votes
1answer
71 views

Make this MySQL query more elegant &/or efficient

I have created a MySQL query that works, but I feel there must be a better way. The query will be used by a PHP script whose purpose is to assign conditions & subconditions to new participants in ...
1
vote
1answer
45 views

Copying a lot of code to filter four PHP arrays

I have made this search filter and it works fine, but I think the code looks a little messy and I have no idea how to clean it up. I hope the following makes sense, otherwise please tell me which ...
0
votes
0answers
29 views

Querying data from different databases, then FTPing the results

I have a script running that will read a configuration file that looks similar to this: [site1] db_name = "site1_db" user = XXX pass = XXX [site2] db_name = "site2_db" user = XXX pass = XXX The ...
0
votes
1answer
77 views

Best way to check mimetype and upload a file

i'm using this method from my Downloads() class in a back-end admin system, where these can upload some files, wich must be .rar or .zip I'm not to concern about filesize, yet. Eventually, these ...
0
votes
0answers
81 views

Does this signup form look secure enough?

Does my PHP look secure enough for a sign up form? <?php $con=mysqli_connect("host","user","password","db_name"); $sql="INSERT INTO users values (?, ?, ?)"; if ($stmt = mysqli_prepare($con,$sql)) ...
0
votes
1answer
77 views

In-memory data cache architecture for data transfer

I am writing a cron job to manipulate and transfer remote data. I need to cache data from a table, process it, merge with previous table, iterate the process, and eventually send the result data to ...
0
votes
2answers
67 views

PHP starting OOP MySQLi singleton

this is my first post on the whole StackExchange network, so I might make some mistakes. And I'm also spanish spearker, so I'll probably have mistakes in my writting too.. Context: I'm starting with ...
2
votes
1answer
73 views

Converting entire table to JSON data. Is there a better way?

Building a 'card' database: I'm simply learning to take input data and store to database. Incorporating JSON, PDO, SQL, and enforcing my general coding skills through PHP, hopefully. $query = ...
1
vote
1answer
86 views

Updating visiting dates of each visitor

I am still a PHP beginner. Please review/improve my PHP code and reveal errors, typos and warnings. <?php date_default_timezone_set('UTC'); $connection = mysqli_connect("localhost", "root", ...
2
votes
3answers
76 views

Make code more memory efficient, or shorter

//rename files if(!empty($_FILES[$desktop_fieldname_1280x800]['name'])){ file_exists($desktop_filename_1280x800 = mb_strtolower($desktop_dir_1280x800 . 'wall_desktop_1280x800_' ...
0
votes
0answers
16 views

Handling repository classes dependencies on other repo classes

As my application grows I'm finding the repository classes are utilizing a pattern that could be thought of as a repo locator. It's testable by overloading the locators config, but having a single ...
4
votes
1answer
58 views

Converting a 32bit number in a proprietary timestamp with PHP

This is a copy of a posting I made on SO, it was suggested I post it here all I've changed from that post is I'm now doing the bitwise AND using a decimal number rather than using bindec("111") to ...
1
vote
2answers
180 views

Finally got a fully working countdown timer working but looks horrendous!

Being new to raw javascript, intervals and times this was not the easiest script to come up with, and thus, although it seems to be working as I want it too the code looks very clunky. The timer ...
2
votes
1answer
72 views

Using a variable in a for loop: is it proper practice or is there a better approach

The goal of this code was to create a table from an associative array. I need to create horizontal rows where the keys need to be used as "headers" while the values are posted below each header. ...
2
votes
1answer
30 views

Add HTML to the page using a PHP Class

I was trying to make my life easier making a class or something that would create HTML tags in a faster way. I ended up with something that I wouldn't consider the best practice. Take a look: /** * ...
1
vote
1answer
42 views

Pushing instantiated class in an array

I've just stumbled upon something today that seemed "unethical" in PHP. What I originally thought as malpractice, turned out to work just fine. Basically what I was wondering is if pushing an ...
0
votes
0answers
13 views

Text conversion - Javascript before saving to db, or php when retrieving? [migrated]

Long story short, I have a social networking site I wrote a while back as a "proof of concept" to myself that I had the skills to do it. I decided to revisit it, and "improve" a lot of the bad ...
0
votes
2answers
55 views

Optimize this path location script?

Example Script is located in /home/insp/public_html/deploy/ I want to return the /home/insp/ section $path = realpath(__DIR__); $parts = explode('/', $path); $newPath = array( ...
1
vote
0answers
24 views

Take an array and return “n” elements, as evenly spaced as possible

I get the following correct results from this code, but it seems incredibly clunky to me. Is there anything I could be doing more elegantly? The results can be imprecise - as long as it's the right ...
-3
votes
2answers
63 views

I need help with integer division in PHP [closed]

I had a bit of code in BASIC I needed to convert, but specifically this following line has me stumped atm: NRSLATHOR=INT(LSLATVER/PITCHVER-.8) In PHP I'm attempting to do an integer division but I ...