I have a php curl script that will check if a site is supported by my site. All I need to do is to enter the url and upload it to the server. But now I want to make it into form. Like, entering a url and submit it will do the same job. This would be much hassle free as I don't have to reupload edited file over and over again. Can anyone tell me where I could find reference to do this? What I want to achieve: Enter url to check <form> <submit> ...process If not success: The domain <domain> is currently not supported. If success: Congratulation, <domain> is supported. Can anyone help me by telling me how can I do this? Existing code: <?php $timeout = 5; $desc = 'Site Compatibility Check'; $file_loc = 'testfile.pdf'; $url = 'http://www.merryone.com/'; $postcontent= array(); $postcontent['file_0']='@'.$file_loc; $postcontent['upload_type']='file'; $postcontent['file_0_descr']= $desc; $postcontent['file_0_public']= 1; $postcontent['tos']= 1; $upload_id=(96).time(); $ch = curl_init (); curl_setopt ($ch, CURLOPT_HTTPHEADER, array('Expect:')); curl_setopt ($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)'); curl_setopt ($ch, CURLOPT_REFERER, $url); curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt ($ch, CURLOPT_URL, $url); $result = curl_exec ($ch); preg_match('/enctype="multipart\/form-data"[^>]+action="(.*?)\/cgi-bin\/upload\.cgi/is',$result,$match); $posturl = $match[1]; curl_setopt ($ch, CURLOPT_URL, $posturl.'/cgi-bin/upload.cgi?upload_id='.$upload_id.'&js_on=1&utype=anon&upload_type=file'); curl_setopt ($ch, CURLOPT_POST, 1); curl_setopt ($ch, CURLOPT_POSTFIELDS, $postcontent); $result = curl_exec ($ch); preg_match('/name=\'fn\'>(.+?)</is',$result,$dll); if($dll[1]) { $postcontent='fn='.$dll[1].'&st=OK&op=upload_result'; curl_setopt ($ch, CURLOPT_URL,$url); curl_setopt ($ch, CURLOPT_POSTFIELDS, $postcontent); $result = curl_exec ($ch); preg_match('/<input[^>]+onFocus="copy\(this\);" value="(http:\/\/[^"]+)/is',$result,$dll); } curl_close ($ch); if($dll[1]) { echo $dll[1]; } else echo 'This site is not supported!'; ?> PHP:
Emm not sure if this is what you want ? do you have a sample url of a matching site ? $url = $_GET['url']; PHP: and add a form after ?> like this ?> <form> <input type="text" name="url"> <input type="submit"> </form> PHP:
Ah, $_GET. I used POST. No wonder any url came out not supported. Now I got it working. Thank you. Rep is coming your way
Great. Now the form is working. I'm reading a tutorial to adapt this form into AJAX. So far, there is no progress of how to make this work. The tutorial I read is from HERE. It's actually a contact form but I figure it could also be used for a simple form as well. Correct me if I'm wrong. Appreciate if anyone can teach me this too Thanks.