Need help with php api

Hi I need to use PHP api service with my html form to submit urls to that service…
Please see

Here is my simple html forum …

<form name="myform" action="apitest.php" method="POST">
        	<label>Campain Name:</label><br /> 
    	<input type="text" name="CAMPAIGN_NAME_HERE"/><br />
        	<label>URLS List</label><br />
    	<textarea name="urls" rows="20" cols="60"></textarea><br />
        	<input type="submit" />

I need to submit this form with list of urls and submit urls to this API.
Best Regards

That page you link to has some sample code to show how it’s done, the only change I can see is that you will need to split the URLs in your textarea in order to place them into the URL to post. The sample code creates an array in hard code (the line that starts “$urls = array(” ) , where you will have to have something to process the contents of $_POST[‘urls’] from your form into the individual URLs - it might be simpler not to put them in an array, just build them directly into the query-string once you’ve validated them.

Can you show your PHP code for apitest.php and an idea of where it’s not working properly?

here is my apitest.php file code

<?php $apikey='my api key is here'; $campaign='CAMPAIGN_NAME_HERE'; // All Links to be sent are hold in an array for example $urls=array('urls'); // build the POST query string and join the URLs array with | (single pipe) $qstring='apikey='.$apikey.'&cmd=submit&campaign='.$campaign.'&urls='.urlencode(implode('|',$urls)); // Do the API Request using CURL functions $ch = curl_init(); curl_setopt($ch,CURLOPT_POST,1); curl_setopt($ch,CURLOPT_URL,''); curl_setopt($ch,CURLOPT_HEADER,0); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_TIMEOUT,40); curl_setopt($ch,CURLOPT_POSTFIELDS,$qstring); curl_exec($ch); curl_close($ch); ?>

OK, so you need to add some code now to process your form variables - split the contents of your textarea into individual URLs, probably by looking for the newline character to terminate each one, check they’re valid URLs, then add them into the $urls array. Start with something like

if (strlen($_POST['urls']) > 0) {
  $urls = explode("\n", $_POST['urls']);

You’ll need to check each URL to make sure it’s valid, and you’ll also need to strip out the last one as this may leave a blank one at the end of the array.

Looking at the query-string, though, that just seems to implode the array again, so you might just be able to do something like

$urls = str_replace("\n", "|", $_POST['urls']);

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.