php

Beginner array problem, extracting items from a 2D array to list and manipulate

Hello, I am learning arrays in PHP and would like to know how to do something like extracting and calculating items in a multidimensional array, for a small receipt exercise I am attempting: $products = array('Textbook' => array('price' => 35.99, 'tax' => 0.08), 'Notebook' => array('price' => 5.99, 'tax' => 0.08),...

PHP pagination and sorting

I'm currently working on an in-house CMS and have come to a bit of a standstill. I'm trying to make it easy to paginate between pages of posts in a blog, and can't decide on how it should be tackled. The real problem only arises when I need to allow a user to choose how many results to display per page or the order to sort posts in. My ...

comparing images programmatically - lib or class

My objective is to supply 2 image files, and get a true/false response as to whether these 2 files could be the same (within an acceptable degree of certainty). I realize this question falls under artificial intelligence and is much more complex than it appears, so I highly doubt I could (or would even want to) do it myself. What I'm l...

Stream binary file from MySQL to download with PHP

I have Excel spreadsheets stored in a MySQL table longblob field. I need to retrieve this data and then stream it to the user as a downloadable file, preferably without writing it to disk first. Possible? Edit - Eh, just figured it out... Posted in answer below. ...

Cannot set current _timestamp or now() with PDO on MySQL

I use PDO prepared statements in a Web application I'm building. I have a timestamp column set to current_timestamp as default value. Using a timestamp should normally assign the current timestamp when the column value is null, same as now() would do. But no matter what I try, I get a NULL value if I set the timestamp column to null and...

check if download is completed

Hello, My question is - What is the best possible way to detect if a download is completed, because after that I want to update the database. I try'd some of this code from php manuel, but it doesn't do much for me. Header ( "Content-Type: application/octet-stream"); Header ( "Content-Length: ".filesize($file)); Header( "Content-Di...

Calculating a users involvement/activity

Hello all, I have a website that calculates a users involvement/activity using multiple MySQL queries. For a typical user I will ask: How many updates have they made? How many photos have they uploaded? etc etc. These are just basic COUNT queries on the relevant tables, updates, photos. I then total the COUNT values of each to get a ...

Help with Supertype/Subtype? (and categories..)

I have a service table. Each service is defined by 1 main category and 1 sub category. For example, Service = Joe's Web Company, MainCategory = Information Technology, SubCategory = Web Development Each service offered will have a common set of properties (cost, location etc) Each service will also have a set of attributes specific...

How can I determine if something is an array or an object in PHP?

Hi, What is the best way to determine if something is an array or an object in PHP? I get a response from a web service and it's either an array or an object depending on how many returned results there are. It is impossible to predict ahead of time how many there will be, so I need to figure out how to process it appropriately. What...

Can a client view server-side PHP source code?

I'm developing a PHP application that has to respond to request from several clients, and I thinks "Can any of the clients see the PHP code that I'm writing?". ...

WebServer for existing app

We have an existing windows desktop app written in C# 6 that uses an MDB MS access database for its storage. I need to write a web interface that can read that php webpage and maybe write to it later on. This web interface will be included with our current installer for the application or as a simple addon. The user should only have t...

Secure way to include page from GET parameter?

I'm working on a set up where the URLs will be along the lines of: http://example.com/index.php?page=about In reality they will rewritten to that from a simpler URL. index.php will include another page, using this code: if ( isset( $_GET['page'] ) ) { $page = $_SERVER['DOCUMENT_ROOT'] . '/pages/' . $_GET['page'] . '.php'; if ( is_f...

quoting constants in php: "this is a MY_CONSTANT"

I want to use a constant in php, but i also want to put it inside double quotes like a variable. Is this at all possible? define("TESTER", "World!"); echo "Hello, TESTER"; obviously outputs "Hello, TESTER", but what I really want is something like: $tester = "World!"; echo "Hello, $tester"; ouputs "Hello, World!". ...

How Do I make a simple .htaccess internal redirect Catch All script while forwarding POST data?

I just want to catch all requests and forward them internally to my catchall page with all POST data intact Catch all page: http://www.mydomain.com/addons/redirect/catch-all.php I've tried so many combinations, but my server doesn't want to redirect internally if I specify more than catch-all.php # Internally redirect all pages to "Ca...

SQLServer data in PHP loses multibyte characters

I have PHP talking to SQLServer through ODBC using FreeTDS and unixODBC. I followed tutorials to get this setup. It's working fine now although special characters in the database are not showing up correctly. Specifically, the ™ symbol. It's showing up in the browser as �. I've tried setting client charset = UTF-8 in the [global] se...

How to prevent rewriting href attributes when rewriting urls?

Hello, on my web site i want to change url's from (just exemple): site.com/showCategory.php?catId=34 to: site.com/category/34/ Here is the contents of my .htaccess file: <IfModule mod_rewrite.c> RewriteEngine On RewriteRule ^affichage/([0-9]+)$ /affichage/$1/ [R] RewriteRule ^affichage/([0-9]+)/$ /affichage.php?n=$1 </...

How to fetch a resource through a php script?

I am trying to do the following in my web application: <img src="static.example.com/image01.jpg?width=300&height=300" /> Is it possible to have my server (I use Apache in a shared hosting environment) run a PHP script when accessing a .jpg (or any filetype that I chose) instead of just serving the file? I know that the PHP script ha...

why is php complaining about passing by reference in this code?

$test = 'love'; $eff = end(explode('ov',$test)); I can't figure it out; oddly enough, this doesn't get a complain: $test = 'love'; $eff = current(explode('ov',$test)); The error I'm getting is: Strict: Only variables should be passed by reference ...

Problems with PHP PCRE

I'm having a problem with PHP PCRE, and I'm used to POSIX, so I'm not too sure about what I'm doing wrong. Basically, this function is matching up to 10 numbers separated by commas. However, it's also matching the string sdf (and probably many others), which I don't see the reason for. Can anyone help me? $pattern='^\d{0,5},? ?\d{0,5},?...

Error pointing to "line 0" in PHP.

Using PHP 5.3.0. I know you can get errors pointing to line 0 when executing code from the shell (with php -a or php -r). I also know you can get line 0 errors when an exception is thrown during the process of executing a custom exception handler. These are logical reasons why PHP might not be able to provide me with a line number for a...