php

What is the best way to generate a random key within PHP?

I'm looking to create a reusable function that will generate a random key with printable ACSII characters of choosen length (anywhere from 2 to 1000+). I'm thinking printable ASCII characters would be 33-126. They key does not need to completely unique, just unique if generated at the exact same millisecond (so uniqid() won't work). I'm...

Unable to call system commands and shell scripts from PHP Fedora 10

I am working on an application that runs locally on a Fedora 10 machine through PHP and Apache. It depends on a process that runs in the background. The higher-ups want to be able to start/stop/restart the process, through the browser. I was trying to get this to work by having PHP make calls to the system using exec() and shell_exec,...

date formatting in php

Hi, I am having a string as mentioned below: $ts = "3/11/09 11:18:59 AM"; which I have got using date() function Now i need to convert this to a readable format like below 11-Mar-2009 I have ave tried everything using date() Can someone please help me with this?? ...

Should I htmlspecialchar() variables inside <title></title>?

Is it necessary to filter/escape unsafe variables in <title> or other tags in <head> to prevent XSS? ...

Switching between mysql databases

function getLink($sa){ if($sa=='1'){ $sa = 'qp_bbl'; } else { $sa = 'qp_sbl'; } return $sa; } if(!$_POST['action']){ header ("Location: index.php"); }else{ $sa = $_POST['select']; $sa = getLink($sa); $link = connect(HOST, USER, PASSWORD, $sa); (....) } This is driving me crazy. Select can be...

Updating a MySql database using PHP via an onClick javascript function

I am creating a web game for learning new words aimed at children. I have a set of four links each displaying a specific word retrieved from my database and a clue, I need to check that the word which has been selected matches the correct word for that clue. I know that I need to use javascript because of the onClick function and I can...

Regular expression to extract [flv:example.flv 465 301] from a string

$content = preg_match('/[flv[^/]]+:(.*?)[^/]]*/]','', $content); Could someone give me the regular expression for extracting [flv:example.flv 465 301] from a string. Also, I would like to put the example.flv into second element of the array, and the dimensions in to the third element. I have tried the above regex and it fails miserably...

PHP form class

I'm used to ASPNET and Django's methods of doing forms: nice object-orientated handlers, where you can specify regexes for validation and do everything in a very simple way. After months living happily without it, I've had to come back to PHP for a project and noticed that everything I used to do with PHP forms (manual output, manual va...

Stop data inserting into a database twice

Im quite new to PHP, i was wondering what methods/preventions other programmers use to stop data being entered twice into a MySQL database when a user refreshes on the same page as a form? Obviouly it happens and i need a good way to stop this. Thanks, Ben ...

Recommend a flat-file blog engine?

Has anyone had success with a flat-file blog engine? I'm trying to arrange a very basic, bare bones blog setup on an intranet site. Unfortunately, the usual solutions rely on MySQL, which is not available on this server. In fact, no database is available. I may be able to do SQLlite, but would prefer a flat-file solution. DokuWiki has ...

How to fetch remote system files using PHP?

I am doing one project, in which I want to access the folders from remote system connected via LAN. From that I have a drop down list. When I select the remote system drive letter (eg: c:, d:) the corresponding files in that folder will displayed in my system. Is there any tutorial for this? I've tried this, but it works for local sy...

Modeling objects with multiple table relationships in Zend Framework

I'm toying with Zend Framework and trying to use the "QuickStart" guide against a website I'm making just to see how the process would work. Forgive me if this answer is obvious, hopefully someone experienced can shed some light on this. I have three database tables: CREATE TABLE `users` ( `id` int(11) NOT NULL auto_increment, `ema...

getting form variables with JavaScript

I have the following form(echoed through php), which when a radio button is selected, I want that value to be passed to a javascript function, which I can then deal with. <form id=\"form1\" name=\"form1\" method=\"\" action=\"JavaScript:alterRecord()\"> <input name=\"radiobutton\" type=\"radio\" value=\"test1\" />Test 2<p> <input name=\...

color code passed to flash variable in Twitter badge

I'm trying to create a simple interface to automate the creation of a flash twitter badge for a WordPress theme. My question is this, on the twitter page which has a simple color customizer, the standard hex color codes are getting translated to something to be passed to the flash as a variable. Can anyone shed any light on what that c...

PHP vs. long-running process (Python, Java, etc.)?

Hello I'd like to have your opinion about writing web apps in PHP vs. a long-running process using tools such as Django or Turbogears for Python. As far as I know: - In PHP, pages are fetched from the hard-disk every time (although I assume the OS keeps files in RAM for a while after they've been accessed) - Pages are recompiled into o...

parse error

I need a fresh set of eyes on this. I got this code from someone who said it worked. Here is the error: PHP Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in C:\Inetpub\wwwroot\2am\employment\send-email-form.php on line 19 Line 19 is the first line of GetUploadedFileInfo(). I get the error for line...

Separation of concerns; MVC; why?

I'm currently reading up on OO before I embark upon my next major project. To give you some quick background, I'm a PHP developer, working on web applications. One area that particularly interests me is the User Interface; specifically how to build this and connect it to my OO "model". I've been doing some reading on this area. One of...

How do I limit PHP apps to their own directories and their own php.ini?

I am running multiple PHP apps on my Mac, running OS X 10.5.6, Apache 2, PHP 5. I have subdomains setup for each project, a host file entries for each subdomain, and Virtual Directory blocks in the Apache config. So project1.localhost goes to /Library/WebServer/Documents/Project1 project2.localhost goes to /Library/WebServer/Documen...

What's needed for PHP's mcrypt_decrypt()?

I have a script that uses mcrypt_decrypt() function, but I get the following error Fatal error: Call to undefined function mcrypt_decrypt() What modules/libraries do I need to include to use this function? Or is there another reason I'm getting the error? Thanks ...

Selecting values from the database and make the checkbox checked if it does exist.

//query to check if part id number exists in table ATTEND where service id = ... $result2 = mysql_query("SELECT * FROM attend WHERE SIDno='$SIDno' and ServiceID='$id"); //if exists $ok = true; if (mysql_num_rows($result2)>0) { $ok == true; } echo "<tr bgcolor=$bgcolor>"; echo "<td><a name=$row1[0] id=$row1[0]>$row1[0]</td>";...