0

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

12
  • Well, you'd better open two tab to do this. Commented Oct 12, 2015 at 12:54
  • @ôkio I don't want to two tab, It need to create two pdf Commented Oct 12, 2015 at 12:57
  • 1 tab = 1 url. You can create 2 PDF, but only one will be shown Commented Oct 12, 2015 at 12:58
  • @ôkio You can give me an example with a code, I don't understand what you say with tab Commented Oct 12, 2015 at 13:01
  • Redirect to the the second file in the first file, after the code execution is finished .. Commented Oct 12, 2015 at 13:04

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.