We help IT Professionals succeed at work.

i post a html page like aspx from php page automatic and capture in a string variable the result of the post.

markosp
markosp asked
on
Hello
How can i post a html page like aspx from php page automatic and capture in a string variable the result of the post.
I want this page called from php with script php commands or javascript commands
I use file and it work on my local server but not in live server
Regads
Psarrakis markos  
Comment
Watch Question

Andyc75Software Architect
Top Expert 2010

Commented:
Here is an example of a simple html form that posts a single value.

When you click on submit it posts the value.  The page then captures $_POST[] value and displays its contents.

Let me know if you need it to do anything else.


<?php
if(isset($_POST['first_name'])){
 //Value was posted Display its values
  echo 'You Posted This value for First Name: ' . $_POST['first_name'];
}else{
 //Display the Form
?>
<html>
<head>
</head>
<body>
<form name="myform" method="post" action="">
First Name: <input type="text" name="first_name" ></input>
<input type="submit" value="submit" />
</form>
</body>
</html>
<?php
}
?>

Open in new window

Author

Commented:
I want reads entire url file into an array
Andyc75Software Architect
Top Expert 2010

Commented:
Sorry, I don't understand what you mean.

Can you explain your requirements a bit more.

Do you want to put the form values into an array  after you post it ?  If so do you have an example of your form.

Thanks.

Author

Commented:
Hello
i have the above php script that running in my local (xampp) server but it isn`t running in my live server apache - cpanel

regards
Markos Psarrakis
Sorry for bad English
<?php

/**
 * @author Markos Psarrakis
 * @copyright 2010
 */
$V_data="http://www.anytimeonline.gr/WebServiceConnectors/PolicyIssueNewCustAnytimeInternet_doCreateProposal.ashx?PaymentType=1&duration=6&vehicleUseCode=000&extraPremium=false&ExtraDiscount=0&vehicleDriverAgeLimit=0
&AutoType=car&damagesCountCustomerDeclaration=0&vehicleCapital=12000&addressPostalCode=49100&vehicleCubicCm=2000&vehicleManufactureDate=01/05/2009";
$lines = file($V_data);
foreach ($lines as $line_num => $line) {
    $Vstr=$line ;
}
$d1 = preg_replace("/<\w*?>/", "", $Vstr);
$d2 = preg_replace("/<\/\w*?>/", ";", $d1);

$list = split(";", $d2);


foreach ($list as $item)
{

   echo $item."<BR />";

}


?>
Andyc75Software Architect
Top Expert 2010

Commented:
No problem Markos

I tried running your code on my server.
One thing i had to change was to use the explode() function instead of split().  Split has been depreciated.

//Change split to explode
//$list = split(";", $d2);
$list = explode(";",$d2);

This is my result, when I run your code:
188.59
231.43
341.21

the values are loaded into the $list array like this:
Array ( [0] => 188.59 [1] => 231.43 [2] => 341.21 [3] => )

Is this what you expected ?

Author

Commented:
Hello
is not work

i think the line :
$lines = file($V_data);
is not running in my server can you help me

Regards
Markos
Andyc75Software Architect
Top Expert 2010

Commented:
Check your php.ini file.

Look for this entry and make sure it is enabled:

allow_url_fopen

That determines if you are allowed to open files from a URL.

Author

Commented:
Hello
in above url is the server and there is phpinfo() script  the
allow_url_fopen is on.
https://www.be-smart.gr/test1.php
The http is secure (ssl) but the same script is not running in other server.
I think the output data are not write in a variable in the php script
Regards
Markos
Andyc75Software Architect
Top Expert 2010

Commented:
you can try changing your code to use file_get_contents(); instead of file()

See if this works for you


<?php

/**
 * @author Markos Psarrakis
 * @copyright 2010
 */
$lines[] = file_get_contents("http://www.anytimeonline.gr/WebServiceConnectors/PolicyIssueNewCustAnytimeInternet_doCreateProposal.ashx?PaymentType=1&duration=6&vehicleUseCode=000&extraPremium=false&ExtraDiscount=0&vehicleDriverAgeLimit=0
&AutoType=car&damagesCountCustomerDeclaration=0&vehicleCapital=12000&addressPostalCode=49100&vehicleCubicCm=2000&vehicleManufactureDate=01/05/2009");

foreach ($lines as $line_num => $line) {
    $Vstr=$line ;
}
$d1 = preg_replace("/<\w*?>/", "", $Vstr);
$d2 = preg_replace("/<\/\w*?>/", ";", $d1);

$list = explode(";", $d2);

foreach ($list as $item){
   echo $item."<BR />";

}

?>

Open in new window

Author

Commented:
Hello
Is not working
I use the script
file_get_contents($V_data);
var_dump($http_response_header);
and does not work i can not receive any data !!!!

Regards
markos
 
Andyc75Software Architect
Top Expert 2010

Commented:
O,k lets see if is a problem with the server you are connecting to.

Try this simple test.

<?php
$data = file_get_contents("http://www.google.com");
echo $data;
?>

Does this work for you ?

Author

Commented:
Hello
I receive the above message :
302 Moved
The document has moved here.

Regards
Psarrakis markow
Andyc75Software Architect
Top Expert 2010

Commented:
Your having some basic connectivity Issues with your server connect to URL's.

The only other thing I can suggest is to try and use CURL to get the contents of your file.

this is an example of how to use CURL to get file contents:

<?php
$ch = curl_init();
$timeout = 5; // set to zero for no timeout
curl_setopt ($ch, CURLOPT_URL, 'http://example.com');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);

// display file
echo $file_contents;
?>

I would suggest contacting your hosting provider and try to resolve the Issue with them.
Commented:
I post new question server oriented