Hej,
Mit php CURL script driller!! Jeg skal nemmelig have fat i SESSIONID hvilket mit script også gør.
I starten af mit dokument kalder jeg nemmelig en side for at skaffe sessionid.
Og jeg kalder så siden "igen" når jeg submitter min form.
Det er som om, at den ikke husker min session rigtig, fordi når jeg indtaster den korrekte captcha kode, siger den "Invalid code".
Kan nogen forklare mig, hvorfor min sessionid ikke dutter (Cookie, Set-Cookie), og har nogen en løsning til hvordan jeg får det til at virke?
Prøv evt. kør scriptet og se hvordan det fungere og så i får et indblik i hvad jeg mener.
Link til simple-source:
http://pastebin.com/CUAjX5NM eller raw source:
- <? session_start()?>
-
- <style type="text/css">.letshavefun{border:5px dotted #999;margin: 0 auto;text-align:center;color:#fff;width:500px;background-color:#333}*{padding:10px;font-family:Courier;}a,a:hover{color:#fff;text-decoration:none}a:hover{text-decoration:underline}.sb{padding:15px;background:orange;color:#000;font-weight:bold;font-size:16px}</style>
-
- <?
-
- //Basic information from the costumer
- $type = "normal";
- $myUrl = "http://google.co.in";
- $email = "webudvikleren@hotmail.com";
- $des = "Best website in the whole world mayn sdjfksdfksdjfsdfksdfj ksdjf skdjfsdjf";
- $name = "Nikolaj Hansen";
-
- //Site informations
- $url = "http://www.w4directory.com/submit.php";
-
-
- $_SESSION['ch'] = curl_init($url);
-
- if ( !isset($_POST['finger'])):
- curl_setopt($_SESSION['ch'], CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($_SESSION['ch'], CURLOPT_HEADER, 1);
-
- preg_match('/^Set-Cookie: (.*?);/m', curl_exec($_SESSION['ch']), $m);
-
- $pat = parse_url($m[1]); $pat=trim($pat['path']);
-
- curl_setopt($_SESSION['ch'], CURLOPT_URL, $url);
-
- curl_setopt($_SESSION['ch'], CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($_SESSION['ch'], CURLOPT_TIMEOUT, '10');
-
- $get = trim(curl_exec($_SESSION['ch']));
- endif;
-
-
-
- if ( isset ( $_POST['finger'] )):
- $fields = array(
- 'LINK_TYPE'=>$type,
- 'TITLE'=>urlencode($_POST['TITLE']),
- 'URL'=>urlencode($myUrl),
- 'DESCRIPTION'=>urlencode($des),
- 'OWNER_NAME'=>urlencode($name),
- 'OWNER_EMAIL'=>urlencode($email),
- 'CATEGORY_ID'=>urlencode($_POST['CATEGORY_ID']),
- 'RECPR_URL' => '',
- 'RECEPR_TEXT' => '',
- 'CAPTCHA' => $_POST['captcha'],
- 'submit' => 'Continue',
- 'AGREERULES' => 'on',
- 'IMAGEHASH' => urlencode($_POST['heey']),
- 'META_DESCRIPTION_limit' => 250,
- 'DESCRIPTION_limit' => (500-strlen($des)),
- 'is_valid' => 'true'
- );
-
- foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }rtrim($fields_string,'&');
-
- $h = array();
- session_write_close();
-
- //Send headers, correct Cookie.
- $h[] = 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8';
- $h[] = 'Connection: Keep-Alive';
- $h[] = 'Accept-Language: da,en-us;q=0.7,en;q=0.3';
- $h[] = 'Accept-Encoding: gzip, deflate';
- $h[] = 'Cookie: '.$pat;
-
- //set the url, number of POST vars, POST data
- curl_setopt($_SESSION['ch'],CURLOPT_URL,$url);
- curl_setopt($_SESSION['ch'],CURLOPT_POST,count($fields));
- curl_setopt($_SESSION['ch'],CURLOPT_POSTFIELDS,$fields_string);
- curl_setopt($_SESSION['ch'],CURLOPT_USERAGENT,'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:12.0) Gecko/20100101 Firefox/12.0');
- curl_setopt($_SESSION['ch'], CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
- curl_setopt($_SESSION['ch'], CURLOPT_COOKIEJAR, 'cookie.txt');
- curl_setopt($_SESSION['ch'], CURLOPT_COOKIEFILE, 'cookie.txt');
- curl_setopt($_SESSION['ch'], CURLOPT_COOKIE, $strCookie );
- curl_setopt($_SESSION['ch'],CURLOPT_ENCODING , "gzip");
- curl_setopt($_SESSION['ch'], CURLOPT_REFERER, $url);
- curl_setopt($_SESSION['ch'], CURLOPT_HTTPHEADER, $h);
-
- //execute post
- $result = curl_exec($_SESSION['ch']);
-
- curl_close($_SESSION['ch']);
-
- echo $result;
-
- session_destroy();
- endif;
-
-
- //Find picture.
- preg_match_all("/<img(.*)src=\"(.*?)captcha\.php(.*?)\"(.*?)>/", $get, $lol);
- $url = explode("/", $url);
- $url = "http://".$url[2];
-
- preg_match_all("/<select(.*?)>(.*)<\/select>/is", $get, $rofl);
- preg_match_all("/<input(.*?)name=\"IMAGEHASH\"(.*?)value=\"(.*?)\"(.*?)>/is", $get, $imagehash);
-
- $imageHashNew = $imagehash[3][0];
- ?>
- <div class="letshavefun">
- <form action="" method="post">
- <div style="text-align:center;margin: 0 auto;width:400px">
- <em>Submitting to <a href="<?=$url;?>" target="_blank"><?=$url;?></a></em><br /><br />
-
- <strong>Title</strong><br />
- <input type="text" name="TITLE" /><br />
-
- <!--PRINTS THE CAPTCHA PICTURE -->
- Enter Captcha:<br />
- <? $e = str_replace("/", "", $lol[0][0]); echo str_replace("captcha.php", $url . "/captcha.php", $e); ?>
- <br /><input type="text" name="captcha" /><br /><br />
-
- Categori: <br />
- <?=$rofl[0][0];?><br /><br />
-
- <input type="hidden" value="<?=$imageHashNew;?>" name="heey" />
- <input type="submit" value="Submit" class="sb" name="finger" />
- </div>
- </form>
- </div>
På forhånd tak og god lørdag.