Re: [PHP] curl and variable parameters in hyperlink

2010-11-24 Thread Adam Richardson
>
> 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


Re: [PHP] curl and variable parameters in hyperlink

2010-11-24 Thread Daniel Molina Wegener
On Wednesday 24 November 2010,
"Bob Keightley"  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.xx.com/query.asp?param1=val1¶m2=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:

 '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:



  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 
System Programmer & Web Developer
Phone: +56 (2) 979-0277 | Blog: http://coder.cl/


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


[PHP] Suppressing error from displaying

2010-11-24 Thread Ron Piggott

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

Re: [PHP] Suppressing error from displaying

2010-11-24 Thread Thiago H. Pojda
On Wed, Nov 24, 2010 at 5:13 PM, Ron Piggott  wrote:

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

Just add @ before checkdnsrr:

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


But you shouldn't use @ as it will make a PITA to find errors in your code
when maintaining it. You should not display Warnings on production too, at
least not for users but instead log those.


Cheers,
Thiago Pojda


Re: [PHP] Suppressing error from displaying

2010-11-24 Thread Daniel P. Brown
On Wed, Nov 24, 2010 at 14:13, Ron Piggott
 wrote:
>
> 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?

Sure.

if (@checkdnsrr($mailDomain,'MX'))

-- 

Dedicated Servers, Cloud and Cloud Hybrid Solutions, VPS, Hosting
(866-) 725-4321
http://www.parasane.net/

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



Re: [PHP] Suppressing error from displaying

2010-11-24 Thread Bastien Koert
On Wed, Nov 24, 2010 at 2:13 PM, Ron Piggott
 wrote:
>
> 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

if ( @checkdnsrr($mailDomain, "MX") ) {

might work.. the @ symbol usually suppresses the error

-- 

Bastien

Cat, the other other white meat

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



Re: [PHP] curl and variable parameters in hyperlink

2010-11-24 Thread Bob Keightley
Guess I've not explained this very well.

The external page I am fetching using another curl script has asp query 
hyperlinks in it. I do not know the variable names in each query or the 
values they have.

All I want to do is replace the external url referenced in those links with 
a url which is on my site (so that I can change style sheet, image locations 
etc.) but the parameters to the original asp query link have to be captured 
and passed to my php script for it to return data.  I know there must be a 
way of doing this as there's a site which is referencing the same third 
party site and doing the same thing, and no, they won't tell me how! 



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



RE: [PHP] Can't find existing file

2010-11-24 Thread Tommy Pham
> -Original Message-
> From: paras...@gmail.com [mailto:paras...@gmail.com] On Behalf Of
> Daniel P. Brown
> Sent: Monday, November 22, 2010 12:08 PM
> To: Dee Ayy
> Cc: PHP General
> Subject: Re: [PHP] Can't find existing file
> 

> so how are we to know?); (h) some other PEBKAC issue;


It's been almost a decade since I've seen 'PEBKAC' used  :)

Regards,
Tommy


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



RE: [PHP] curl and variable parameters in hyperlink

2010-11-24 Thread Tommy Pham
> -Original Message-
> From: Bob Keightley [mailto:bob.keight...@virgin.net]
> Sent: Wednesday, November 24, 2010 11:25 AM
> To: php-general@lists.php.net
> Subject: Re: [PHP] curl and variable parameters in hyperlink
> 
> Guess I've not explained this very well.
> 
> The external page I am fetching using another curl script has asp query
> hyperlinks in it. I do not know the variable names in each query or the
> values they have.
> 
> All I want to do is replace the external url referenced in those links
with a
> url which is on my site (so that I can change style sheet, image locations
> etc.) but the parameters to the original asp query link have to be
captured
> and passed to my php script for it to return data.  I know there must be a
> way of doing this as there's a site which is referencing the same third
party
> site and doing the same thing, and no, they won't tell me how!
> 

Bob,

There's several issues with this.

1) They're providing the info which you're trying to pass it as your own and
most likely that they won't get any positive results, as some company do
analysis on visits to improve the marketing strategy, customer service,
customer relations, etc.  You're just skewing their data analysis and
prevent them from becoming successful.  Which may force them to go out of
business then you'll lose your source of information.
2) Waste of bandwidth.  3rd party > you > user instead of just you > user.
3) I'm don't like that fact that some people take others work and try to
pass it as their own.  I think many folks on this list feels the same way.
So why not just quote them and give them the credit they deserve.  That's
probably the reason why you're not able to find much info on how to do this
:)

Regards,
Tommy


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



RE: [PHP] curl and variable parameters in hyperlink

2010-11-24 Thread Bob Keightley

 Thanks to all for your interest so far but as I said, new to PHP. Changed
POST to GET and all now working fine!

 Tommy, the third party site is fully aware of what I am doing. We pay them
to use the data, as do lots of other companies in our industry. Supplying
data is what they do. We could not use the site at all without being given a
valid user name. Far from 'preventing them being successful' the more users
they have the more successful they become. We do not 'pass the work as our
own' they are credited on our site as suppliers of the content, so there
really is no issue there.


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