On Wednesday 24 November 2010, "Bob Keightley" <bob.keightley@xxxxxxxxxx> 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 = ""> > > 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 = "" => '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_close($ch); > > $data="" '.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.