Skip to content

Tag: php

How do PHP sessions work? (not “how are they used?”)

Session files are usually stored in, say, /tmp/ on the server, and named sess_{session_id}. I have been looking at the contents and cannot figure out how they really work. Fetching the variable name and and content from the file is easy. But how does PHP know what session belongs to whom? The session_id seems…

Image resize issue in PHP – gd creates ugly resized images

I am creating thumbnails of fixed height and width from my PHP script using the following function and I call this function with following parameters but the problem is the resulting image is of very poor quality, when I perform the same operation with Adobe Photo shop, it performs a good conversion.. why it …

PDO looping through and printing fetchAll

I’m having trouble getting my data from fetchAll to print selectively. In normal mysql I do it this way: In PDO, I’m having trouble. I bound the params, then I’m saving the fetched data into $rs like above, with the purpose of looping through it the same way.. Now comes the trouble part. Wha…

How to filter an array by a condition

I have an array like this: Now I want to filter that array by some condition and only keep the elements where the value is equal to 2 and delete all elements where the value is NOT 2. So my expected result array would be: Note: I want to keep the keys from the original array. How can I do

Mysql transactions within transactions

In a PHP script working with a mysql database, I recently had the need to use a transaction at a point that happened to be inside another transaction. All my tests seem to indicate this is working out fine, but I can’t find any documentation on this usage. I want to be sure – are transactions with…

PHPUnit: Verifying that array has a key with given value

Given the following class: And this testcase: How do I verify that $params (which is an array) and is passed to $Other->post() contains a key named ‘key1’ that has a value of ‘Value 1’? I do not want to verify all of the array – this is just a sample code, in actual code the p…

Access JSON object name in PHP

I have the following JSON: { “nickname”: “xadoc”, “level”: 4, “loc”: “Tulsa, OK, USA”, “score”: 122597, “money”: 29412.5, “streetNum”: 8, “streets”: { “-91607259/387798111”: { …