n1concepts Posted May 4, 2011 Share Posted May 4, 2011 I need to pass captured data, basically, a list of email addresses that are being read from a CSV file and (1st) saved to an local database, then sent over to an external source via URL string. I have everything working except - script opens the file, read and validates all emails in the specified column, and saves to local db. ISSUE: after validating then INSERTING the data into local mySQL db, I need to then pass each piece of data to an external source via URL string. Example: www.domain.com?email={$new_email} I was initially think to just add the URL in a header function but, I'm not sure if the HEADER() function the right method to pass all of the data - during the loop - via the URL string. For example, if the CSV file contain 500 emails: Q: how can I continue that loop until the last email read, passing each up to the external source via the URL string? I'm not sure if using the HEADER() function at the end of the script - but within the loop - will interate and send each capture email via that URL string. Can anyone advise a possible solution to this? Thx Quote Link to comment https://forums.phpfreaks.com/topic/235558-need-to-pass-a-list-of-captured-data-to-external-source-via-url-string/ Share on other sites More sharing options...
efficacious Posted May 5, 2011 Share Posted May 5, 2011 i could be wrong but I believe you can still send variables using the POST method to external sources.. <form action='www.domain.com\somePage.php' method='POST' > <input hidden name='var1' value='someValue' /> ect... Quote Link to comment https://forums.phpfreaks.com/topic/235558-need-to-pass-a-list-of-captured-data-to-external-source-via-url-string/#findComment-1210653 Share on other sites More sharing options...
n1concepts Posted May 5, 2011 Author Share Posted May 5, 2011 I meant to say, "I have everything working - script opens the file, read and validates all emails in the specified column, and saves to local db." Note: I just need some guidance on coding the the function to pass each piece of data into the provided URL string to be forward to that external source. I'm concerned the header() function will only send the 1st email and the script stops being that's a redirect. I haven't coded it yet but was wondering if anyone had an answer to this to save me from the migraine coming.... ) Quote Link to comment https://forums.phpfreaks.com/topic/235558-need-to-pass-a-list-of-captured-data-to-external-source-via-url-string/#findComment-1210655 Share on other sites More sharing options...
efficacious Posted May 5, 2011 Share Posted May 5, 2011 well you can't just do somepage.php?var=thisVar,thatVar,etcVar so you'll either have to give a unique name for each value or concatenate the string and break it down on the other end. thats why i suggested the POST method instead of GET so you don't have to use the URL in the first place. Plus you can pass much more data with POST while GET method its limited characters. Quote Link to comment https://forums.phpfreaks.com/topic/235558-need-to-pass-a-list-of-captured-data-to-external-source-via-url-string/#findComment-1210658 Share on other sites More sharing options...
smsmarketeers Posted May 5, 2011 Share Posted May 5, 2011 You should really be using cURL to do this. I am not going to write you a full example unless you really need it because you seem to have most of the functionality done that you are looking for so here is a snippet using cURL to accomplish what you are wanting to do. Since you could careless if there is any data being returned, you just want to submit it and get it over with. <?php $ch = curl_init('YOUR_URL_GOES_HERE'); curl_setopt($ch, CURLOPT_VERBOSE, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_POST, FALSE); curl_exec($ch); ?> Quote Link to comment https://forums.phpfreaks.com/topic/235558-need-to-pass-a-list-of-captured-data-to-external-source-via-url-string/#findComment-1210660 Share on other sites More sharing options...
n1concepts Posted May 5, 2011 Author Share Posted May 5, 2011 Thanks for the reply but it's bit more complex and I'm not needing a form b/c the data is being receiving (to us) via FTP. Note: I have a script that takes those CSV files, move them to a different folder and process them (opening and reading the columns, then saving the data in local db, and final - sending that data to external source). The external vendor provided the URL string (it's a requirement that I can not change) so I need to figure out how to get all captured data to that external source via their provided URL string. Example: <?php if ($checkDup == 1){ if ($new_email == $db_email) { $submit = "INSERT INTO leads (email,date,ipaddress,logdate,filename,affiliate,source,status) VALUES ('$new_email','$cedatetime','$ip',now(),'$cefile','$affiliate','$source','$dupNgm');"; $result = mysql_query($submit) or die("<br>Query string: $submit<br>Returned error: " . mysql_error() ); } // submit lead up to external source via URL string header("Location: http://domain.com?email=$new_email"); // THIS IS THE LINE OF CODE I"M QUESTIONING (WILL THIS CONTINUE TO LOOP AND PASS EACH EMAIL IN THE REDIRECT } ?> Quote Link to comment https://forums.phpfreaks.com/topic/235558-need-to-pass-a-list-of-captured-data-to-external-source-via-url-string/#findComment-1210661 Share on other sites More sharing options...
efficacious Posted May 5, 2011 Share Posted May 5, 2011 well then you need to contact them and ask them of the format they expect the data don't you think? the first part about you receiving the data is irrelevant to this issue.. the issue is that you need to send the data to someone else. We have already established that you have it. I can't imagine that they only take one email at a time... Quote Link to comment https://forums.phpfreaks.com/topic/235558-need-to-pass-a-list-of-captured-data-to-external-source-via-url-string/#findComment-1210663 Share on other sites More sharing options...
n1concepts Posted May 5, 2011 Author Share Posted May 5, 2011 BTW: I have the WHILE and that code is within the loop <including the redirect string>) Example: while ($file_name = readdir($dir)) { if (($file_name != ".") && ($file_name != "..")) { // BLAH BLAH // Then the example code from previous post. } Again, I'm trying to figure out how to get EACH email that is captured during the WHILE loop sent via the URL string to external source. Note: there is no form - it's all backend operation via PHP. I simply need to keep the script going - passing each 'email' variable via that URL String to the external destination. Quote Link to comment https://forums.phpfreaks.com/topic/235558-need-to-pass-a-list-of-captured-data-to-external-source-via-url-string/#findComment-1210667 Share on other sites More sharing options...
n1concepts Posted May 5, 2011 Author Share Posted May 5, 2011 smsmarketeers, I see what you are saying. I got to wrap my head around cURL but this sounds like what I need... Just got to figure out the code now.... \ Appreciate it! I'll respond back soon as I have it working - will be abit Quote Link to comment https://forums.phpfreaks.com/topic/235558-need-to-pass-a-list-of-captured-data-to-external-source-via-url-string/#findComment-1210668 Share on other sites More sharing options...
smsmarketeers Posted May 5, 2011 Share Posted May 5, 2011 I gave you a valid way of making this happen. I am not sure if you were referring to me about "not needing a form" but if you were, I did not mention a form at all. cURL is your answer and here is your example: What you provided: <?php if ($checkDup == 1){ if ($new_email == $db_email) { $submit = "INSERT INTO leads (email,date,ipaddress,logdate,filename,affiliate,source,status) VALUES ('$new_email','$cedatetime','$ip',now(),'$cefile','$affiliate','$source','$dupNgm');"; $result = mysql_query($submit) or die("<br>Query string: $submit<br>Returned error: " . mysql_error() ); } // submit lead up to external source via URL string header("Location: http://domain.com?email=$new_email"); // THIS IS THE LINE OF CODE I"M QUESTIONING (WILL THIS CONTINUE TO LOOP AND PASS EACH EMAIL IN THE REDIRECT } ?> Here is what I am suggesting: <?php if ($checkDup == 1){ if ($new_email == $db_email) { $result = mysql_query("INSERT INTO leads SET email = '" . $new_email . "', date = '" . $cedatetime . "', ipaddress = '" . $ip . "', logdate = NOW(), filename = '" . $cefile . "', affiliate = '" . $affiliate . "', source = '" . $source . "', status = '" . $dupNgm . "'") or die("<br />Error: " . mysql_error()); } $ch = curl_init("http://domain.com?email=" . $new_email); curl_setopt($ch, CURLOPT_VERBOSE, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_POST, FALSE); curl_exec($ch); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/235558-need-to-pass-a-list-of-captured-data-to-external-source-via-url-string/#findComment-1210669 Share on other sites More sharing options...
n1concepts Posted May 5, 2011 Author Share Posted May 5, 2011 Hi smsmarketeers, No, I was responding to efficacious to which I appreciate comments as well as yours. FYI: your suggestions and code snippets worked - just as you said it would! cURL was the answer to the problem (works perfectly!) Appreciate the support! later! Quote Link to comment https://forums.phpfreaks.com/topic/235558-need-to-pass-a-list-of-captured-data-to-external-source-via-url-string/#findComment-1210809 Share on other sites More sharing options...
smsmarketeers Posted May 5, 2011 Share Posted May 5, 2011 No problem! I have known about phpFreaks for awhile and occasionally used the tutorials (years ago) when I was learning (I am still learning every day, but really advanced stuff now) so I know what it feels like to need help. You are one of the first persons I have helped! Glad it worked. Quote Link to comment https://forums.phpfreaks.com/topic/235558-need-to-pass-a-list-of-captured-data-to-external-source-via-url-string/#findComment-1210928 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.