php-general Digest 24 Feb 2012 02:02:31 -0000 Issue 7700

Topics (messages 316764 through 316774):

Re: PHP-FPM security.limit_extensions
        316764 by: Nilesh Govindrajan

Selecting checkboxes based on SQL query
        316765 by: Rick Dwyer
        316766 by: Matijn Woudt
        316767 by: Matijn Woudt
        316768 by: Fatih P.
        316769 by: Rick Dwyer
        316770 by: Fatih P.
        316771 by: Jim Lucas

Where did my comment go related to lower/upper bounds for any number and offset?
        316772 by: Daevid Vincent
        316773 by: Daniel Brown

Apache 2.4.1 and php?
        316774 by: Daniel Fenn

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


----------------------------------------------------------------------
--- Begin Message ---
On Feb 23, 2012 2:46 PM, "Paspao" <pas...@gmail.com> wrote:
>
> Hello ,
>
> I need to parse PHP files with no extension , I was getting access denied
error than I discovered that it was cause by security.limit_extensions
option in PHP-FPM config file.
>
> I tried to add the script name (testscript) to the configuration file and
now it works:
>
> security.limit_extensions = .php .php3 .php4 .php5 testscript
>
> I do not want to add all filenames and then restart php-fpm each time, is
there a way to parse all file without extension or a wildcard to put in
configuration?
>
>
> Thank you
> P.
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

I'm not sure why would you want to do that. Why dont you use rewrite rules
instead?

--
Nilesh Govindrajan
http://nileshgr.com

--- End Message ---
--- Begin Message ---
Hello all.

I perform a SQL query like the following:

$sql = 'select * from my_table where id="10"

It returns the the following array for 3 records:


Array ( [0] => Array ( [cb] => 2 ) [1] => Array ( [cb] => 6 ) [2] => Array ( [cb] => 1 ) )

The values of CB in the above array are the values of html checkboxes on a page.

input type="checkbox" name="cb[ ]" value="1"...
input type="checkbox" name="cb[ ]" value="2"...
input type="checkbox" name="cb[ ]" value="3"...
input type="checkbox" name="cb[ ]" value="4"... etc

If the above array's cb value matches the value of a checkbox on the page, I need the default state of the checkbox to be checked.... so I know I'm going to have some ternary logic in each html checkbox. But I don't know how to create a custom function from the above array to provide that logic. I've tried some tutorials, but with no success as the array I am receiving is not like those in the tutorials.

Any help would be greatly appreciated.

Thank you.


 --Rick



--- End Message ---
--- Begin Message ---
On Thu, Feb 23, 2012 at 7:49 PM, Rick Dwyer <rpdw...@earthlink.net> wrote:
> Hello all.
>
> I perform a SQL query like the following:
>
> $sql = 'select * from my_table where id="10"
>
> It returns the the following array for 3 records:
>
>
> Array ( [0] => Array ( [cb] => 2 ) [1] => Array ( [cb] => 6 ) [2] => Array (
> [cb] => 1 ) )
>
> The values of CB in the above array are the values of html checkboxes on a
> page.
>
> input type="checkbox" name="cb[ ]" value="1"...
> input type="checkbox" name="cb[ ]" value="2"...
> input type="checkbox" name="cb[ ]" value="3"...
> input type="checkbox" name="cb[ ]" value="4"... etc
>
> If the above array's cb value matches the value of a checkbox on the page, I
> need the default state of the checkbox to be checked.... so I know I'm going
> to have some ternary logic in each html checkbox.  But I don't know how to
> create a custom function from the above array to provide that logic.  I've
> tried some tutorials, but with no success as the array I am receiving is not
> like those in the tutorials.
>
> Any help would be greatly appreciated.
>
> Thank you.
>
>
>  --Rick
>

How about this:

input type="checkbox" name="cb[ ]" value="1" <?php
if(in_array(array('cb' => 1))) echo "checked"; ?>...
input type="checkbox" name="cb[ ]" value="2" <?php
if(in_array(array('cb' => 2))) echo "checked"; ?>...
input type="checkbox" name="cb[ ]" value="3" <?php
if(in_array(array('cb' => 3))) echo "checked"; ?>...
input type="checkbox" name="cb[ ]" value="4" <?php
if(in_array(array('cb' => 4))) echo "checked"; ?>... etc

- Matijn

--- End Message ---
--- Begin Message ---
On Thu, Feb 23, 2012 at 8:07 PM, Matijn Woudt <tijn...@gmail.com> wrote:
> On Thu, Feb 23, 2012 at 7:49 PM, Rick Dwyer <rpdw...@earthlink.net> wrote:
>> Hello all.
>>
>> I perform a SQL query like the following:
>>
>> $sql = 'select * from my_table where id="10"
>>
>> It returns the the following array for 3 records:
>>
>>
>> Array ( [0] => Array ( [cb] => 2 ) [1] => Array ( [cb] => 6 ) [2] => Array (
>> [cb] => 1 ) )
>>
>> The values of CB in the above array are the values of html checkboxes on a
>> page.
>>
>> input type="checkbox" name="cb[ ]" value="1"...
>> input type="checkbox" name="cb[ ]" value="2"...
>> input type="checkbox" name="cb[ ]" value="3"...
>> input type="checkbox" name="cb[ ]" value="4"... etc
>>
>> If the above array's cb value matches the value of a checkbox on the page, I
>> need the default state of the checkbox to be checked.... so I know I'm going
>> to have some ternary logic in each html checkbox.  But I don't know how to
>> create a custom function from the above array to provide that logic.  I've
>> tried some tutorials, but with no success as the array I am receiving is not
>> like those in the tutorials.
>>
>> Any help would be greatly appreciated.
>>
>> Thank you.
>>
>>
>>  --Rick
>>
>
> How about this:
>
> input type="checkbox" name="cb[ ]" value="1" <?php
> if(in_array(array('cb' => 1))) echo "checked"; ?>...
> input type="checkbox" name="cb[ ]" value="2" <?php
> if(in_array(array('cb' => 2))) echo "checked"; ?>...
> input type="checkbox" name="cb[ ]" value="3" <?php
> if(in_array(array('cb' => 3))) echo "checked"; ?>...
> input type="checkbox" name="cb[ ]" value="4" <?php
> if(in_array(array('cb' => 4))) echo "checked"; ?>... etc
>
> - Matijn

Uh, this should of course be in_array(array('cb' => 1, $sqlArray))

- Matijn

--- End Message ---
--- Begin Message ---
On Thu, Feb 23, 2012 at 8:49 PM, Rick Dwyer <rpdw...@earthlink.net> wrote:

> Hello all.
>
> I perform a SQL query like the following:
>
> $sql = 'select * from my_table where id="10"
>
> It returns the the following array for 3 records:
>
>
> Array ( [0] => Array ( [cb] => 2 ) [1] => Array ( [cb] => 6 ) [2] => Array
> ( [cb] => 1 ) )
>
> The values of CB in the above array are the values of html checkboxes on a
> page.
>
> input type="checkbox" name="cb[ ]" value="1"...
> input type="checkbox" name="cb[ ]" value="2"...
> input type="checkbox" name="cb[ ]" value="3"...
> input type="checkbox" name="cb[ ]" value="4"... etc
>
> If the above array's cb value matches the value of a checkbox on the page,
> I need the default state of the checkbox to be checked.... so I know I'm
> going to have some ternary logic in each html checkbox.  But I don't know
> how to create a custom function from the above array to provide that logic.
>  I've tried some tutorials, but with no success as the array I am receiving
> is not like those in the tutorials.
>
> Any help would be greatly appreciated.
>
> Thank you.
>
>
>  --Rick
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
replace the name part as following

input type="checkbox" name="cb[put_the_id_here]" value="1".


when dumping into html from array


foreach ($sql_result as $value) {
   if ($value == $selected) {
           input type checkbox name=cb[$value['id']] value=$value['id']
checked=checked
   } else {
        input type checkbox name=cb[$value['id']]   value=$value['id']
   }
}

hope this helps

--- End Message ---
--- Begin Message ---
I should have been more explicit in my description...

The SQL command that returns the array is not the same one that creates the checkboxes.... they are two different sql queries and I would prefer to keep them that way.

I actually have it working for a form submit with a custom function I got off the web. But the custom function relies on the array it's working on to look like this:

[cb] => Array ( [0] => 1 [1] => 6 [2] => 2 [3] => 4 [4] => 3 )


So, to use my existing function, how do I get the following array to look like the above one:

Array ( [0] => Array ( [cb] => 2 ) [1] => Array ( [cb] => 6 ) [2] => Array ( [cb] => 1 ) )


 --Rick


On Feb 23, 2012, at 2:08 PM, Fatih P. wrote:

On Thu, Feb 23, 2012 at 8:49 PM, Rick Dwyer <rpdw...@earthlink.net> wrote:

Hello all.

I perform a SQL query like the following:

$sql = 'select * from my_table where id="10"

It returns the the following array for 3 records:


Array ( [0] => Array ( [cb] => 2 ) [1] => Array ( [cb] => 6 ) [2] => Array
( [cb] => 1 ) )

The values of CB in the above array are the values of html checkboxes on a
page.

input type="checkbox" name="cb[ ]" value="1"...
input type="checkbox" name="cb[ ]" value="2"...
input type="checkbox" name="cb[ ]" value="3"...
input type="checkbox" name="cb[ ]" value="4"... etc

If the above array's cb value matches the value of a checkbox on the page, I need the default state of the checkbox to be checked.... so I know I'm going to have some ternary logic in each html checkbox. But I don't know how to create a custom function from the above array to provide that logic. I've tried some tutorials, but with no success as the array I am receiving
is not like those in the tutorials.

Any help would be greatly appreciated.

Thank you.


--Rick



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


replace the name part as following

input type="checkbox" name="cb[put_the_id_here]" value="1".


when dumping into html from array


foreach ($sql_result as $value) {
  if ($value == $selected) {
          input type checkbox name=cb[$value['id']] value=$value['id']
checked=checked
  } else {
       input type checkbox name=cb[$value['id']]   value=$value['id']
  }
}

hope this helps


--- End Message ---
--- Begin Message ---
On Thu, Feb 23, 2012 at 9:30 PM, Rick Dwyer <rpdw...@earthlink.net> wrote:

> I should have been more explicit in my description...
>
> The SQL command that returns the array is not the same one that creates
> the checkboxes.... they are two different sql queries and I would prefer to
> keep them that way.
>
> I actually have it working for a form submit with a custom function I got
> off the web.  But the custom function relies on the array it's working on
> to look like this:
>
> [cb] => Array ( [0] => 1 [1] => 6 [2] => 2 [3] => 4 [4] => 3 )
>
>
> So, to use my existing function, how do I get the following array to look
> like the above one:
>
>
> Array ( [0] => Array ( [cb] => 2 ) [1] => Array ( [cb] => 6 ) [2] => Array
> ( [cb] => 1 ) )
>
>
>  --Rick
>
>
>
> On Feb 23, 2012, at 2:08 PM, Fatih P. wrote:
>
>  On Thu, Feb 23, 2012 at 8:49 PM, Rick Dwyer <rpdw...@earthlink.net>
>> wrote:
>>
>>  Hello all.
>>>
>>> I perform a SQL query like the following:
>>>
>>> $sql = 'select * from my_table where id="10"
>>>
>>> It returns the the following array for 3 records:
>>>
>>>
>>> Array ( [0] => Array ( [cb] => 2 ) [1] => Array ( [cb] => 6 ) [2] =>
>>> Array
>>> ( [cb] => 1 ) )
>>>
>>> The values of CB in the above array are the values of html checkboxes on
>>> a
>>> page.
>>>
>>> input type="checkbox" name="cb[ ]" value="1"...
>>> input type="checkbox" name="cb[ ]" value="2"...
>>> input type="checkbox" name="cb[ ]" value="3"...
>>> input type="checkbox" name="cb[ ]" value="4"... etc
>>>
>>> If the above array's cb value matches the value of a checkbox on the
>>> page,
>>> I need the default state of the checkbox to be checked.... so I know I'm
>>> going to have some ternary logic in each html checkbox.  But I don't know
>>> how to create a custom function from the above array to provide that
>>> logic.
>>> I've tried some tutorials, but with no success as the array I am
>>> receiving
>>> is not like those in the tutorials.
>>>
>>> Any help would be greatly appreciated.
>>>
>>> Thank you.
>>>
>>>
>>> --Rick
>>>
>>>
>>>
>>> --
>>> PHP General Mailing List (http://www.php.net/)
>>> To unsubscribe, visit: http://www.php.net/unsub.php
>>>
>>>
>>>  replace the name part as following
>>
>> input type="checkbox" name="cb[put_the_id_here]" value="1".
>>
>>
>> when dumping into html from array
>>
>>
>> foreach ($sql_result as $value) {
>>  if ($value == $selected) {
>>          input type checkbox name=cb[$value['id']] value=$value['id']
>> checked=checked
>>  } else {
>>       input type checkbox name=cb[$value['id']]   value=$value['id']
>>  }
>> }
>>
>> hope this helps
>>
>
>

read the manual!

--- End Message ---
--- Begin Message ---
On 02/23/2012 11:30 AM, Rick Dwyer wrote:
So, to use my existing function, how do I get the following array to
look like the above one:

Array ( [0] => Array ( [cb] => 2 ) [1] => Array ( [cb] => 6 ) [2] =>
Array ( [cb] => 1 ) )

$d = <results from SQL query>
$a = array();
foreach ($d AS $r)
  $a[] = $r['cb'];

--
Jim Lucas

http://www.cmsws.com/
http://www.cmsws.com/examples/
http://www.bendsource.com/

--- End Message ---
--- Begin Message ---
Hey. To anyone that works on the php.net site. I posted this comment:

http://www.php.net/manual/en/language.operators.bitwise.php#107617

And I saw it there shortly after and even sent that link to some colleagues.
Now it's gone on every mirror too. WTF?? :-( It certainly was relevant as it
used & and ~.

This is what it said basically (although this is a much longer
version/explanation. The note post only had the code function and results).

We've started to convert more of our queries to a "wide" mode and take even
more advantage of memcache instead of a "thin" mode where we hit the DB (and
store in memcache too) for each scene. The idea being that if we make the
queries pull more data than needed (in an intelligent way of course) then we
hit the DB less and memcache more. This works great with the concept of a
DVD vs SCENE as one is macro and one is micro. 

I used some bitwise operations to figure out a lower/upper number for any
given number (and offset). 

/**
 * Get the upper and lower boundaries for any given number and 2^n offset
(other offsets give bizarre results)
 *
 * @access      public
 * @return      array
 * @param       integer $number
 * @param       integer $offset (32) must be a 2^n value [8, 16, 32, 64,
128, ...)
 * @author      Daevid Vincent
 * @date      2012-02-21
 */
function boundaries_ul($number, $offset=32)
{
        if ($offset < 8) return false; //nothing smaller than this makes
practical sense
        if (($offset & ($offset - 1)) != 0) return false; //not a 2^n
        
        $offset = $offset - 1;
        
        //zero out least significant bits. 
        //For example if $offset = 32, then the least 5 bits [16 8 4 2 1] ==
31 == 0xFFE0
        $lowerbound = $number & ~$offset;
        $upperbound = $lowerbound + $offset;
        
        return array('lower_bound'=>$lowerbound,
'upper_bound'=>$upperbound);
}

for ($i = 0; $i < 20; $i++) 
{
        debug_print($i, 'forloop $i decimal');
        $b = boundaries_ul($i, 8);
        var_dump($b); 
        echo "<hr>\n";
}
?>

________________________________________
forloop $i decimal = 3
array
  'lower_bound' => int 0
  'upper_bound' => int 7
________________________________________
forloop $i decimal = 4
array
  'lower_bound' => int 0
  'upper_bound' => int 7
________________________________________
forloop $i decimal = 5
array
  'lower_bound' => int 0
  'upper_bound' => int 7
________________________________________
...
________________________________________
forloop $i decimal = 12
array
  'lower_bound' => int 8
  'upper_bound' => int 15
________________________________________
forloop $i decimal = 13
array
  'lower_bound' => int 8
  'upper_bound' => int 15
________________________________________
forloop $i decimal = 14
array
  'lower_bound' => int 8
  'upper_bound' => int 15
________________________________________


In the get_like()/get_dislike(), we pull in both at the same time from the
same table, which is great. But we can only pull in by scene_id and not a
whole dvd_id (since we don't have the dvd_id in that table) as many of the
other queries I'm converting. That got me thinking of how can I get more
juice for the squeeze. Given that most scenes (if not all) are sequential
that is a clue.

We use the md5($sql) as the hash for memcache so that's why this works,
since the same 128 scene_id's will all result in the same $sql query string
(thanks to upper/lower bounds) and therefore the same hash key is pulled.

Knowing these 'constants', I then fabricate a query for say scene_id = 21269

var_dump(boundaries_ul(21269, 128));

Which would look something like this:

SELECT `scene_id`, `like`, `dislike` FROM `scene_likes` WHERE `scene_id`
BETWEEN 21248 AND 21375;

The MD5 hash = 801206aca6ee8b908095161db8d77585 . Which is now the same for
ANY of 128 scenes from 21248 through 21375 and therefore all in the same
memcache slab.

Now in code, pull up to 128 rows at a time (since a memcache slab can be
upto 1 MB, this should easily fit)

$b = boundaries_ul($this->id, 128);
$result = $con->fetch_query_pair("SELECT `scene_id`,
CONCAT(`like`,'|',`dislike`) FROM `scene_likes` WHERE `scene_id` BETWEEN
".$b['lower_bound']." AND ".$b['upper_bound']);
list($this->like, $this->dislike) = explode('|', $result[$this->id]); 

And with a little clever PHP slicing and dicing, I have an index right to
the scene_id and the dis/likes. fetch_query_pair() does just like it sounds,
it returns a hash/array where the $col[0] is the key and $col[1] is the
value since this is such a common thing to do.



--- End Message ---
--- Begin Message ---
On Thu, Feb 23, 2012 at 15:31, Daevid Vincent <dae...@daevid.com> wrote:
> Hey. To anyone that works on the php.net site. I posted this comment:
>
> http://www.php.net/manual/en/language.operators.bitwise.php#107617
>
> And I saw it there shortly after and even sent that link to some colleagues.
> Now it's gone on every mirror too. WTF?? :-( It certainly was relevant as it
> used & and ~.

    Some of the editors are overzealous and simply want to delete the
majority of notes for their own reasons.  I'm generally the one who
manages user note submissions, but the past several weeks I've been
overloaded with regular work and haven't been as involved in reviewing
and editing notes.

    You can see the action taken on your note here, as well as the
editor who chose to remove it (though no explanation was given):

        http://news.php.net/php.notes/186291

    You may want to contact them to see their reasoning for the removal.




> This is what it said basically (although this is a much longer
> version/explanation. The note post only had the code function and results).
>
> We've started to convert more of our queries to a "wide" mode and take even
> more advantage of memcache instead of a "thin" mode where we hit the DB (and
> store in memcache too) for each scene. The idea being that if we make the
> queries pull more data than needed (in an intelligent way of course) then we
> hit the DB less and memcache more. This works great with the concept of a
> DVD vs SCENE as one is macro and one is micro.
>
> I used some bitwise operations to figure out a lower/upper number for any
> given number (and offset).
>
> /**
>  * Get the upper and lower boundaries for any given number and 2^n offset
> (other offsets give bizarre results)
>  *
>  * @access      public
>  * @return      array
>  * @param       integer $number
>  * @param       integer $offset (32) must be a 2^n value [8, 16, 32, 64,
> 128, ...)
>  * @author      Daevid Vincent
>  * @date      2012-02-21
>  */
> function boundaries_ul($number, $offset=32)
> {
>        if ($offset < 8) return false; //nothing smaller than this makes
> practical sense
>        if (($offset & ($offset - 1)) != 0) return false; //not a 2^n
>
>        $offset = $offset - 1;
>
>        //zero out least significant bits.
>        //For example if $offset = 32, then the least 5 bits [16 8 4 2 1] ==
> 31 == 0xFFE0
>        $lowerbound = $number & ~$offset;
>        $upperbound = $lowerbound + $offset;
>
>        return array('lower_bound'=>$lowerbound,
> 'upper_bound'=>$upperbound);
> }
>
> for ($i = 0; $i < 20; $i++)
> {
>        debug_print($i, 'forloop $i decimal');
>        $b = boundaries_ul($i, 8);
>        var_dump($b);
>        echo "<hr>\n";
> }
> ?>
>
> ________________________________________
> forloop $i decimal = 3
> array
>  'lower_bound' => int 0
>  'upper_bound' => int 7
> ________________________________________
> forloop $i decimal = 4
> array
>  'lower_bound' => int 0
>  'upper_bound' => int 7
> ________________________________________
> forloop $i decimal = 5
> array
>  'lower_bound' => int 0
>  'upper_bound' => int 7
> ________________________________________
> ...
> ________________________________________
> forloop $i decimal = 12
> array
>  'lower_bound' => int 8
>  'upper_bound' => int 15
> ________________________________________
> forloop $i decimal = 13
> array
>  'lower_bound' => int 8
>  'upper_bound' => int 15
> ________________________________________
> forloop $i decimal = 14
> array
>  'lower_bound' => int 8
>  'upper_bound' => int 15
> ________________________________________
>
>
> In the get_like()/get_dislike(), we pull in both at the same time from the
> same table, which is great. But we can only pull in by scene_id and not a
> whole dvd_id (since we don't have the dvd_id in that table) as many of the
> other queries I'm converting. That got me thinking of how can I get more
> juice for the squeeze. Given that most scenes (if not all) are sequential
> that is a clue.
>
> We use the md5($sql) as the hash for memcache so that's why this works,
> since the same 128 scene_id's will all result in the same $sql query string
> (thanks to upper/lower bounds) and therefore the same hash key is pulled.
>
> Knowing these 'constants', I then fabricate a query for say scene_id = 21269
>
> var_dump(boundaries_ul(21269, 128));
>
> Which would look something like this:
>
> SELECT `scene_id`, `like`, `dislike` FROM `scene_likes` WHERE `scene_id`
> BETWEEN 21248 AND 21375;
>
> The MD5 hash = 801206aca6ee8b908095161db8d77585 . Which is now the same for
> ANY of 128 scenes from 21248 through 21375 and therefore all in the same
> memcache slab.
>
> Now in code, pull up to 128 rows at a time (since a memcache slab can be
> upto 1 MB, this should easily fit)
>
> $b = boundaries_ul($this->id, 128);
> $result = $con->fetch_query_pair("SELECT `scene_id`,
> CONCAT(`like`,'|',`dislike`) FROM `scene_likes` WHERE `scene_id` BETWEEN
> ".$b['lower_bound']." AND ".$b['upper_bound']);
> list($this->like, $this->dislike) = explode('|', $result[$this->id]);
>
> And with a little clever PHP slicing and dicing, I have an index right to
> the scene_id and the dis/likes. fetch_query_pair() does just like it sounds,
> it returns a hash/array where the $col[0] is the key and $col[1] is the
> value since this is such a common thing to do.
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>



-- 
</Daniel P. Brown>
Network Infrastructure Manager
http://www.php.net/

--- End Message ---
--- Begin Message ---
Just a quick question, will I be able to run Apache 2.4.1 and php
5.3.10 together? Or will I need to wait for php to be updated? I'm
setting this up on CentOs 6.2

Regards,

Daniel Fenn

--- End Message ---

Reply via email to