Reputation: 11
I need to go to two different url in same time for create two pdf file .
Currently with my code, only the last redirection work , I want to redirect user to two url , how can I do this ?
// I need to create 2 different pdf , (pdf is created when we go to create_Pdf.php)
for($i=0;$i<2;$i++)
{
header('Location: ../../Create_PDF.php?idcode='.$code.'&inputdate='.$datein.'&outputdate='.$dateoutfr.'&username='.$usernameOut);
header('Location: ../../Create_PDF.php?idcode='.$code'&inputdate='.$datenominate.'&outputdate=31/12/2015&username='.$usernameIn);
}
**** The pdf will be not output, only 2 pdf file will be create in a repository ***
Upvotes: 0
Views: 441
Reputation: 8482
You could use cURL for this: http://php.net/manual/en/book.curl.php
Essentially cURL allows you to contact URLs "behind the scenes" (rather than using an HTTP Redirect) - but there are several settings that will depend on your setup... and there are a lot of cURL settings: http://php.net/manual/en/curl.constants.php
However, in essence here you'll want a function which just contacts the given URL - maybe throws an Exception if the URL can't be reached.
function curlCreatePDF($sURL) {
//open the cURL session
$hCurl = curl_init();
//set the cURL options
curl_setopt($hCurl, CURLOPT_URL, $sURL); //URL
curl_setopt($hCurl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); //HTTP version
curl_setopt($hCurl, CURLOPT_HEADER, 0); //no HTTP headers
curl_setopt($hCurl, CURLOPT_RETURNTRANSFER, 1); //return raw data to script rather than browser
curl_setopt($hCurl, CURLOPT_TIMEOUT, 60); //set timeout
//execute
curl_exec($hCurl); //this will actually return the response
//throw an Exception if cURL failed
if($e = curl_error($hCurl)) {
throw new Execption($e, E_USER_ERROR);
}
//close the cURL handle
curl_close($hCurl);
}
// I need to create 2 different pdf , (pdf is created when we go to create_Pdf.php)
try {
for($i=0;$i<2;$i++) {
curlCreatePDF("http://www.yoursite.com/path/to/Create_PDF.php?idcode={$code}&inputdate={$datein}&outputdate={$dateoutfr}&username={$usernameOut}");
curlCreatePDF("http://www.yoursite.com/path/to/Create_PDF.php?idcode={$code}&inputdate={$datenominate}&outputdate=31/12/2015&username={$usernameIn}");
}
}
catch(Exception $e) {
die($e->getMessage());
}
This may not work "as is", especially over SSL (as you'll need to set the CURLOPT_SSL_VERIFYPEER
and CURLOPT_SSL_VERIFYHOST
options)...
It would make more sense though to just put your create PDF stuff into a class and then just call it in your loop rather than calling an external file over HTTP.
Upvotes: 1