php-general Digest 5 Dec 2009 00:56:16 -0000 Issue 6472

2009-12-04 Thread php-general-digest-help

php-general Digest 5 Dec 2009 00:56:16 - Issue 6472

Topics (messages 300246 through 300255):

Good SQL builder class
300246 by: Anton Heuschen
300247 by: Tony Marston
300254 by: Daevid Vincent

php.ini  session_auto.start = 1
300248 by: scotdiddle.silverdarkroom.com
300249 by: scotdiddle.silverdarkroom.com
300250 by: scotdiddle.silverdarkroom.com

json_last_error
300251 by: Kirby Bakken
300252 by: Jim Lucas
300253 by: Ryan Sun

Use specific IP for outbound traffic.
300255 by: shiplu

Administrivia:

To subscribe to the digest, e-mail:
php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
php-gene...@lists.php.net


--
---BeginMessage---
Good day.

I'm looking for a good class to handle building dynamically from and
array (and if it is good it will automatically determine / or even
have different methods) to handle mutli-dimensional arrays or simple
associative arrays ... and build the SQL statement :

for example I have an array :

$home[$suburb][street] = test1;
$home[$suburb][housenr] =2;


Ok to keep it simple to 2, then I want to build the SQL like

insert into homes (STREET, HOUSENR) VALUES ($val1,$val2);


something like that, but I could also pass some array like :

$home[street] = test2;
$home[housenr] = 2;


but the idea stays the same = the index is the name of the DB fields
and the assigned value the element



I have looked on hotscripts and phpclasses but I have no idea how good
the solutions are that I have found thus far - therefor need some
recommendation from someone else past experience of this
---End Message---
---BeginMessage---
Take a look at http://www.tonymarston.net/php-mysql/databaseobjects.html

You can also download a working example of this code from 
http://www.tonymarston.net/php-mysql/sample-application.html

-- 
Tony Marston
http://www.tonymarston.net
http://www.radicore.org

Anton Heuschen anto...@gmail.com wrote in message 
news:e6d501390912040509k1b27f082mc22ff95d46004...@mail.gmail.com...
 Good day.

 I'm looking for a good class to handle building dynamically from and
 array (and if it is good it will automatically determine / or even
 have different methods) to handle mutli-dimensional arrays or simple
 associative arrays ... and build the SQL statement :

 for example I have an array :

 $home[$suburb][street] = test1;
 $home[$suburb][housenr] =2;


 Ok to keep it simple to 2, then I want to build the SQL like

 insert into homes (STREET, HOUSENR) VALUES ($val1,$val2);


 something like that, but I could also pass some array like :

 $home[street] = test2;
 $home[housenr] = 2;


 but the idea stays the same = the index is the name of the DB fields
 and the assigned value the element



 I have looked on hotscripts and phpclasses but I have no idea how good
 the solutions are that I have found thus far - therefor need some
 recommendation from someone else past experience of this 


---End Message---
---BeginMessage---
Multi-dimensional arrays generally indicate some kind of glue/hanging table, so 
you'll have to special case them for your needs...
But here is a generic insert and update functions that may be a groundwork for 
you


/**
* Insert a single row into a $database.$table from an array hash of column = 
value pairs
*
* Usually these are the form field names corresponding to the equivallent SQL 
database column/field name.
* Use the string 'null' to insert a true NULL.
*
* @access   public
* @return   mixed inserted ID on success or result on failure
* @paramstring $database the database to connect to (agis_core) is the 
default
* @paramstring $table the name of the table to insert into
* @paramhash $rows hash of column = value pairs (optionally columns 
validated against $validate_columns)
* @paramarray $valid_columns array of column/field names. Also useful 
to limit SQL to certain forced columns to prevent
unwanted tampering with 'default' columns for example.
* @author  Daevid Vincent
* @date 11/23/09
* @see  sql_update(), sql_insert_id()
*/
function sql_insert($database, $table, $rows, $valid_columns=null)
{
ksort($rows); //not required, just easier to debug and find appropriate 
keys.

$validate_columns = (is_array($valid_columns)) ? true : false;

$temp = array();
$arrays = array();
foreach ($rows as $column = $val)
{
if (is_array($val))
{
$arrays[$column] = $val;
unset($rows[$column]);
continue;
}

if ($validate_columns  !in_array($column, $valid_columns))
{
unset($rows[$column]);
   

[PHP] How to read a certificate and compute hash of it

2009-12-04 Thread Tanveer Chowdhury
Hi

Currently I am doing some coding in php to match a client certifcate with an
openldap certificate of that same user just to verify.
I mean the user stored one copy of this certficate in openldap previously
and now when he shows his certificate to server the server will then fetch
that users certificate from ldap and match.

and later I want to do hash. Now in ldap its stored in .der format and in
browser its in .p12
So what I am doing is as below:

?php
$HASH_ALG='md5';
include_once '../ldapconnect.php';
//
//Reading the client certificate from web server
$loginCert = openssl_x509_read ($_SERVER[SSL_CLIENT_CERT]);

//convert the certificate into string
$pemb = chunk_split(base64_encode($loginCert), 64, \n);
$pemb = -BEGIN CERTIFICATE-\n.$pemb.-END CERTIFICATE-\n;

openssl_x509_export($pemb,$cert_pemb_string);

$login_cert_hash = hash ($HASH_ALG, $cert_pemb_string);
echo Browser HASH= . $login_cert_hash;
echo br /;

///

$userName=$_SERVER[SSL_CLIENT_S_DN_CN];
$filter=(cn=$userName);
$justthese = array (userCertificate;binary);
$result=ldap_search ($ldapconnect,ou=people,dc=example,dc=com, $filter);
$entry = ldap_first_entry($ldapconnect,$result);
$attributes= ldap_get_attributes($ldapconnect,$entry);
$cert_der =$attributes[userCertificate;binary][0];

// converting der to pem
$pem = chunk_split(base64_encode($cert_der), 64, \n);
$pem = -BEGIN CERTIFICATE-\n.$pem.-END CERTIFICATE-\n;
openssl_x509_export($pem,$cert_pem_string);
$ldap_cert_hash = hash($HASH_ALG, $cert_pem_string);

Now finally I will match $login_cert_hash and $ldap_cert_hash but problem is
its always giving me the same output of hash even if I manually change the
certificate of client to make sure.
I don't get it.

Thank in advance.


[PHP] Good SQL builder class

2009-12-04 Thread Anton Heuschen
Good day.

I'm looking for a good class to handle building dynamically from and
array (and if it is good it will automatically determine / or even
have different methods) to handle mutli-dimensional arrays or simple
associative arrays ... and build the SQL statement :

for example I have an array :

$home[$suburb][street] = test1;
$home[$suburb][housenr] =2;


Ok to keep it simple to 2, then I want to build the SQL like

insert into homes (STREET, HOUSENR) VALUES ($val1,$val2);


something like that, but I could also pass some array like :

$home[street] = test2;
$home[housenr] = 2;


but the idea stays the same = the index is the name of the DB fields
and the assigned value the element



I have looked on hotscripts and phpclasses but I have no idea how good
the solutions are that I have found thus far - therefor need some
recommendation from someone else past experience of this

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Good SQL builder class

2009-12-04 Thread Tony Marston
Take a look at http://www.tonymarston.net/php-mysql/databaseobjects.html

You can also download a working example of this code from 
http://www.tonymarston.net/php-mysql/sample-application.html

-- 
Tony Marston
http://www.tonymarston.net
http://www.radicore.org

Anton Heuschen anto...@gmail.com wrote in message 
news:e6d501390912040509k1b27f082mc22ff95d46004...@mail.gmail.com...
 Good day.

 I'm looking for a good class to handle building dynamically from and
 array (and if it is good it will automatically determine / or even
 have different methods) to handle mutli-dimensional arrays or simple
 associative arrays ... and build the SQL statement :

 for example I have an array :

 $home[$suburb][street] = test1;
 $home[$suburb][housenr] =2;


 Ok to keep it simple to 2, then I want to build the SQL like

 insert into homes (STREET, HOUSENR) VALUES ($val1,$val2);


 something like that, but I could also pass some array like :

 $home[street] = test2;
 $home[housenr] = 2;


 but the idea stays the same = the index is the name of the DB fields
 and the assigned value the element



 I have looked on hotscripts and phpclasses but I have no idea how good
 the solutions are that I have found thus far - therefor need some
 recommendation from someone else past experience of this 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] php.ini session_auto.start = 1

2009-12-04 Thread scotdiddle
Hello All,

In my previous LAMP position, I developed an intranet system from
scratch, and chose to use session_auto.start = 1 for sessions.

My new employer has auto-start turned off, and I have been tasked with
re-writing the entire system.  I would like to use auto-start, but
during testing I found a couple of system calls that don't work if the
session has  already been started .

I there a resource somewhere out in google-land which will show me a
list of system functions don't play nice session_auto.start = 1 ?

Also, what are the thoughts of the folks on this list about using the
auto-start setting ?

Any advice / direction will be appreciated.

Scot L. Diddle, Richmonc VA








-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] php.ini session_auto.start = 1

2009-12-04 Thread scotdiddle
Hello All,

In my previous LAMP position, I developed an intranet system from
scratch, and chose to use session_auto.start = 1 for sessions.

My new employer has auto-start turned off, and I have been tasked with
re-writing the entire system.  I would like to use auto-start, but
during testing I found a couple of system calls that don't work if the
session has  already been started .

I there a resource somewhere out in google-land which will show me a
list of system functions don't play nice session_auto.start = 1 ?

Also, what are the thoughts of the folks on this list about using the
auto-start setting ?

Any advice / direction will be appreciated.

Scot L. Diddle, Richmond VA








-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] php.ini session_auto.start = 1

2009-12-04 Thread scotdiddle
Hello All,

In my previous LAMP position, I developed an intranet system from
scratch, and chose to use session_auto.start = 1 for sessions.

My new employer has auto-start turned off, and I have been tasked with
re-writing the entire system.  I would like to use auto-start, but
during testing I found a couple of system calls that don't work if the
session has  already been started .

I there a resource somewhere out in google-land which will show me a
list of system functions don't play nice session_auto.start = 1 ?

Also, what are the thoughts of the folks on this list about using the
auto-start setting ?

Any advice / direction will be appreciated.

Scot L. Diddle, Richmond VA








-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] json_last_error

2009-12-04 Thread Kirby Bakken
None of the servers I run on have PHP 5.3, and I have no idea when 
they'll be updated.  The json_last_error function is in 5.3.  What can I 
do to provide a temporary json_last_error function until my servers get 
updated to 5.3?  Is there source available for json_last_error somewhere?


Thanks,

Kirby

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] json_last_error

2009-12-04 Thread Ryan Sun
json_decode
(PHP 5 = 5.2.0, PECL json = 1.2.0)

so json_decode will be avaliable for php 5.2.0+

php is open source, I believe you can get an idea from their C source

On Fri, Dec 4, 2009 at 2:16 PM, Jim Lucas li...@cmsws.com wrote:

 Kirby Bakken wrote:
  None of the servers I run on have PHP 5.3, and I have no idea when
  they'll be updated.  The json_last_error function is in 5.3.  What can I
  do to provide a temporary json_last_error function until my servers get
  updated to 5.3?  Is there source available for json_last_error somewhere?
 
  Thanks,
 
  Kirby
 

 I don't believe you will be able to provide this functionality without
 recreating the json_decode() function also.

 json_last_error() looks like it retrieves information that is from the last
 attempt to run json_decode() on a given string.  My guess is that
 json_decode()
 set an internal variable that json_last_error() picks up and returns.

 Without having json_decode() say what the problem was/is then you can never
 recreate the json_last_error() function.

 Jim Lucas

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Good SQL builder class

2009-12-04 Thread Daevid Vincent
Multi-dimensional arrays generally indicate some kind of glue/hanging table, so 
you'll have to special case them for your needs...
But here is a generic insert and update functions that may be a groundwork for 
you


/**
* Insert a single row into a $database.$table from an array hash of column = 
value pairs
*
* Usually these are the form field names corresponding to the equivallent SQL 
database column/field name.
* Use the string 'null' to insert a true NULL.
*
* @access   public
* @return   mixed inserted ID on success or result on failure
* @paramstring $database the database to connect to (agis_core) is the 
default
* @paramstring $table the name of the table to insert into
* @paramhash $rows hash of column = value pairs (optionally columns 
validated against $validate_columns)
* @paramarray $valid_columns array of column/field names. Also useful 
to limit SQL to certain forced columns to prevent
unwanted tampering with 'default' columns for example.
* @author  Daevid Vincent
* @date 11/23/09
* @see  sql_update(), sql_insert_id()
*/
function sql_insert($database, $table, $rows, $valid_columns=null)
{
ksort($rows); //not required, just easier to debug and find appropriate 
keys.

$validate_columns = (is_array($valid_columns)) ? true : false;

$temp = array();
$arrays = array();
foreach ($rows as $column = $val)
{
if (is_array($val))
{
$arrays[$column] = $val;
unset($rows[$column]);
continue;
}

if ($validate_columns  !in_array($column, $valid_columns))
{
unset($rows[$column]);
continue;
}

$val = trim($val);
if (!$val)
{
unset($rows[$column]);
continue;
}

if (strtolower($val) == 'null')
$temp[$column] = 'NULL';
else
$temp[$column] = '.mysql_escape_string($val).';
}

$values = implode(', ',$temp);
$columns = `.implode(`, `, array_keys($rows)).`;
$sql = INSERT INTO `.$table.` (.$columns.) VALUES (.$values.);
//echo $sql;

if (count($arrays))
echo \nbr/sql_insert() has arrays that need to be handled 
still: .implode(', ', array_keys($arrays));

$result = sql_query($database, $sql, null, false);
if ($result)
{
$iid = sql_insert_id();
if ($iid) return $iid;
}

return $result;
}


/**
* Update rows in $database.$table from an array hash of column = value pairs
*
* Usually these are the form field names corresponding to the equivallent SQL 
database column/field name.
* Use the string 'null' to insert a true NULL.
*
* @access   public
* @return   mixed   affected rows on success or result on failure
* @paramstring  $database the database to connect to (agis_core) is the 
default
* @paramstring  $table the name of the table to insert into
* @paramhash$rows hash of column = value pairs (optionally columns 
validated against $validate_columns)
* @parammixed   hash of ID column/field name and record ID value [such 
as array('id_foo' = 69)] OR string to craft custom
WHERE clause
* @paramarray   $valid_columns array of column/field names. Also useful 
to limit SQL to certain forced columns to prevent
unwanted tampering with 'default' columns for example.
* @author  Daevid Vincent
* @date 11/23/09
* @see  sql_insert()
*/
function sql_update($database, $table, $rows, $where, $single=true, 
$valid_columns=null)
{
ksort($rows); //not required, just easier to debug and find appropriate 
keys.

$validate_columns = (is_array($valid_columns)) ? true : false;

$temp = array();
$arrays = array();
foreach ($rows as $column = $val)
{
if (is_array($val))
{
$arrays[$column] = $val;
unset($rows[$column]);
continue;
}

if ($validate_columns  !in_array($column, $valid_columns))
{
unset($rows[$column]);
continue;
}

$val = trim($val);
if (!$val)
{
unset($rows[$column]);
continue;
}

if (strtolower($val) == 'null')
$temp[$column] = '`'.$column.` = NULL;
else
$temp[$column] = '`'.$column.` = 
'.mysql_escape_string($val).';
}

$sql = UPDATE `.$table.` SET .implode(', ', $temp);

if 

[PHP] Use specific IP for outbound traffic.

2009-12-04 Thread shiplu
Hello,
I have 3 IPs in my VPS. Everytime I request to a site it uses only 1
IP as gateway. So all the outbound traffic goes thorough that IP.
What I want is one of my script will always communicate using an
specific ip. Not default one.
I'll use 3 scripts for 3 IPs. How can I do that?
I know it can be done by changing the routing table. I think this
technique has a problem. If one script changes the gate way to its own
IP other script will be using that IP too.
Is there any way to achieve this without changing the routing table gloablly?


-- 
Shiplu
Innovation distinguishes bet ... ... (ask Steve Jobs the rest)

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php