I've written a simple PHP script which checks if a random value is a valid Rugby Union score. It works quite nicely but isn't particularly efficient, any advice on improving it would be most welcome.
$score = rand(0, 60);
/* Rugby Union
*
* Try = 5 points
* Conversion = 2 points
* Penalty = 3 points
* Drop goal = 3 points
*
*/...
I'm a desktop application developer. I'm creating a basic website from which to sell an application I've written, and learning some web tech along the way, but haven't learnt that much yet (my chosen CMS - Textpattern - has saved me learning much PHP so far).
I want my desktop application to call my website and say "I'm version x.x.x.x"...
In PHP, what would be the cleanest way to get the parent directory of the current running script relative to the www root? Assume I have:
$_SERVER['SCRIPT_NAME'] == '/relative/path/to/script/index.php'
Or just:
$something_else == '/relative/path/to/script/'
And I need to get /relative/path/to/ with slashes properly inserted. What w...
I'm pretty much a complete newbie to PHP. My background is C/C++ and C#. I'm trying to object orient-ify some simple PHP code, but I'm doing something wrong.
Class code:
class ConnectionString
{
public $String = "";
public $HostName = "";
public $UserName = "";
public $Password = "";
public $Database = "";
function LoadFro...
I have a linux server with PHP, I do not see gettext in the PHPINFO output, so I assume gettext is not enabled/included in the PHP. I have installed the gettext lib on the machine.
What other steps do I need to do to enable gettext in my PHP?
I read the php.net documentation, the only entry there writes about building PHP with gettext...
Hi folks,
I'm using two regular expressions to pull assignments out of MySQL queries and using them to create an audit trail. One of them is the 'picky' one that requires quoted column names/etc., the other one does not.
Both of them are tested and parse the values out correctly. The issue I'm having is that with certain queries the 'p...
I have a strange behavior with PHP system function. In this php script there are only 2 instructions (the rest being pure html):
<?php echo system('cgi-bin/gallery2/galleryheaderview.cgi'); ?>
<?php echo system('cgi-bin/gallery2/galleryview.cgi'); ?>
The first cgi just returns a single line as you can check here
http://reboltutorial.c...
Hi all,
I'm trying to find a way to search inside PDF files. I came accross the PHP PDF class but I can't seem to find any function for reading/searching a filestream.
So, as naive as I am, i tried to simple get a stream using file_get_contents(), obviously it's an encrypted-like output ;)
So my question, is there any way to search t...
PHP code:
function compute_signature($key, $hash_string)
{
$digest = hash_hmac("sha1", $hash_string, $key, true);
return base64_encode($digest);
}
Ruby Code:
digest = HMAC.digest(Digest.new(SHA1), Base64.decode64(key), HashString)
return Base64.encode64(digest.to_s()).chomp()
Could this be a charset iss...
I am trying to create a simple login system. When I run the login form (with the correct username and password) it doesn't seem to run the php. Any suggestions?
<?php
$host="linuxserver"; // Host name
$username="jparry2"; // Mysql username
$password=""; // Mysql password
$db_name="jparry2"; // Database name
$tbl_name="customer"; // Tabl...
Using PHP, how do I get an entire subset of nodes from an XML document? I can retrieve something like:
<?xml version="1.0" encoding="utf-8"?>
<people>
<certain>
<name>Jane Doe</name>
<age>21</age>
</certain>
<certain>
<certain>
<name>John Smith</name>
<age>34</age>
</certain>
</people>
But what if I only want...
I need to make a button that:
Send to php script variable pressed=true when its pressed
open new tab with an adress
How can I do it without using java-script?
...
I am writing a web app for a company that wants to host the app on its servers. I want to protect the source code for two reasons. The first is the obvious closed source business model. The second is source code protection. I don't want them to be able to edit the source code (They aren't competent). I've looked into things like the Zend...
I've looked online for ways to do this, and I've found two PHP methods for accesing WebDAV:
http://freshmeat.net/projects/class%5Fwebdav%5Fclient/
This is less than ideal, because it doesn't support WebDAV at a sub-path of the server; it cannot access, say, http://my-dav-server/configuration, only http://my-dav-server
http://php-webda...
I'm using following Code to add status-messages via PHP & Javascript (Ajax):
$(document).ready(function(){
$("form#status_form").submit(function(){
var s_autor = $('#s_autor').attr('value');
var s_status = $('#s_status').attr('value');
$.ajax({
type: "POST",
url: "/request.php",
data: "s_autor="+ s_a...
Hi there,
I have the following "test-class" made on the fly:
http://sumoin.pastebin.com/ff744ea4
No fine-tuning or something else, just a brief testing pdo class.
And I have the test.php:
http://sumoin.pastebin.com/d70dcb4ec
The funny thing is:
The PDOStatement object is never returned directly and I it never gets assigned to $this->...
On a page I am working on, I have several distinct pieces of PHP, such as one in the head to handle dynamic Javascript and one in the main body for table creation. However, many of the operations, SQL queries, etc. are the same between the two area. For example, I keep having to reconnect to the same database over and over. Is there some...
I have set up a little server on an old XP Pro box, with php 5.3.1.
In order to use it as a test box to mirror our hosted site, I need to get sqlite sessions working.
While sqlite is definitely there in phpinfo(), I can't seem to get php.ini to use it as a save handler:
Registered save handlers - files user
In php.ini, I've got
s...
Here is an example array:
$foo = array(
'employer' => array(
'name' => 'Foobar Inc',
'phone' => '555-555-5555'
),
'employee' => array(
'name' => 'John Doe',
'phone' => '555-555-5556',
'address' ...
Is there any way I can pre-process a PHP view script without using a particular MVC framework?
Basically I want to render the view and pass it as an HTML string to another view. The view I'm trying to render has some references like $this->rows, and, of course, I would need to add the values of those references to the script before gen...