php-general Digest 24 Nov 2010 19:13:53 -0000 Issue 7052

Topics (messages 309646 through 309650):

Re: curl and variable parameters in hyperlink
        309646 by: Bob Keightley
        309647 by: Adam Richardson
        309649 by: Daniel Molina Wegener

Re: is this thing on??
        309648 by: Gary

Suppressing error from displaying
        309650 by: Ron Piggott

Administrivia:

To subscribe to the digest, e-mail:
        [email protected]

To unsubscribe from the digest, e-mail:
        [email protected]

To post to the list, e-mail:
        [email protected]


----------------------------------------------------------------------
--- Begin Message ---
I already have a curl script that gets the web page, but it doesn't pass the
parameters

Being new to PHP I haven't the first idea how to modify it so that it does.

Script is as follows:

$url = "http://www.xxxxxx.com/query.asp?param1=val1&param2=val2";;

foreach ($_POST as $key=>$post) {
        $post=str_replace(" ", "+", $post);
        $url.=$key."=".$post."&";
        }

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
$data = curl_exec($ch);
curl_close($ch);

$data=str_replace('.asp', '.php', $data);
echo $data;

This returns the web page, but ignores val1 and val2 which are necessary to
execute the query.



--- End Message ---
--- Begin Message ---
>
> foreach ($_POST as $key=>$post) {
>        $post=str_replace(" ", "+", $post);
>        $url.=$key."=".$post."&";
>        }
>

Hi Bob,

One thing I see is that you're appending values on to the end of a url that
already has 2 values, so you should place the "&" at the beginning of your
line instead of at the end.  Value 2 is being merged with whatever value is
coming after it in your example.  So, try something like:

$url .= "&" . $key. "=" .$post;

Also, I'd suggest url encoding the post value rather than merely hunting
down spaces and swapping them out with "+".

Hope this helps,

Adam

-- 
Nephtali:  PHP web framework that functions beautifully
http://nephtaliproject.com

--- End Message ---
--- Begin Message ---
On Wednesday 24 November 2010,
"Bob Keightley" <[email protected]> wrote:

> I already have a curl script that gets the web page, but it doesn't pass
> the parameters

  Hello Bob,

> 
> Being new to PHP I haven't the first idea how to modify it so that it
> does.
> 
> Script is as follows:
> 
> $url = "http://www.xxxxxx.com/query.asp?param1=val1&param2=val2";;
> 
> foreach ($_POST as $key=>$post) {
>       $post=str_replace(" ", "+", $post);
>       $url.=$key."=".$post."&";
>       }


  Instead of concatenating strings, I suggest to use the http_build_query()
function:

<?php
$data = array('param1' => 'val1',
              'param2' => 'val2',
              'param3' => 'val3');
$query = http_build_query($data);
echo "Query: {$query}\n";
 ?>

  So, to create a query string based on your $_POST request parameters,
you just need to use the function as follows:

<?php
$query = http_build_query($_POST);
echo "Query: {$query}\n";
 ?>

  This will create the proper query string to be used on your URL.

> 
> $ch = curl_init($url);
> curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
> curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
> $data = curl_exec($ch);
> curl_close($ch);
> 
> $data=str_replace('.asp', '.php', $data);
> echo $data;
> 
> This returns the web page, but ignores val1 and val2 which are necessary
> to execute the query.


Best regards,
-- 
Daniel Molina Wegener <dmw [at] coder [dot] cl>
System Programmer & Web Developer
Phone: +56 (2) 979-0277 | Blog: http://coder.cl/

Attachment: signature.asc
Description: This is a digitally signed message part.


--- End Message ---
--- Begin Message ---
Steve Staples wrote:

> tap tap tap... testing testing... 1, 2, 3....

*pff* *pff*

We've got cheese rolls, ham rolls, casseroles, ars...

What's wrong with this f...ing mike, 'Arry?


--- End Message ---
--- Begin Message ---
I am using this syntax to check for a valid e-mail address

list($userName, $mailDomain) = split("@", $buyer_email);
if (checkdnsrr($mailDomain, "MX")) { 

if no domain is provided ( ie e-mail address is something like “ron” with no @ 
) the following error is displayed:

Warning: checkdnsrr() [function.checkdnsrr]: Host and type cannot be empty

Can I suppress this from displaying so *just* my error message displays?

Ron

The Verse of the Day
“Encouragement from God’s Word”
http://www.TheVerseOfTheDay.info

--- End Message ---

Reply via email to