mad_pierrot 0 Newbie Poster

Hello everyone,

I'm trying to create a PHP cURL script that does two main things.

1) Login to website (works)
2) Export table as CSV (doesn't work)

To export the table as a CSV, two things need to be selected. Which table I want to export, in this case customers, and the file type, CSV. Then it needs to be submitted.

The main problem is that when I run the script I get a message saying, "No special characters allowed."

Here's the result from live HTTP headers.

http://1abcd.2adffa.example.com/admin/db_export.asp

POST /admin/export.asp HTTP/1.1
Host: 1abcd.2adffa.example.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
Referer: 1abcd.2adffa.example.com/admin/db_export.asp?QueryBank=Y
Cookie: lastmsgnum=1; ASPSESSIONIDACTSSSCT=JEEAEKEBMDACOPMMMKNPBFFI; vsettings=; slt=893A3EDD-AFE6-4F71-A538-94852B31E400; CustomerID=9E41743071AFF4FEA97FD1034678F5F5D716212CCFAB83604DB3AD783BE10284; Session%5FToken=C7A68336D3374BD392DA1A6636C7577A; ASP.NET_SessionId=ttuf3u55hdiciaatbxgtz13y
Content-Type: application/x-www-form-urlencoded
Content-Length: 97
NOSAVE___Form_Submission_Token=E1EA967B526A470A9EB5AEF31F2C59BD&QB_ID=25&QueryBank=Y&FileType=CSV
HTTP/1.1 200 OK
Connection: Keep-Alive
Date: Thu, 03 Feb 2011 20:26:11 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
Content-Type: text/html
Cache-Control: private
Vary: Accept-Encoding, User-Agent
Content-Encoding: gzip
Content-Length: 11363

Here is the PHP Code that is supposed to submit the form.

<?php
$target = "http://1abcd.2adffa.example.com/admin/db_export.asp";
$useragent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1";
$ref = "http://1abcd.2adffa.example.com/admin/db_export.asp";
$form_string = "NOSAVE___Form_Submission_Token=E1EA967B526A470A9EB5AEF31F2C59BD&QB_ID=25&QueryBank=Y&FileType=CSV";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $target); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_REFERER, $ref);
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies.txt"); 
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies.txt"); 
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, urlencode($form_string));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); 
$page = curl_exec($ch);
echo $page;
curl_close($ch);
?>

I've tried it with and without urlencode, rawurlencode, but no luck.
If there's is any other info you need me to post let me know.
Thanks