php-general Digest 25 Nov 2009 20:31:08 -0000 Issue 6460

Topics (messages 300088 through 300099):

Class not returning value
        300088 by: Pieter du Toit
        300089 by: Peter Ford
        300090 by: Pieter du Toit
        300091 by: Pieter du Toit

Re: function not returning query
        300092 by: Ashley Sheridan

Re: processing html forms and keeping the values
        300093 by: Raymond Irving
        300094 by: Merlin Morgenstern
        300097 by: Kim Madsen

Re: Create client certificate with openssl
        300095 by: Ryan Sun

Re: php mail() function
        300096 by: James Prentice
        300098 by: James Prentice

Detecting The Encoding Of A Text File
        300099 by: Nitsan Bin-Nun

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 ---
Hi

This is my first class and it does not work, i do a return 
$this->responseArray; with the public function getResult() method, but get 
nothing. Can someone please help me.

Thsi is how i create the object
$number = new Smsgate($cell_numbers, $message, "27823361602", "27");
$result = $number->getResult();

Here is the code:
<?php

/**
 *
 * @version 1.0
 * @copyright 2009
 */

/**
 */
class Smsgate {

    protected $number;
    protected $message;
    protected $sender_id;
    protected $tofind;
    private $result;
    /**
     * Constructor
     */
    function __construct($number = "", $message = "", $sender_id = "", 
$tofind = "")
    {

        $this->message = $message;
        $this->number = $number;
        $this->sender_id = $sender_id;
        $this->tofind = $tofind;
    }

    protected function display ($result)
    {
        return $result;
    }

    public function getResult()
    {
        return $this->processRequest();

    }
    public function numberErrors()
    {
        return $this->errorResult;
    }

    /**
     * Smsgate::checknumbers()
     *
     * @return array of correct and incorrect formatted numbers
     */
    private function processRequest()
    {
        echo "nou by numers";
        print_r($this->number);
        // check if the property is an array and add to new array for 
sending
        if (is_array($this->number)) {
            // check for starting digits
            $this->result = "";
            // loop through numbers and check for errors
            foreach ($this->number as $this->val) {

                $this->position = strpos($this->val , $this->tofind);

                // number correct
                if ($this->position === 0) {
                    echo "is integer <br/>";
                    if ($this->result != "") {
                        $this->result .= ",";
                    }
                    // create comma seperated numbers to send as bulk in 
sendSMS method
                    $this->result .= $this->val; //infobip multiple 
recipients must be seperated by comma
                    // create an array to use with responseStringExplode in 
sendSMS method
                    $this->cellarray[] = $this->val;
                    echo "Result is " . $this->result . "<br>";
                } else {
                    // numbers not in correct format
                    $this->errorResult[] = $this->val;
                }

            } //end foreach
   $this->sendSMS();

        } else {
            $this->result = "Not ok";
         return $this->result;
        }

    }

    private function sendSMS()
    {

        $this->smsUrl = 
'http://www.infobip.com/Addon/SMSService/SendSMS.aspx?user=xxxx&password=xxxx';
        $this->post_data = '&sender=' . $this->sender_id . '&SMSText=' . 
urlencode($this->message) . '&IsFlash=0&GSM=' . $this->result;
        $this->sendData = $this->sendWithCurl($this->smsUrl, 
$this->post_data);
        $this->responseStringExplode = explode("\n", $this->sendData);

     $count=0;
        foreach ($this->responseStringExplode as $this->rvalue) {
          $this->responseArray[$this->rvalue] = ($this->cellarray[$count]);
          $count = ++$count;
        }
     return $this->responseArray;
    }
 private function sendWithCurl($url, $postData) {
  if (!is_resource($this->connection_handle)) {
   // Try to create one
   if (!$this->connection_handle = curl_init()) {
    trigger_error('Could not start new CURL instance');
    $this->error = true;
    return;
   }
  }
  curl_setopt($this->connection_handle, CURLOPT_URL, $url);
  curl_setopt ($this->connection_handle, CURLOPT_POST, 1);
  $post_fields = $postData;
  curl_setopt ($this->connection_handle, CURLOPT_POSTFIELDS, $post_fields);
  curl_setopt($this->connection_handle, CURLOPT_RETURNTRANSFER, 1);
  $this->response_string = curl_exec($this->connection_handle);
  curl_close($this->connection_handle);
  return $this->response_string;
 }
}

?> 



--- End Message ---
--- Begin Message ---
Pieter du Toit wrote:
> Hi
> 
> This is my first class and it does not work, i do a return 
> $this->responseArray; with the public function getResult() method, but get 
> nothing. Can someone please help me.
> 
> Thsi is how i create the object
> $number = new Smsgate($cell_numbers, $message, "27823361602", "27");
> $result = $number->getResult();
> 
> Here is the code:
> <?php
> 
> /**
>  *
>  * @version 1.0
>  * @copyright 2009
>  */
> 
> /**
>  */
> class Smsgate {
> 
>     protected $number;
>     protected $message;
>     protected $sender_id;
>     protected $tofind;
>     private $result;
>     /**
>      * Constructor
>      */
>     function __construct($number = "", $message = "", $sender_id = "", 
> $tofind = "")
>     {
> 
>         $this->message = $message;
>         $this->number = $number;
>         $this->sender_id = $sender_id;
>         $this->tofind = $tofind;
>     }
> 
>     protected function display ($result)
>     {
>         return $result;
>     }
> 
>     public function getResult()
>     {
>         return $this->processRequest();
> 
>     }
>     public function numberErrors()
>     {
>         return $this->errorResult;
>     }
> 
>     /**
>      * Smsgate::checknumbers()
>      *
>      * @return array of correct and incorrect formatted numbers
>      */
>     private function processRequest()
>     {
>         echo "nou by numers";
>         print_r($this->number);
>         // check if the property is an array and add to new array for 
> sending
>         if (is_array($this->number)) {
>             // check for starting digits
>             $this->result = "";
>             // loop through numbers and check for errors
>             foreach ($this->number as $this->val) {
> 
>                 $this->position = strpos($this->val , $this->tofind);
> 
>                 // number correct
>                 if ($this->position === 0) {
>                     echo "is integer <br/>";
>                     if ($this->result != "") {
>                         $this->result .= ",";
>                     }
>                     // create comma seperated numbers to send as bulk in 
> sendSMS method
>                     $this->result .= $this->val; //infobip multiple 
> recipients must be seperated by comma
>                     // create an array to use with responseStringExplode in 
> sendSMS method
>                     $this->cellarray[] = $this->val;
>                     echo "Result is " . $this->result . "<br>";
>                 } else {
>                     // numbers not in correct format
>                     $this->errorResult[] = $this->val;
>                 }
> 
>             } //end foreach
>    $this->sendSMS();
> 
>         } else {
>             $this->result = "Not ok";
>          return $this->result;
>         }
> 
>     }
> 
>     private function sendSMS()
>     {
> 
>         $this->smsUrl = 
> 'http://www.infobip.com/Addon/SMSService/SendSMS.aspx?user=xxxx&password=xxxx';
>         $this->post_data = '&sender=' . $this->sender_id . '&SMSText=' . 
> urlencode($this->message) . '&IsFlash=0&GSM=' . $this->result;
>         $this->sendData = $this->sendWithCurl($this->smsUrl, 
> $this->post_data);
>         $this->responseStringExplode = explode("\n", $this->sendData);
> 
>      $count=0;
>         foreach ($this->responseStringExplode as $this->rvalue) {
>           $this->responseArray[$this->rvalue] = ($this->cellarray[$count]);
>           $count = ++$count;
>         }
>      return $this->responseArray;
>     }
>  private function sendWithCurl($url, $postData) {
>   if (!is_resource($this->connection_handle)) {
>    // Try to create one
>    if (!$this->connection_handle = curl_init()) {
>     trigger_error('Could not start new CURL instance');
>     $this->error = true;
>     return;
>    }
>   }
>   curl_setopt($this->connection_handle, CURLOPT_URL, $url);
>   curl_setopt ($this->connection_handle, CURLOPT_POST, 1);
>   $post_fields = $postData;
>   curl_setopt ($this->connection_handle, CURLOPT_POSTFIELDS, $post_fields);
>   curl_setopt($this->connection_handle, CURLOPT_RETURNTRANSFER, 1);
>   $this->response_string = curl_exec($this->connection_handle);
>   curl_close($this->connection_handle);
>   return $this->response_string;
>  }
> }
> 
> ?> 
> 
> 


Based on a first scan of your code, it looks like the only return in
processRequest() is inside the else block, so nothing is returned unless the
processing fails.

-- 
Peter Ford                              phone: 01580 893333
Developer                               fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

--- End Message ---
--- Begin Message ---
Sorry i found the problem, need to do this:
public function getResult()
    {
        $this->processRequest();
     return $this->responseArray;

    }

""Pieter du Toit"" <pie...@lpwebdesign.co.za> wrote in message 
news:57.90.33335.88fec...@pb1.pair.com...
> Hi
>
> This is my first class and it does not work, i do a return 
> $this->responseArray; with the public function getResult() method, but get 
> nothing. Can someone please help me.
>
> Thsi is how i create the object
> $number = new Smsgate($cell_numbers, $message, "27823361602", "27");
> $result = $number->getResult();
>
> Here is the code:
> <?php
>
> /**
> *
> * @version 1.0
> * @copyright 2009
> */
>
> /**
> */
> class Smsgate {
>
>    protected $number;
>    protected $message;
>    protected $sender_id;
>    protected $tofind;
>    private $result;
>    /**
>     * Constructor
>     */
>    function __construct($number = "", $message = "", $sender_id = "", 
> $tofind = "")
>    {
>
>        $this->message = $message;
>        $this->number = $number;
>        $this->sender_id = $sender_id;
>        $this->tofind = $tofind;
>    }
>
>    protected function display ($result)
>    {
>        return $result;
>    }
>
>    public function getResult()
>    {
>        return $this->processRequest();
>
>    }
>    public function numberErrors()
>    {
>        return $this->errorResult;
>    }
>
>    /**
>     * Smsgate::checknumbers()
>     *
>     * @return array of correct and incorrect formatted numbers
>     */
>    private function processRequest()
>    {
>        echo "nou by numers";
>        print_r($this->number);
>        // check if the property is an array and add to new array for 
> sending
>        if (is_array($this->number)) {
>            // check for starting digits
>            $this->result = "";
>            // loop through numbers and check for errors
>            foreach ($this->number as $this->val) {
>
>                $this->position = strpos($this->val , $this->tofind);
>
>                // number correct
>                if ($this->position === 0) {
>                    echo "is integer <br/>";
>                    if ($this->result != "") {
>                        $this->result .= ",";
>                    }
>                    // create comma seperated numbers to send as bulk in 
> sendSMS method
>                    $this->result .= $this->val; //infobip multiple 
> recipients must be seperated by comma
>                    // create an array to use with responseStringExplode in 
> sendSMS method
>                    $this->cellarray[] = $this->val;
>                    echo "Result is " . $this->result . "<br>";
>                } else {
>                    // numbers not in correct format
>                    $this->errorResult[] = $this->val;
>                }
>
>            } //end foreach
>   $this->sendSMS();
>
>        } else {
>            $this->result = "Not ok";
>         return $this->result;
>        }
>
>    }
>
>    private function sendSMS()
>    {
>
>        $this->smsUrl = 
> 'http://www.infobip.com/Addon/SMSService/SendSMS.aspx?user=xxxx&password=xxxx';
>        $this->post_data = '&sender=' . $this->sender_id . '&SMSText=' . 
> urlencode($this->message) . '&IsFlash=0&GSM=' . $this->result;
>        $this->sendData = $this->sendWithCurl($this->smsUrl, 
> $this->post_data);
>        $this->responseStringExplode = explode("\n", $this->sendData);
>
>     $count=0;
>        foreach ($this->responseStringExplode as $this->rvalue) {
>          $this->responseArray[$this->rvalue] = ($this->cellarray[$count]);
>          $count = ++$count;
>        }
>     return $this->responseArray;
>    }
> private function sendWithCurl($url, $postData) {
>  if (!is_resource($this->connection_handle)) {
>   // Try to create one
>   if (!$this->connection_handle = curl_init()) {
>    trigger_error('Could not start new CURL instance');
>    $this->error = true;
>    return;
>   }
>  }
>  curl_setopt($this->connection_handle, CURLOPT_URL, $url);
>  curl_setopt ($this->connection_handle, CURLOPT_POST, 1);
>  $post_fields = $postData;
>  curl_setopt ($this->connection_handle, CURLOPT_POSTFIELDS, $post_fields);
>  curl_setopt($this->connection_handle, CURLOPT_RETURNTRANSFER, 1);
>  $this->response_string = curl_exec($this->connection_handle);
>  curl_close($this->connection_handle);
>  return $this->response_string;
> }
> }
>
> ?>
> 



--- End Message ---
--- Begin Message ---
Thanks for th reply Peter

i call this method on success
$this->sendSMS();

But i sorted the problem with this:
 public function getResult()
    {
        $this->processRequest();
     return $this->responseArray;

    }

"Peter Ford" <p...@justcroft.com> wrote in message 
news:cf.a1.33335.d5cfc...@pb1.pair.com...
> Pieter du Toit wrote:
>> Hi
>>
>> This is my first class and it does not work, i do a return
>> $this->responseArray; with the public function getResult() method, but 
>> get
>> nothing. Can someone please help me.
>>
>> Thsi is how i create the object
>> $number = new Smsgate($cell_numbers, $message, "27823361602", "27");
>> $result = $number->getResult();
>>
>> Here is the code:
>> <?php
>>
>> /**
>>  *
>>  * @version 1.0
>>  * @copyright 2009
>>  */
>>
>> /**
>>  */
>> class Smsgate {
>>
>>     protected $number;
>>     protected $message;
>>     protected $sender_id;
>>     protected $tofind;
>>     private $result;
>>     /**
>>      * Constructor
>>      */
>>     function __construct($number = "", $message = "", $sender_id = "",
>> $tofind = "")
>>     {
>>
>>         $this->message = $message;
>>         $this->number = $number;
>>         $this->sender_id = $sender_id;
>>         $this->tofind = $tofind;
>>     }
>>
>>     protected function display ($result)
>>     {
>>         return $result;
>>     }
>>
>>     public function getResult()
>>     {
>>         return $this->processRequest();
>>
>>     }
>>     public function numberErrors()
>>     {
>>         return $this->errorResult;
>>     }
>>
>>     /**
>>      * Smsgate::checknumbers()
>>      *
>>      * @return array of correct and incorrect formatted numbers
>>      */
>>     private function processRequest()
>>     {
>>         echo "nou by numers";
>>         print_r($this->number);
>>         // check if the property is an array and add to new array for
>> sending
>>         if (is_array($this->number)) {
>>             // check for starting digits
>>             $this->result = "";
>>             // loop through numbers and check for errors
>>             foreach ($this->number as $this->val) {
>>
>>                 $this->position = strpos($this->val , $this->tofind);
>>
>>                 // number correct
>>                 if ($this->position === 0) {
>>                     echo "is integer <br/>";
>>                     if ($this->result != "") {
>>                         $this->result .= ",";
>>                     }
>>                     // create comma seperated numbers to send as bulk in
>> sendSMS method
>>                     $this->result .= $this->val; //infobip multiple
>> recipients must be seperated by comma
>>                     // create an array to use with responseStringExplode 
>> in
>> sendSMS method
>>                     $this->cellarray[] = $this->val;
>>                     echo "Result is " . $this->result . "<br>";
>>                 } else {
>>                     // numbers not in correct format
>>                     $this->errorResult[] = $this->val;
>>                 }
>>
>>             } //end foreach
>>    $this->sendSMS();
>>
>>         } else {
>>             $this->result = "Not ok";
>>          return $this->result;
>>         }
>>
>>     }
>>
>>     private function sendSMS()
>>     {
>>
>>         $this->smsUrl =
>> 'http://www.infobip.com/Addon/SMSService/SendSMS.aspx?user=xxxx&password=xxxx';
>>         $this->post_data = '&sender=' . $this->sender_id . '&SMSText=' .
>> urlencode($this->message) . '&IsFlash=0&GSM=' . $this->result;
>>         $this->sendData = $this->sendWithCurl($this->smsUrl,
>> $this->post_data);
>>         $this->responseStringExplode = explode("\n", $this->sendData);
>>
>>      $count=0;
>>         foreach ($this->responseStringExplode as $this->rvalue) {
>>           $this->responseArray[$this->rvalue] = 
>> ($this->cellarray[$count]);
>>           $count = ++$count;
>>         }
>>      return $this->responseArray;
>>     }
>>  private function sendWithCurl($url, $postData) {
>>   if (!is_resource($this->connection_handle)) {
>>    // Try to create one
>>    if (!$this->connection_handle = curl_init()) {
>>     trigger_error('Could not start new CURL instance');
>>     $this->error = true;
>>     return;
>>    }
>>   }
>>   curl_setopt($this->connection_handle, CURLOPT_URL, $url);
>>   curl_setopt ($this->connection_handle, CURLOPT_POST, 1);
>>   $post_fields = $postData;
>>   curl_setopt ($this->connection_handle, CURLOPT_POSTFIELDS, 
>> $post_fields);
>>   curl_setopt($this->connection_handle, CURLOPT_RETURNTRANSFER, 1);
>>   $this->response_string = curl_exec($this->connection_handle);
>>   curl_close($this->connection_handle);
>>   return $this->response_string;
>>  }
>> }
>>
>> ?>
>>
>>
>
>
> Based on a first scan of your code, it looks like the only return in
> processRequest() is inside the else block, so nothing is returned unless 
> the
> processing fails.
>
> -- 
> Peter Ford                              phone: 01580 893333
> Developer                               fax:   01580 893399
> Justcroft International Ltd., Staplehurst, Kent 



--- End Message ---
--- Begin Message ---
On Tue, 2009-11-24 at 23:27 -0800, Allen McCabe wrote:

> If I were to loop through my inputs, I could just exclude any
> problematic names, eg.:
> 
> foreach ($_POST as $var = $val)
> {
>    if ($var != filter.x || $var != filter.y)
>   {
>     $var = $val;
>   }
> }
> 
> Like that?
> 
> 
> On Tue, Nov 24, 2009 at 2:34 AM, Ashley Sheridan
> <a...@ashleysheridan.co.uk> wrote:
> 
>         
>         On Tue, 2009-11-24 at 02:11 -0800, Allen McCabe wrote:
>         
>         > I am! Will these extra query variables cause any problems or
>         > should I use standard submit inputs?
>         > 
>         > Thanks Ashley!
>         > 
>         > On Tue, Nov 24, 2009 at 1:10 AM, Ashley Sheridan
>         > <a...@ashleysheridan.co.uk> wrote:
>         > 
>         >         
>         >         On Mon, 2009-11-23 at 21:53 -0800, Allen McCabe
>         >         wrote: 
>         >         
>         >         > Okay, suddenly I got it to filter the results, but I 
> still can't figure out
>         >         > where this part of the query is coming from, at the end 
> of the query string
>         >         > in the URL, I have this "filter.x=0&filter.y=0".
>         >         > 
>         >         > No where in my form do I have a field named filter.x or 
> filter.y. I DO
>         >         > however, have 3 forms (I don't want to mess with AJAX), 
> my set up looks like
>         >         > this:
>         >         > 
>         >         > Filter by:
>         >         > User - [username dropdown  v] Order by [database fields  
> v] Asc/Desc
>         >         > [Ascend  v] - Go
>         >         > School - [school dropdown  v] Order by [database fields  
> v] Asc/Desc
>         >         > [Ascend  v] - Go
>         >         > Show - [show dropdown  v] Order by [database fields  v] 
> Asc/Desc [Ascend  v]
>         >         > - Go
>         >         > 
>         >         > There are actually two order by fields, but this gives 
> you the idea. Each of
>         >         > the three lines is a separate form, each with a unique 
> name all with a "get"
>         >         > method, but all three Go buttons are named "filter", I 
> didn't think to try
>         >         > changing it until now, but is this perhaps where the 
> filter.x and filter.y
>         >         > are coming from? I have never seen this before in a query.
>         >         > 
>         >         > Oh, now the filter that was working spontaneously gives 
> me the error I have
>         >         > been getting all along, this is so frustrating.
>         >         > 
>         >         > To those who asked, yes I am connected to the database; I 
> forgot to mention
>         >         > that the else part of my if statement works, as long as I 
> don't try to
>         >         > filter my results it works.
>         >         > 
>         >         > Here is an example of the URL that my filter function 
> (via one of the 3
>         >         > forms) outputs:
>         >         > 
> http://lpacmarketing.hostzi.com/afy/orders/default.php?filterby=school&schoolid=36&orderby1=order_id&asc_desc_order1=Descend&orderby2=pmt_recd_date&asc_desc_order2=Descend&filter.x=13&filter.y=8&filter=Go
>         >         > 
>         >         > On Mon, Nov 23, 2009 at 8:03 PM, Philip Thompson 
> <philthath...@gmail.com>wrote:
>         >         > 
>         >         > > On Nov 23, 2009, at 6:22 PM, Allen McCabe wrote:
>         >         > >
>         >         > > > Hi, thanks for reading, I hope you can help:
>         >         > > >
>         >         > > > In my main file for an orders page I have the 
> following code:
>         >         > > >
>         >         > > >
>         >         > > > if (isset($_GET['filterby']))
>         >         > > > {
>         >         > > >  $resultOrders = adminFilterQuery();
>         >         > > >  $numberOfOrders = mysql_num_rows($resultOrders);
>         >         > > > }
>         >         > > > else
>         >         > > > {
>         >         > > >  $resultOrders = mysql_query("SELECT * FROM 
> afy_order;") or
>         >         > > > die(mysql_error("Could not query the database!"));
>         >         > > >  $numberOfOrders = mysql_num_rows($resultOrders);
>         >         > > > }
>         >         > >
>         >         > > You reduce this part by one line by putting the 
> following after the else
>         >         > > statement and removing the other 2:
>         >         > >
>         >         > > $numberOfOrders = mysql_num_rows ($resultOrders);
>         >         > >
>         >         > > Also, these queries don't need a semi-colon (;) to end 
> the query. PHP
>         >         > > handles this part. Remove them.
>         >         > >
>         >         > >
>         >         > > > adminFilterQuery() is a custom function that is 
> supposed to return a
>         >         > > > mysql_query, here are the last few lines of this 
> function:
>         >         > > >
>         >         > > >
>         >         > > > $query = "SELECT * FROM afy_order WHERE school_id = 
> '{$school}' ORDER BY
>         >         > > > {$order_by_param};";
>         >         > > > $result = mysql_query($query);
>         >         > > > return $result;
>         >         > > >
>         >         > > > l am getting this error when I try to filter my query 
> using a form in
>         >         > > tandem
>         >         > > > with the quey building function:
>         >         > > >
>         >         > > > *Warning*: mysql_num_rows(): supplied argument is not 
> a valid MySQL
>         >         > > result
>         >         > > > resource
>         >         > > >
>         >         > > > where the line is the one where I use the 
> mysql_num_rows function.
>         >         > > >
>         >         > > > What am I missing here?
>         >         > > >
>         >         > > > Thanks!
>         >         > >
>         >         > > Do you get this warning with both queries? Make sure 
> that your queries are
>         >         > > using a valid mysql connection. You may also consider 
> using a database class
>         >         > > to perform the repetitive tasks so that you really only 
> have to be concerned
>         >         > > with the queries you're writing...?
>         >         > >
>         >         > > <?php
>         >         > > class database {
>         >         > >    public function query ($sql) {
>         >         > >        $result = mysql_query ($sql);
>         >         > >        if ($result === false) {
>         >         > >            die ('Uh oh!');
>         >         > >        }
>         >         > >        return $result;
>         >         > >    }
>         >         > >
>         >         > >    public function numRows ($result) {
>         >         > >        return mysql_num_rows ($result);
>         >         > >    }
>         >         > > }
>         >         > > $db = new database();
>         >         > > $result = $db->query('SELECT * FROM afy_order');
>         >         > > $numRows = $db->numRows($result);
>         >         > > ?>
>         >         > >
>         >         > > Of course this is just a simple example, but you get 
> the idea. Hope that
>         >         > > stirs your brain!
>         >         > >
>         >         > > ~Philip
>         >         
>         >         
>         >         
>         >         My guess would be that you're submitting the form
>         >         using an image button, which would send the x and y
>         >         coordinates of the click within the button.
>         >         
>         >         Thanks,
>         >         Ash
>         >         http://www.ashleysheridan.co.uk
>         >         
>         >         
>         >         
>         >         
>         > 
>         > 
>         
>         
>         
>         
>         The only time they'll cause a problem is if you use some sort
>         of loop to translate all the form inputs into something that
>         is used in your code. For example, if you looped through all
>         the form inputs to create your filter, regardless of what the
>         inputs were called, then you would be running into all sorts
>         of problems.
>         
>         This is not something you should try and 'fix' on the
>         client-side but the server side, as everything that comes from
>         the client is not to be trusted, ever!
>         
>         Saying that though, I have seen some systems (HSBC payment
>         system) reject inputs containing x and y coordinates from
>         image buttons and cause the whole form to fail. In your case
>         that won't happen, but it's something to keep in mind in the
>         future maybe?
>         
>         If you want to change the button, you could use a regular
>         submit button and style it up with css:
>         
>         #submit_button_id
>         {
>             border: 0px none;
>             background-image: url('button.png');
>             background-repeat: no-repeat;
>             width: 100px;
>             height: 25px;
>         
>         
>         }
>         
>         Thanks,
>         Ash
>         http://www.ashleysheridan.co.uk
>         
>         
>         
> 
> 


Not really, what if someone else decided they wanted to throw in their
own form field values in the hope of breaking your system? It's much
better to be specifically looking for certain form fields and certain
field values/ranges. For example, if you had some fields that would
filter something by cost, you might have two form fields named 'max' and
'min' which would be ranges for the cost. You should check that these
fields only contain numbers for example before processing them. Any data
coming from the client-side is untrustworthy and should be regarded as
tainted until you can prove otherwise.

Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
There are a couple of ways that you can do this:

1. Store the post values in the $_SESSION variable then echo them back to the 
screen. Be careful with this as it can lead to XSS. Strip html, etc
2. Send the post values back to the form as part of the query sting. This 
solution is limited to the size of the query string (2k). Be careful with XSS


Another solution is to use a framework to handle the post back values. One such 
framework is called Raxan. Here's an example of what it can do: 

http://raxanpdi.com/form-state-example.html

__
Raymond Irving


________________________________
From: Merlin Morgenstern <merli...@fastmail.fm>
To: php-gene...@lists.php.net
Sent: Tue, November 24, 2009 12:14:01 PM
Subject: [PHP] processing html forms and keeping the values

Hi there,

I am trying to redirect a user back to a html form if a validation failes. The 
form shoult then hold all entered values. So far I did this over $_GET, but 
there is a 100 Character limitation. How could I do this while keeping all 
characters?

Thank you for any hint,

Merlin

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

--- End Message ---
--- Begin Message ---
Hello Raymond,

thank you for your hint. I will go with sessions. Thanx for the note regarding XSS.

Kind regards, merlin

Raymond Irving wrote:
There are a couple of ways that you can do this:

1. Store the post values in the $_SESSION variable then echo them back to the screen. Be careful with this as it can lead to XSS. Strip html, etc 2. Send the post values back to the form as part of the query sting. This solution is limited to the size of the query string (2k). Be careful with XSS

Another solution is to use a framework to handle the post back values. One such framework is called Raxan. Here's an example of what it can do:

http://raxanpdi.com/form-state-example.html

__
Raymond Irving
------------------------------------------------------------------------
*From:* Merlin Morgenstern <merli...@fastmail.fm>
*To:* php-gene...@lists.php.net
*Sent:* Tue, November 24, 2009 12:14:01 PM
*Subject:* [PHP] processing html forms and keeping the values

Hi there,

I am trying to redirect a user back to a html form if a validation failes. The form shoult then hold all entered values. So far I did this over $_GET, but there is a 100 Character limitation. How could I do this while keeping all characters?

Thank you for any hint,

Merlin

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


--- End Message ---
--- Begin Message ---
Merlin Morgenstern wrote on 2009-11-24 18:38:

This is not so easy. I am doing some checking with php on the values and if one failes php returns via GET to the form with the help of header location:

       $parameter =  "&demo=this";
       HEADER("Location:/test.html?error=1".$parameter);
       exit;

I would need to change way to many things in order to simply change to post.

Isn't there another way?

This is what I normally do with larger forms:

1. create the form as a function: form()
2. submit the form to the same page
3. test relevant input and if the fail print form()

Example:

function form() {
print '
<form action="'.$_SERVER['PHP_SELF'].'" method="post">
<input type="text" name="email" value="'.$_POST['email'].'">
<input type="submit" name="submit" value="send form">
</form>';
}

if($_POST['submit']) {
  // test email is entered
  if(!$_POST['email']) {
    print "error: you must enter an e-mail address";
    form();
  }
  else {
    // do stuff from here...
  }
}
else
  form();

With a 50 field form this is a nice approach for me :-)

--
Kind regards
Kim Emax - masterminds.dk

--- End Message ---
--- Begin Message ---
check these options
*-pass arg, -passin arg*

the PKCS#12 file (i.e. input file) password source. For more information
about the format of *arg* see the *PASS PHRASE ARGUMENTS* section in *
openssl*(1) <http://www.openssl.org/docs/apps/openssl.html#>.
*-passout arg*

pass phrase source to encrypt any outputed private keys with. For more
information about the format of *arg* see the *PASS PHRASE ARGUMENTS*section in
*openssl*(1) <http://www.openssl.org/docs/apps/openssl.html#>.
I believe you can ask user their password on previous page and utilize the
'pass' option and it won't ask for a password again

HTH


On Wed, Nov 25, 2009 at 2:53 AM, Tanveer Chowdhury <
tanveer.chowdh...@gmail.com> wrote:

> Hi all,
>
> I have an apache server and for that I created CA as the signing authority
> using openssl.
>
> Now I created a  php page which will generate client certificates with key
> and will sign by CA. Now the output is in .pem .
> Now how to convert it in .p12 for exporting it in client browser..
>
> Again, If using exec gives another problem which is it asks for export
> password so how to give this via php.
>
> Thanks in advance.
> Below is the code:
>
>  <?
> Header("Content-Type: text/plain");
> $CA_CERT = "/usr/local/openssl/misc/demoCA/cacert.pem";
> $CA_KEY  = "/usr/local/openssl/misc/demoCA/private/cakey.pem";
> $req_key = openssl_pkey_new();
> if(openssl_pkey_export ($req_key, $out_key)) {
>        $dn = array(
>                "countryName"            => "AU",
>                "stateOrProvinceName"    => "AR",
>                "organizationName"       => "Widget Ltd",
>                "organizationalUnitName" => "Test",
>                "commonName"             => "John Smith"
>                );
>        $req_csr  = openssl_csr_new ($dn, $req_key);
>        $req_cert = openssl_csr_sign($req_csr, "file://$CA_CERT",
> "file://$CA_KEY", 365);
>        if(openssl_x509_export ($req_cert, $out_cert)) {
>                echo "$out_key\n";
>                echo "$out_cert\n";
>                $myFile2 = "/tmp/testFile.pem";
>               // $myFile1 = "/tmp/testKey.pem";
>
> $fh2 = fopen($myFile2, 'w') or die("can't open file");
> fwrite($fh2, $out_key);
> $fh1 = fopen($myFile2, 'a') or die("can't open file");
> fwrite($fh1, $out_cert);
> fclose($fh1);
> fclose($fh2);
>
> $command = `openssl pkcs12 -export test -in /tmp/testFile.pem -out
> client-cert.p12`;
> exec( $command );
>
>        }
> else    echo "Failed Cert\n";
>        }
> else
>        echo "FailedKey\n";
> ?>
>

--- End Message ---
--- Begin Message ---
After a long delay, I've finally got mail working. I had decided to
move on in the book that I'm working through (Head First PHP & MySQL)
but doubled back to address the mail issue again. This is how I
finally got it to work:

1. Switched to XAMPP for linux rather than using my existing versions
of mysql, php and apache.

2. Uninstalled Postfix and reinstalled Sendmail. Then I followed the
instructions here:

http://dbaron.org/linux/sendmail

I can't vouch that the method described at that link is completely
safe and secure, but it worked for me and was very easy. I've spent
many hours and days trying to get this to work so am very relieved.

My only complaint is that there is quite a long delay after submitting
report.html (from Ch. 1) while it says 'waiting for localhost...'. It
can take up to 20 seconds or so before sending and giving
confirmation.

Thanks for all your help.

On Mon, Oct 26, 2009 at 4:37 AM, Bob McConnell <r...@cbord.com> wrote:
> From: James Prentice
>
>> I have tried setting both $to and $email to be the same shaw address
>> since I assumed it should be recognized by the mail server, but it's
>> still getting bounced. So why is 'www-d...@homemade' being listed as
>> the sender? Any ideas?
>
> I strongly recommend you call the help desk at Shaw and ask them to
> explain what is happening. They should know what is going on with their
> servers. Everyone on this list appears to be guessing at the problem,
> which is not likely to help you.
>
> Bob McConnell
>

--- End Message ---
--- Begin Message ---
It looks like using XAMPP wasn't strictly necessary. I tried running
this example again using my previous versions of mysql and apache and
it worked fine. So the key is to configure Sendmail as described at
the URL I gave.

On Wed, Nov 25, 2009 at 10:58 AM, James Prentice <prentice....@gmail.com> wrote:
> After a long delay, I've finally got mail working. I had decided to
> move on in the book that I'm working through (Head First PHP & MySQL)
> but doubled back to address the mail issue again. This is how I
> finally got it to work:
>
> 1. Switched to XAMPP for linux rather than using my existing versions
> of mysql, php and apache.
>
> 2. Uninstalled Postfix and reinstalled Sendmail. Then I followed the
> instructions here:
>
> http://dbaron.org/linux/sendmail
>
> I can't vouch that the method described at that link is completely
> safe and secure, but it worked for me and was very easy. I've spent
> many hours and days trying to get this to work so am very relieved.
>
> My only complaint is that there is quite a long delay after submitting
> report.html (from Ch. 1) while it says 'waiting for localhost...'. It
> can take up to 20 seconds or so before sending and giving
> confirmation.
>
> Thanks for all your help.
>
> On Mon, Oct 26, 2009 at 4:37 AM, Bob McConnell <r...@cbord.com> wrote:
>> From: James Prentice
>>
>>> I have tried setting both $to and $email to be the same shaw address
>>> since I assumed it should be recognized by the mail server, but it's
>>> still getting bounced. So why is 'www-d...@homemade' being listed as
>>> the sender? Any ideas?
>>
>> I strongly recommend you call the help desk at Shaw and ask them to
>> explain what is happening. They should know what is going on with their
>> servers. Everyone on this list appears to be guessing at the problem,
>> which is not likely to help you.
>>
>> Bob McConnell
>>
>

--- End Message ---
--- Begin Message ---
Hi,

I have been trying for the last couple of hours to determine the
encoding of a text file (.txt in windowz).

I have this code:

        $contents = file_get_contents($config['txt_dir'] . $file);
        $encoding = mb_detect_encoding($contents,
"UTF-8,ISO-8859-1,WINDOWS-1252"); //,Windows-1255

        echo "||encoding:".$encoding."||";

        if ($encoding == 'UTF-8')
        {
            $utfcontents = $contents;
        }
        else if ($encoding == 'ISO-8859-1')
        {
            $utfcontents = utf8_encode($contents);
        }

        var_dump($utfcontents);

The $encoding is ISO-8859-1, the text file contains Hebrew characters, then
I'm converting it to utf8.

The above code is outputing gibbrish, it seems that it has converted it in
some way but not in the
proper way that it should have converted it.

My page is UTF-8 encoded, without BOM, I send UTF-8 headers to the browser
and HTML content
encoding meta tag as well.

I have no idea what I am doing wrong.

I would highly appreciate it if someone could point me to the right
direction.

Thanks in Advance,

Nitsan

--- End Message ---

Reply via email to