php-general Digest 4 Oct 2011 06:03:09 -0000 Issue 7503

Topics (messages 315115 through 315120):

Re: Variable question
        315115 by: Ford, Mike

Re: php.ini setting
        315116 by: Jim Giner
        315117 by: Richard Quadling
        315118 by: Jim Giner

Method C14N from DOM
        315119 by: QI.VOLMAR QI

Re: Oauth consumer and provider gives signature_invalid error
        315120 by: chamila gayan

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 ---
> -----Original Message-----
> From: Ron Piggott [mailto:ron....@actsministries.org]
> Sent: 01 October 2011 18:59
> To: php-gene...@lists.php.net
> Subject: [PHP] Variable question
> 
> 
> If $correct_answer has a value of 3 what is the correct syntax
> needed to use echo to display the value of $trivia_answer_3?
> 
> I know this is incorrect, but along the lines of what I am wanting
> to do:
> 
> echo $trivia_answer_$correct_answer;

Just for the record, one more way of doing what you asked for is:

    echo ${"trivia_answer_$correct_answer"};

But I totally agree with all the suggestions to use an array instead.

Cheers!

Mike

-- 
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,  
Portland PD507, City Campus, Leeds Metropolitan University,
Portland Way, LEEDS,  LS1 3HE,  United Kingdom 
E: m.f...@leedsmet.ac.uk     T: +44 113 812 4730



To view the terms under which this email is distributed, please go to 
http://disclaimer.leedsmet.ac.uk/email.htm

--- End Message ---
--- Begin Message ---
>
> <?php
> if (get_magic_quotes_gpc()) {
>     $process = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST);
>     while (list($key, $val) = each($process)) {
>         foreach ($val as $k => $v) {
>>>>             unset($process[$key][$k]);
>             if (is_array($v)) {
>                 $process[$key][stripslashes($k)] = $v;
>                 $process[] = &$process[$key][stripslashes($k)];
>             } else {
>                 $process[$key][stripslashes($k)] = stripslashes($v);
>             }
>         }
>     }
>     unset($process);
> }
> ?>
>
> I know it is not the answer you are looking for, but it does work, and 
> used by thousands of coders.
>
> Stephen
>
Thanks for the code sample - a little more complex than I've ever used.  Can 
you explain something for me?

The first "unset" line - what is it doing?  If it is removing the item from 
the $process array, then how can you then reference the value ($v) in the 
very next line?  I must be missing something.

Also - I don't see the need to be stripping slashes from the $k 
(keys/indices?) elements.  What am I missing there?

As I said - the lines are a something new to me and I may not be 
interpreting what is going on here.  Basically I see that you are processing 
all of the arrays (GET,POST, etc) at once, doing each one in turn.  For each 
one, you then get down to the values returned to the script as a $k/$v pair 
which you then check to see if it is in itself an array.(although you ask if 
$v is an array, while I would have thought you'd ask if $k was an array). 
Once you get to the basest element you remove the slashes.

Thanks again - still waiting on my host company to get back to me - they've 
escalated the problem of not being able to turn the quotes off.  Hmmm.... 



--- End Message ---
--- Begin Message ---
On 3 October 2011 14:30, Jim Giner <jim.gi...@albanyhandball.com> wrote:
> Thanks for the code sample - a little more complex than I've ever used.  Can
> you explain something for me?
>
> The first "unset" line - what is it doing?  If it is removing the item from
> the $process array, then how can you then reference the value ($v) in the
> very next line?  I must be missing something.
>
> Also - I don't see the need to be stripping slashes from the $k
> (keys/indices?) elements.  What am I missing there?
>
> As I said - the lines are a something new to me and I may not be
> interpreting what is going on here.  Basically I see that you are processing
> all of the arrays (GET,POST, etc) at once, doing each one in turn.  For each
> one, you then get down to the values returned to the script as a $k/$v pair
> which you then check to see if it is in itself an array.(although you ask if
> $v is an array, while I would have thought you'd ask if $k was an array).
> Once you get to the basest element you remove the slashes.
>
> Thanks again - still waiting on my host company to get back to me - they've
> escalated the problem of not being able to turn the quotes off.  Hmmm....

<?php
// Are magic quotes enabled?
if (get_magic_quotes_gpc()) {

   // Create an array of refererences to the GET, POST, COOKIE and
REQUEST super-globals.
   // Because these are references, any changes made to $process will
also be reflected
   // in the GET, POST, COOKIE and REQUEST super-globals.
   $process = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST);

   // Iterate each element in $process, creating $key and $val
   // $key is the index of $process and $val is the referenced
super-global array.
   while (list($key, $val) = each($process)) {

       // Iterate $val (the super global array), creating $k and $v
       // $k is the name of the entry in the super-global and $v is the value.
       foreach ($val as $k => $v) {

           // Remove the entry from the super-global.
           unset($process[$key][$k]);

           // Is the value an array.
           if (is_array($v)) {

               // Insert the value back into the super-global, but
strip slashes from the key.
               $process[$key][stripslashes($k)] = $v;

               // Because the value is an array, we don't want to
process it here.
               // Instead, append a reference to the value to the
$process array.
               // It will be picked up after the other super-globals
are processed by the while() line.
               $process[] = &$process[$key][stripslashes($k)];
           } else {
               // As the value is not an array, insert the stripped
value back into the super-global,
               // using a stripped key.
               $process[$key][stripslashes($k)] = stripslashes($v);
           }
       }
   }

   // All done, so remove $process also.
   unset($process);
}
?>




-- 
Richard Quadling
Twitter : EE : Zend : PHPDoc
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea

--- End Message ---
--- Begin Message ---
"Richard Quadling" <rquadl...@gmail.com> wrote in message 
news:CAKUjMCVwFos-=swewaoyxw2ukvhkwaueh6dahptycj-4wud...@mail.gmail.com...
On 3 October 2011 14:30, Jim Giner <jim.gi...@albanyhandball.com> wrote:
> Thanks for the code sample - a little more complex than I've ever used. 
> Can
> you explain something for me?
>
> The first "unset" line - what is it doing? If it is removing the item from
> the $process array, then how can you then reference the value ($v) in the
> very next line? I must be missing something.
>
> Also - I don't see the need to be stripping slashes from the $k
> (keys/indices?) elements. What am I missing there?
>
> As I said - the lines are a something new to me and I may not be
> interpreting what is going on here. Basically I see that you are 
> processing
> all of the arrays (GET,POST, etc) at once, doing each one in turn. For 
> each
> one, you then get down to the values returned to the script as a $k/$v 
> pair
> which you then check to see if it is in itself an array.(although you ask 
> if
> $v is an array, while I would have thought you'd ask if $k was an array).
> Once you get to the basest element you remove the slashes.
>

**************************
Thank you Richard for your effort, but I had the jist of all of this.  What 
I don't get is the points I asked about.  Can you answer the questions I 
mentioned? 



--- End Message ---
--- Begin Message ---
I've got this error:
*"Fatal error*: Call to undefined method DOMElement::C14N() in..."

My local server has the version 2.7.6 of libxml, and works fine. The
development server has the version 2.6.26
DOM/XML API Version 20031129.
This may be the problem? Or there's a dependency lost? or something like
this...

--- End Message ---
--- Begin Message ---
hi again.

it look likes my code is ugly so no one wants to play with it :D.

rewrote the consumer and provider code using only the php provided
classes/methods. I have borrowed code from
http://www.lornajane.net/posts/2011/php-oauth-provider-request-tokens and
http://toys.lerdorf.com/archives/55-Writing-an-OAuth-Provider-Service.html.

still it's same "invalid signature" exception. This time it's in
localhost,consumer on port 3000 and provider on port 5000.

new consumer code http://pastebin.com/ndEhP8Rv and provider code
http://pastebin.com/SfdKu3nQ . it's my second week struggling with this
code. any help would be really appreciate.

~Chamila Gayan



On Mon, Oct 3, 2011 at 12:34 PM, chamila gayan <cgcham...@gmail.com> wrote:

>
> hi All,
>
> I'm trying develop Oauth consumer and provider as very same way of twitter.
> I followed the below tutorials. Here is my  consumer code
> http://pastebin.com/39sxKbuz and here is my provider code
> http://pastebin.com/xtEsrTGf
>
> when I run the client it gives error as follow
>
> Array
> (
>     [oauth_problem] => signature_invalid
>     [debug_sbs] => GET
>     [http%253A%252F%252Fwww.abc.loc%252Foauth%252Frequesttoken] =>
>
> [oauth_consumer_key%253D1d7259a770e0732d191bb566b5cf9e%2526oauth_nonce%253Db4168962db5559eb55859f1699622d07%2526oauth_signature_method%253DHMAC-SHA1%2526oauth_timestamp%253D1317621581%2526oauth_version%253D1.0%2526route%253Doauth%25252Frequesttoken]
> =>
> )
>
> may be I'm doing this in a wrong way or not understood properly so your
> suggestions are  welcome. And I really appreciate if someone can explain
> what are the wrong codes here and how I correct them.   thanks a bunch .
>
>
> ~Chamila Gayan
>

--- End Message ---

Reply via email to