Jump to content

Need to pass a list of captured data to external source via URL String


n1concepts

Recommended Posts

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

Link to comment
Share on other sites

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.... )

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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);

?>

Link to comment
Share on other sites

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

    }  
?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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);
}

?>

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.