Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP Curl - Validate and Fetch .csv file efficiently. How?
    primarykey
    data
    text
    <p>I'm very weak in curl functions. I have a script which does hourly routines to update files among networked sites. </p> <p>I have three concerns:</p> <ol> <li>Efficiency </li> <li>Accuracy </li> <li>Security</li> </ol> <p>Having tested it in some length, <strong>it will grab the 404's and save them as csv files</strong>, and then the validation afterward deletes them. But it would be better to reject a non-csv file flat out...even if its disguised as a .csv for malicious purposes. </p> <p>On that note, I will be saving them to a special folder. Is there any way to hide executable (malicious) code in them? I figured I would keep this directory non-executable to ensure safety.</p> <p>Here is the code: </p> <pre><code>//check file exists first: if ( !$fp = curl_init( $url ) ) return 'Symbiocard not found at this address ('.$url.'). Please upload manually.'; $ch = curl_init( $url ); curl_setopt( $ch, CURLOPT_NOBODY, 0 ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt( $ch, CURLOPT_BINARYTRANSFER, 1 ); $raw = curl_exec( $ch ); curl_close( $ch ); if ( file_exists( $newfile ) ) { unlink( $newfile ); } //file_exists( $newfile ) $fp = fopen( $newfile, 'x' ); fwrite( $fp, $raw ); fclose( $fp ); $required_fields = array( 'symbiostock_site', 'admin_email', 'symbiostock_version' ); </code></pre> <p>I didn't past my validation / file writing code simply because I'd like to filter it on the CURL level. </p> <p><strong>THE QUESTION: How do I limit curl to only communicate with a genuine csv file (not a 404 or any other document at the supposed .csv location).</strong></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload