php

illegal command error code 127 in php exec function

I am using this php code: exec("unrar e file.rar",$ret,$code); and getting an error code of illegal command ie 127 ... but when I am using this command through ssh its working ... because unrar is installed on the server ... so can anyone guess why exec is not doing the right stuff? ...

PHP 'something like widget' code design

I have a prototype website written in PHP. Lately i've rewritten code to separate logic from layout and database operations. So now I have something like MVC code design. Now what bothers me, is that in MVC I'll have many files and each will display something when combined with other (model+view+controller). So I figured out that it wou...

How can I get PHP to use the same APC cache when invoked on the CLI and the web?

I'm using APC to cache user variables (with the apc_store/apc_fetch commands). I've also enabled APC for the CLI with the option "apc.enable_cli = 1". However, the CLI version of PHP seems to access a different APC cache from the version used by Apache. Is it possible to configure APC to use the same cache for both CLI and web invocati...

Validating one or the other

I've created a javascript function that allows me to validate if one field or the other is filled (called, shockingly enough, oneortheother). Essentially, it checks if neither is filled, or both, and throws an error. One of the fields being validated is a input type="file" field. I'm displaying below the field the existing file, so tha...

MySQL design with dynamic number of fields.

My experience with MySQL is very basic. The simple stuff is easy enough, but I ran into something that is going to require a little more knowledge. I have a need for a table that stores a small list of words. The number of words stored could be anywhere between 1 to 15. Later, I plan on searching through the table by these words. I ...

Is a PHP, Python, PostgreSQL design suitable for a business application?

I'm looking for some quick thoughts about a business application I am looking to build. I'd like to separate the three layers of presentation, domain logic, and data using PHP, Python, and PostgreSQL, respectively. I would like to hear, possibly from other folks who have gone down this path before, if there are problems with this approa...

MySQL Insert: Test first?

As an example, when inserting a record into a table with a unique index, is it best to test first? e.g., $mysqli->query('SELECT email FROM tblUser WHERE email = '[email protected]'); then make sure 0 rows are returned, then do the insert? $mysqli->query('INSERT INTO tblUser ...'); Or is it better to just skip the test and handle the er...

Share Constants Between PHP and JavaScript

I have several constants in a PHP application I'm developing. I've defined a Constants class and the defined the constants as const VAR_NAME = value; in this class. I would like to share these constants between my JavaScript and PHP code. Is there a DRY (Don't Repeat Yourself) mechanism to share them? class Constants { const RESOU...

Set variable to be formatted in HTML before sending email

I am sending out an email, and the message ($message) is in HTML I used a different script before (HTML MIME MAIL) and I just set it to HTML by doing this: setHTML($message). With this script, I am unsure how I would set $message to output as HTML within the email. require_once "Mail.php"; $from = "[email protected]"; $host = "mail....

Best way to store global variables

I'm writing an application in PHP that uses a LOT of global variables that are used throughout the script. Right now, I have a config file that stores a bunch of global variables created by using the define() function, but since I'm going to have so many, would it be better to create a table in the database that is just contains variable...

Check if remote file is well-formed XML with PHP

I have a PHP-driven site that includes an XML stock feed, which is remotely served from ASP (i.e. the XML feed url is of the order: http://remote.com/client.asp). As the feed is often unavailable (by which I mean the site returns an ASP error) I'd like to check if the feed is well-formed XML before including it. My usual url_exists func...

php exercises

Hi, I'm looking for exercises that will help me to learn php (complex loops, arrays, tricks etc) ...

How to convert code from C# to PHP

Hello, I have a business logic classes that are written in pure C# (without any specific things from this language) and I would convert this code into PHP. I can write my own parser, but think if I could someone did it before me. Could you please tell me where can I find this kind of converter? Ps. As I've written I use only plain C#...

Download Mail Attachments - Yahoo Webmail

Hi everyone, I'd like to create a script in PHP that can be run through a cron job. This script has to do the following: A) Log in to Yahoo Webmail B) Navigate to the inbox C) Loop through all mails with attachments D) Download each attachment * E) Put the downloaded attachment into a directory on the server *: When viewing a mail...

Regular expression to find and replace the content of HTML Comment Tags

I have a CMS that uses a syntax based on HTML comments to let the user insert flash video players, slideshows, and other 'hard' code that the user could not easily write. The syntax for one FLV movies looks like this: <!--PLAYER=filename.flv--> I use this code: $find_players = preg_match("/<!--PLAYER\=(.*)-->/si", $html_content, $mat...

Session lost when switching from HTTP to HTTPS in PHP

When sending the user to a checkout page, they are switched from http://mysite.com to https://mysite.com. As a result, $_SESSION variables are lost. The site has a valid SSL certificate which may or may not be of some use. ...

Return words before and after the first occurrence of a string

I have a body of text returned from a search query, lets call it $body. Now, what I want to do is for the script to find the first occurrence of the search query, $query. I know I can find this first occurrence this with strripos. Once found, I want the script to return a couple of words before the first occurrence of the string as ...

How can I change the <title> tag dynamically in php based on the URL values

I want the title page to be changed so that a crawler can see it. The URL is of the format: public.sample.com/account/Disney I load a standard, global header include file using require() That's where the current default tags are defined. IF the URL is public.sample.com/account/Disney, I would like the tag to read, instead: This is...

How should I count the number of occurrences of a character at the beginning of a string in PHP

The best that I have been able to come up with is: strlen(preg_replace('/^([\\*]*)\s(.+)/',"$1",$line)); ^^That seems to give the length of the string.^^ edit: I think that I should clarify that the character that I am trying to find is '*' ...

Best way to implement a download counter?

Say a user clicks on a link to download a file. The user gets the save as dialogue box but then clicks on cancel. How do you detect this? Meaning if the user hits the cancel link or doesn't get the whole file, the server should not record that the file was downloaded. ...