OSEC

Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com
php-general Digest 26 May 2008 17:34:49 -0000 Issue 5480

php-general-digest-helplists.php.net
Date: Mon May 26 2008 - 12:34:49 CDT


php-general Digest 26 May 2008 17:34:49 -0000 Issue 5480

Topics (messages 274683 through 274702):

scanned in & manipulate to a pdf
        274683 by: Ronald Wiplinger
        274698 by: Bastien Koert

Weird update problem..
        274684 by: Ryan S
        274685 by: Chris
        274687 by: Ryan S

Re: Image modifications
        274686 by: Chris
        274699 by: tedd

validating username
        274688 by: Sudhakar
        274691 by: Richard Heyes

Re: array recursion from database rows
        274689 by: Bob

how ROR is implemented in php
        274690 by: MukeshPandey82
        274692 by: Tony Marston
        274693 by: Hélio Rocha

exception handling
        274694 by: Sandro Felicioni
        274695 by: Runar Olsen
        274696 by: Thiago Pojda
        274697 by: Aschwin Wesselius

visibility + unserialization
        274700 by: Ted Wood
        274701 by: Ted Wood

How would you rewrite this snippet without using eval?
        274702 by: Luigi Perroti

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscribelists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscribelists.php.net

To post to the list, e-mail:
        php-generallists.php.net

----------------------------------------------------------------------

attached mail follows:


I got a Windows program, which can scan in a book by scanning in the pages
1,3,5, ....n turn the book by 180 degrees and scan in from the back side
n-1,n-3, ... 2. Then the program made a pdf book of the scanned in pages.

I am not sure if a php program is the right way to do, but I thought to do
the same by scanning in the pages (p0001, p0002, p0003, .....) and then work
on each page in a batch to turn p0001 by 180 degree and rename it to a0001,
rename p000(n-1) to a0002, turn p0002 by 180 degree and rename it to a0003
....
and add each page to a book.pdf

Is php right for that?

bye

Ronald

attached mail follows:


On Mon, May 26, 2008 at 12:47 AM, Ronald Wiplinger <tm.ronaldgmail.com>
wrote:

> I got a Windows program, which can scan in a book by scanning in the pages
> 1,3,5, ....n turn the book by 180 degrees and scan in from the back side
> n-1,n-3, ... 2. Then the program made a pdf book of the scanned in pages.
>
> I am not sure if a php program is the right way to do, but I thought to do
> the same by scanning in the pages (p0001, p0002, p0003, .....) and then
> work
> on each page in a batch to turn p0001 by 180 degree and rename it to a0001,
> rename p000(n-1) to a0002, turn p0002 by 180 degree and rename it to a0003
> ....
> and add each page to a book.pdf
>
> Is php right for that?
>
> bye
>
> Ronald
>

I would say no, not saying that you couldn't do it, but its not what its
really designed for. As PHP runs server side, you would need to have the
scanner available to the server, set up commands to allow php/apache access
to the pdf application, etc.

This is much more a c/c++/vb/.net type application.

--

Bastien

Cat, the other other white meat

attached mail follows:


This is really weird... i have tried the same exact code in phpmyadmin and it works like a charm, but when i run the script... no errors then i go to phpmyadmin and nothing has changed :(

this is the code:
============================================================================
$how_many_to_update=count($cardno_array);

// update the cards status to sent
for($i=0;$i<$how_many_to_update;$i++)
{
$update_sql="update greetings set is_sent=1 where cardno='".$cardno_array[$i]."' and rand_str='".$rand_str_array[$i]."' LIMIT 1";

$result = mysql_query($sql_1);
$num_rows1 = mysql_num_rows($result);

    if(!$result || $num_rows1==0){echo "Error: unable to update sent greetings";exit;}
echo "updating<br>$update_sql<br>";
}
=========================================================================

In the second last line you can see i have an echo statement... the SQL thats outputted from there works perfectly in phpmyadmin...
any idea whats wrong?

Slightly OT, any better way to run the multiple updates needed above than instead of running the update query in a loop?
I searched google and the best i could find was the IN() for mySql... but that does not take 2 parameters (eg: cardno and rand_str) it would work just on card_no like this in('14','34')

Thanks!
R

      

attached mail follows:


Ryan S wrote:
> This is really weird... i have tried the same exact code in phpmyadmin and it works like a charm, but when i run the script... no errors then i go to phpmyadmin and nothing has changed :(
>
> this is the code:
> ============================================================================
> $how_many_to_update=count($cardno_array);
>
> // update the cards status to sent
> for($i=0;$i<$how_many_to_update;$i++)
> {
> $update_sql="update greetings set is_sent=1 where cardno='".$cardno_array[$i]."' and rand_str='".$rand_str_array[$i]."' LIMIT 1";
>
> $result = mysql_query($sql_1);

You're running the wrong query.

You're building a query in "$update_sql" but running something else.

Change the mysql_query($sql_1) line and you should be right to go.

> Slightly OT, any better way to run the multiple updates needed above than instead of running the update query in a loop?
> I searched google and the best i could find was the IN() for mySql... but that does not take 2 parameters (eg: cardno and rand_str) it would work just on card_no like this in('14','34')

An IN() clause is the same as:

field='x' or field='y'

so you can use that:

update greetings set is_sent=1 where cardno='a' or cardno='b'

if you need the extra stuff (about the rand_str) you should be able to:

update greetings set is_sent=1 where (cardno='a' and rand_str='a') or
(cardno='b' and rand_str='b')

Try it with some test data first obviously.

Some of the comments here:

http://dev.mysql.com/doc/refman/5.0/en/update.html

Provide other suggestions.

--
Postgresql & php tutorials
http://www.designmagick.com/

attached mail follows:


<clip>
> $result = mysql_query($sql_1);

You're running the wrong query.

You're building a query in "$update_sql" but running something else.
</clip>
DUH!!!
Thats what you get for being up all night i guess! Time to hit the sack... pulled an all nighter and its 7:24am now

>Some of the comments here:

>http://dev.mysql.com/doc/refman/5.0/en/update.html

Thanks for all the help Chris, I appreciate it.

Cheers (and goodnite!)
R

      

attached mail follows:


Ronald Wiplinger wrote:
> I would like to find some samples to start with.
>
> We want to upload a picture and the user may apply some "filters" or
> "instructions" to create a new picture, based on the uploaded picture and
> the available "filters" and "instructions".
>
> The idea of it is not really mature, since we have no idea where to start
> and what is possible to do.

Depends. What do you want to do (what is a filter, what are instructions)?

imagemagick and to a (much?) lesser extent, gd - let you do image
manipulations but it depends what you need to be able to do.

--
Postgresql & php tutorials
http://www.designmagick.com/

attached mail follows:


At 12:40 PM +0800 5/26/08, Ronald Wiplinger wrote:
>I would like to find some samples to start with.
>
>We want to upload a picture and the user may apply some "filters" or
>"instructions" to create a new picture, based on the uploaded picture and
>the available "filters" and "instructions".
>
>The idea of it is not really mature, since we have no idea where to start
>and what is possible to do.
>
>bye
>
>R.

When you have an idea, try again.

Cheers,

tedd

--
-------
http://sperling.com http://ancientstones.com http://earthstones.com

attached mail follows:


i have used the following code to validate the username it is working fine

=============================================
if( $username == "" || !preg_match("/^[a-z0-9]+(?:_[a-z0-9]+)?$/i",
$username) )
{
$error.="User name cannot be blank or has special characters";
}
=============================================

it does not accept UNDERSCORE at the beginning or end however while i was
testing with different special characters except for # the validation works
fine for all other special characters.

for example if i enter the user name as = abc#123 in this case # sign and
what comes after # sign is being ignored. so in this case the username is
being read as abc ONLY and not abc#123

this is very strange, how can i still validate # sign and tell the user that
# sign is not a valid username like i have been doing with any other special
characters like = !$...........

please advice.

thanks.

attached mail follows:


Sudhakar wrote:
> ...

Seems to work fine here.

--
               Richard Heyes

          In Cambridge? Employ me
         http://www.phpguru.org/cv

+----------------------------------------+
| Access SSH with a Windows mapped drive |
| http://www.phpguru.org/sftpdrive |
+----------------------------------------+

attached mail follows:


Genius.

I was almost there in my own code, it was the _print_menu($items,
$parent_id) recursion that clinched it.

Many thanks (to all respondents) for your advice.

Cheers.

Bob.

-----Original Message-----
From: Larry Garfield
Sent: 25 May 2008 09:16
To: php-generallists.php.net
Subject: Re: [PHP] Re: array recursion from database rows

On Saturday 24 May 2008, Chris W wrote:
> Bob wrote:
> > Hi.
> >
> > I have a database table I have created for navigation.
> >
> > The table fields are uid, parent_id, menu_name.
> >
> > Each entry is either a top level element with a parent_id of 0 or a
child
> > which has a parent_id that relates to the parent uid.
> >
> > What I am trying to do is recurse through a set of rows adding the
> > child(ren) of a parent to a multi-dimensional array.
> >
> > Does anyone know how I can do this, I've tried (unsuccessfully) to
> > traverse the rows to create this array but I keep failing miserably.
> >
> > This is probably very easy for the people on this list so I am hoping
> > someone could help me out.
>
> I recently wrote a function to do just that. My data structure is a
> little different than yours. My table is called menuitems and is
> designed to store menu items for many different menus. But I do use the
> same ParentID concept you described to link sub menus in. I just call
> my function recessively. Here is a slightly simplified version of my
> function. I replaced the standard html tags with [ and ] to avoid
> stupid email clients trying to encode it as an html message.
>
>
> function PrintMenu($MenuID, $ParentItemID)
> {
> $query = "SELECT * \n";
> $query .= "FROM `menuitem` \n";
> $query .= "WHERE `MenuID` = '$MenuID' AND `ParentItemID` =
> '$ParentItemID' \n";
> $query .= "ORDER BY `OrderBy` \n";
> //print "[pre>$query[/pre>\n";
> $result = mysql_query($query);
> QueryErrorLog($result, $query, __FILE__, __LINE__, __FUNCTION__,
> mysql_error(), mysql_errno(), 1);
> if(mysql_num_rows($result) > 0){
> print "[ul]\n";
> while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){
> foreach($row as $TmpVar => $TmpValue){
> $$TmpVar = $TmpValue;
> }
> print "[li][a href='$URL']$Title[/a][/li]\n";
> PrintMenu($MenuID, $MenuItemID);
> }
> print "[/ul]\n";
> }
>
> }

That's bad, because it will run a variable number of SQL queries.

It's better to pull all of the data at once, and then recurse over that data

structure. To wit (off the cuff and not tested, using PDO syntax for the
database):

function print_menu() {
  $items = array();
  $db = db_connection();
  $result = $db->query("SELECT menu_id, parent_id, name FROM menu_items
ORDER
BY name");
  foreach ($result as $record) {
    $items[$record->parent_id][$record->menu_id] = $record;
  }

  $output = _print_menu($items, 0);

  return $output;
}

function _print_menu($items, $parent_id) {
  $output = '';

  if (!empty($items[$parent_id])) {
    foreach ($items[$parent_id] as $menu_id => $item) {
      $output .= '<li>' . $item->name . _menu_print($items,
$menu_id) . '</li>';
    }
  }

  return $output ? "<ul>$output</ul>" : '';
}

That way you run only one SQL query, and by pre-grouping you can reduce your

iterations as well.

--
Larry Garfield AIM: LOLG42
larrygarfieldtech.com ICQ: 6817012

"If nature has made any one thing less susceptible than all others of
exclusive property, it is the action of the thinking power called an idea,
which an individual may exclusively possess as long as he keeps it to
himself; but the moment it is divulged, it forces itself into the possession

of every one, and the receiver cannot dispossess himself of it." -- Thomas
Jefferson

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

attached mail follows:


Mukesh pandey
(http://www.seospecialistindia.com)
Sanework Technologies Private Limited
405, Super Plaza, Nr. Lad Society, Sandesh Press Road,
Vastrapur, Ahmedabad - 380 015. INDIA
Phone : +91 - 79 - 30125030, 65124030
Telefax : +91 - 79 - 30125030
Email : infosanework.com
Web : www.sanework.com

--
View this message in context: http://www.nabble.com/how-ROR-is-implemented-in-php-tp17468188p17468188.html
Sent from the PHP - General mailing list archive at Nabble.com.

attached mail follows:


This is a stupid question. RoR is a combination of a language (Ruby) and a
framework (Rails), so asking how to implement the Ruby language in the PHP
language simply does not compute.

I suspect that the real question is "how is the Rails framework implemented
in PHP?", in which case it is easier to provide answers:

(a) The Rails framework was written specifically in the Ruby language, so
does not come with an implementation in the PHP language.

(b) It is possible that some developers may have created a clone of the
Rails framework in PHP, but there is no guarantee that they would be
anything like the original.

Besides, if you really want to use the Rails framework why don't you want to
use the language it was written in?

If you really want a PHP implementation of the Rails framework then why
can't you write it yourself?

Better still, why not try to find a PHP framework which is comparable to (or
even better than) RoR?

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

"MukeshPandey82" <mukeshpandey82gmail.com> wrote in message
news:17468188.posttalk.nabble.com...
>
>
>
> Mukesh pandey
> (http://www.seospecialistindia.com)
> Sanework Technologies Private Limited
> 405, Super Plaza, Nr. Lad Society, Sandesh Press Road,
> Vastrapur, Ahmedabad - 380 015. INDIA
> Phone : +91 - 79 - 30125030, 65124030
> Telefax : +91 - 79 - 30125030
> Email : infosanework.com
> Web : www.sanework.com
>
> --
> View this message in context:
> http://www.nabble.com/how-ROR-is-implemented-in-php-tp17468188p17468188.html
> Sent from the PHP - General mailing list archive at Nabble.com.
>

attached mail follows:


www.*cakephp*.org/

On Mon, May 26, 2008 at 9:54 AM, MukeshPandey82 <mukeshpandey82gmail.com>
wrote:

>
>
>
> Mukesh pandey
> (http://www.seospecialistindia.com)
> Sanework Technologies Private Limited
> 405, Super Plaza, Nr. Lad Society, Sandesh Press Road,
> Vastrapur, Ahmedabad - 380 015. INDIA
> Phone : +91 - 79 - 30125030, 65124030
> Telefax : +91 - 79 - 30125030
> Email : infosanework.com
> Web : www.sanework.com
>
> --
> View this message in context:
> http://www.nabble.com/how-ROR-is-implemented-in-php-tp17468188p17468188.html
> Sent from the PHP - General mailing list archive at Nabble.com.
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

attached mail follows:


Hello,

I've a question regarding the exception handling in PHP 5.

In my php script I created a try catch block in order to catch throwing exceptions. The problem is that my try - block starts at the end of a php file, but ends in a different one. This always leads to the following error: "Parse error: syntax error, unexpected $end ".

I hope you could tell me how to resolve this problem.

Thanks and kind regards
Sandro Felicioni

e.g.:

start top.php
-------------

try{

end top.php
-----------

start main.php
--------------

require_once("top.php");

execute some critical php code

}catch(Exception $e){
  doSomething();
}

end main.php
--------------
end main.php
------------

--
GMX startet ShortView.de. Hier findest Du Leute mit Deinen Interessen!
Jetzt dabei sein: http://www.shortview.de/?mc=sv_ext_mfgmx

attached mail follows:


Sandro Felicioni wrote:
> Hello,
>
> I've a question regarding the exception handling in PHP 5.
>
> In my php script I created a try catch block in order to catch throwing exceptions. The problem is that my try - block starts at the end of a php file, but ends in a different one. This always leads to the following error: "Parse error: syntax error, unexpected $end ".
>
> I hope you could tell me how to resolve this problem.
>
> Thanks and kind regards
> Sandro Felicioni
>
> e.g.:
>
> start top.php
> -------------
>
> try{
>
> end top.php
> -----------
>
> start main.php
> --------------
>
> require_once("top.php");
>
> execute some critical php code
>
> }catch(Exception $e){
> doSomething();
> }
>
> end main.php
> --------------
> end main.php
> ------------
>
>
Hello,

PHP considers each file a separate php script and because of that you
will have to end any blocks opened before the file ends. The way you're
doing it in your example would simply not work. Try putting the try
block and the start of main.php.

Runar

attached mail follows:


Someone please correct me if I'm wrong but I'm not sure you can do that at
all, it's not like building HTML files, PHP needs to parse it before
executing.

Atenciosamente,
www.softpartech.com.br
Thiago Henrique Pojda
Desenvolvimento Web
+55 41 3033-7676
thiago.pojdasoftpartech.com.br
Excelência em Softwares Financeiros
-----Mensagem original-----
De: Sandro Felicioni [mailto:s.felicionigmx.ch]
Enviada em: domingo, 25 de maio de 2008 11:20
Para: php-generallists.php.net
Assunto: [PHP] exception handling

Hello,

I've a question regarding the exception handling in PHP 5.

In my php script I created a try catch block in order to catch throwing
exceptions. The problem is that my try - block starts at the end of a php
file, but ends in a different one. This always leads to the following error:
"Parse error: syntax error, unexpected $end ".

I hope you could tell me how to resolve this problem.

Thanks and kind regards
Sandro Felicioni

e.g.:

start top.php
-------------

try{

end top.php
-----------

start main.php
--------------

require_once("top.php");

execute some critical php code

}catch(Exception $e){
  doSomething();
}

end main.php
--------------
end main.php
------------

--
GMX startet ShortView.de. Hier findest Du Leute mit Deinen Interessen!
Jetzt dabei sein: http://www.shortview.de/?mc=sv_ext_mfgmx

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

attached mail follows:


Thiago Pojda wrote:
> Hello,
>
> I've a question regarding the exception handling in PHP 5.
>
> In my php script I created a try catch block in order to catch throwing
> exceptions. The problem is that my try - block starts at the end of a php
> file, but ends in a different one. This always leads to the following error:
> "Parse error: syntax error, unexpected $end ".
>
> I hope you could tell me how to resolve this problem.
>
> Thanks and kind regards
> Sandro Felicioni
>
> e.g.:
>
> start top.php
> -------------
>
> try{
>
> end top.php
> -----------
>
> start main.php
> --------------
>
> require_once("top.php");
>
> execute some critical php code
>
> }catch(Exception $e){
> doSomething();
> }
>
> end main.php
> --------------
> end main.php
> ------------

Hi,

Maybe you can read upon it about 'trigger_error':

http://www.php.net/*trigger_error

*
--

Aschwin Wesselius

/'What you would like to be done to you, do that to the other....'/

attached mail follows:


I have a 4 year old framework that serializes objects and stores them
in the database. It is now going PHP 5-only, so I began to add
visibility to the class definitions of the serialized objects.
However, then things didn't work properly after objects stored [before
the visibility was added] were unserialized. For example, each
protected field ended up creating two fields, with one followed by
":protected".

Expected Result:
----------------------

object(Foo) {
  ["bar"]=>
  string(0) "banana"
}

Actual Result:
----------------------

object(Foo) {
  ["bar:protected"]=>
  string(0) ""
  ["bar"]=>
   string(6) "banana"
}

Anybody run into this, or can explain why this might be and how I can
avoid it?

Thanks,

~Ted

attached mail follows:


Small correction on my details:

Actual Result:
----------------------

object(Foo) {
["bar:protected"]=>
string(0) "banana"
["bar"]=>
  string(6) ""
}

The value of my existing field, which has since been given "protected"
visibility, is now stored in the "bar:protected" field after
deserialization, and thus not accessible to the application code.

~Ted

attached mail follows:


Hi all,

I'm rewriting a script trying to avoid using functions that might pose
a security threat if used incorrectly.
I have a portion of code that looks like the one pasted below.
I don't seem to be able to avoid using eval without introducing too
many changes, losing in simplicity.

Here's the code:

<?php

echo Logic::getFirstValue(); // Output: first value

class Logic {
        public static function getFirstValue() {
                return Data::getData('$firstArray','firstKey');
        }
}

class Data {
        private static $firstArray = array ('firstKey'=>'first value');
        private static $secondArray = array ('secondKey'=>'second value');
        public static function getData($array, $key) {
                $string = 'return self::'.$array.'[\''.$key.'\'];';
                return eval ($string);
        }
}

?>

How would you rewrite the snippet without using eval and still keeping
things very straightforward?

Thanks for your attention!