php

PHP - Good practice to apply multi-level PHP User Authorization

Hello all, Given a website site has different web pages that can only be accessed by different group of users. Say guest users can only access welcome page/search page, while, administrator users can access pages that update the DB, etc. I have little experience on this field and would like to adopt some best practice with clean/simple...

How to use nginx with PHP?

What is a good way of using PHP with nginx? From the finding I got, maybe using PHP-FPM might be a good way of handing PHP behind nginx. The problem we have is that the free web based API we serve gets a lot of request (about 500K a day), mostly the requests are very short and small in size but Apache is consuming a lot of memory. I wa...

The server at www.localhost.com is taking too long to respond.

Hello all, A very strange thing is happening. I am running a script on a new server (it works on my current server and laptop). The strange thing is that I only get it to (sort of) work when I increase memory limit to 1024M (!). It is extracting a large zip file and going through the files, so I thought it was normal. Instead of this s...

How to extract and save/read XML email attachment from stdin pipe?

I have an email address piped to a php script which can catch the inbound data. The thing I need out of the email is the XML that is attached. I need to extract the XML attachment into a variable so I can parse it and do stuff with it. I have the parsing routine down without an issue since I use it now fopen'ing data that I get using ...

Reading a simple xml using php

<key><name>testing name</name><result>success</result></key> My PHP code: $doc = new DOMDocument(); $doc->load( 'key.xml' ); $result = $doc->getElementsByTagName( "result" ); echo $result->item(0)->nodeValue; I just need to extract the text value of "result", but it doesn't output that to me. Could you help me please? ...

Array value matching - return keys

I have two arrays. The first one looks like: Array1 ( [14] => foo [15] => bar [16] => hello } and the sencond looks like: Array2 ( [Label1] => foo [Label2] => bar [Label3] => hello [Label4] => foo [Label5] => bar } I would like to compare the values of array1 against array2, if they match, I would like to re...

Delete duplicate rows in MySQL table but foreign key relationship exists?

How can I delete duplicate rows from a MySQL table when a foreign key relationship has already been setup up on those rows. Can the duplicates be merged somehow and then foreign key updated with the new value? ...

Form over several pages - URL should remain

Hello! Don´t know if my english is sufficient to explain this right: I have made a Form that is needs 4 or 5 pages until final submit comes. On every change the Post is added to the new page as a hidden field and a new script is called. <form method="post" action="form4.php"> My problem is i dont want the browser to ...

Populating Nagivation Tabs with SQL?

I'm looking for some kind of Nav tab (vertical) that allows it to be populated by SQL. For example, in the SQL table there would be a column for title (which is the title of the tab) and a column for the contents of the tab. I have tried building one myself, but I have no idea how to fit it in a nav bar because usually I'd do a while l...

Foreach loop with multiple arrays

This is what I want: foreach($_POST['something'] as $something){ foreach($_POST['example'] as $example){ $query = mysql_query("INSERT INTO table (row, row2) VALUES ('{$something}','{$example}')"); } } $_POST['something'] and $_POST['example'] are arrays from an input with name="something[]" and name="example[]". T...

Can't require mage.php from an interactive shell

I would like to try some code snippets (about to make a script) which uses Magento's models and classes. The problem is that I get the following error: fdr@fderose-gtrade:/var/www/globaltrade$ fdr@fderose-gtrade:/var/www/globaltrade$ php -a Interactive shell php > require './app/Mage.php'; Fatal error: Class 'Mage' not found in /va...

Why isn't natsort (or natcasesort) working here?

Perhaps I'm doing something embarrassingly wrong, but why isn't this array being sorted? $narray=array(); $dir_handle = @opendir($path.$projectFolder) or die("Unable to open $path$projectFolder"); $i=0; while($file = readdir($dir_handle)) { $filenameSplit = explode('.',$file); if ($file != "." && $file != ".." && $filenameSplit[0...

PHP: Image upload, thumbnails, specific crops

I've created a script which implements jCrop to crop an image before displaying it. In the CMS the client needs to be able to upload logos, which fit a specific size as determined by our designer. So I think I'm looking for something which can crop, resize and save out the original, a specific sized version and potentially other thumbna...

Control different access levels

Hello all, I plan to use two tables (i.e. guest and employee) to control which page is available to which user. The guess can sign up for an account while the employee cannot. The account of an employee can only be assigned by a system administrator. Here is the question I just found: Assume UserA is a employee and has 'login001' as ...

Functions save incorrect values if called in real-time; called manually they save correct values. What's going on?!

I have a (php/mysql) system that rewards users for doing things on the site. For the sake of the question, let's say a user gets a rose for every 5 comments they make. The front page has a counter that shows how many roses have been earned today, and how many roses have been earned all-time. The rough logic is below: //Save a single, d...

What is the easiest way to integrate iPhone app with Web Sites that don't have web service

I am about to offer an iphone app for a travel agency. They probably use web services but if not what can I do? What is the easiest way to integrate an iPhone app that read and send data to a website without web service. Site is built with php (I dont know php am a java guy). What can I do for that? Client is a travel agency has a websit...

persistent data in php question

OK Ive written this neat javascript 'thing' using jquery and ajax. Its all based on the idea that a div has an attribute that lets you write inside the div. (contenteditable=true). I thought it would be cool to make a chatroom type thing out of it, and holy cow its doing some cool stuff(*), but I have an issue. Using ajax I post to a p...

Sessions or cookies?

I'm making a forum for learning mostly but hopefully it will have a couple of users some day. What im wondering is should you use sessions or cookies for user authentication? ...

How to construct the query

I am confused with building the query. I am implementing the search feature in a restaurant site. User first selects the area he is searching for restaurant and then he select the food types like chinese, japanese, thai from the checkboxes. After selecting all these, the restaurants which providing the selected food in the selected area...

How to perform: Upload Image > Recognize Text > Make Image Searchable > Store into DB?

Hey there, I need to know how to perform the procedure, you already have read in the title. You'll upload an image (e.g. a piece of text, an article) and on server-side the text will be recognized via OCR and stored into a database. Which would be the best programming language for it? It should be a browser application. I found the oc...