login  Naam:   Wachtwoord: 
Registreer je!
 Forum

Wat heb ik fout gedaan ? regel 66 snap er niks meer van :s

Offline iky - 28/02/2012 18:55 (laatste wijziging 28/02/2012 23:10)
Avatar van ikyLid
  1. <?php
  2.  
  3.  
  4. class Curl {
  5. var $callback = false;
  6. var $secure = false;
  7. var $conn = false;
  8. var $cookiefile =false;
  9. var $header = false;
  10. var $cookie = false;
  11. var $follow = true;
  12. var $dump = false;
  13. var $range = false;
  14. var $timeout = false;
  15. var $user_agent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
  16.  
  17. function Curl($u = false) {
  18. $this->conn = curl_init();
  19. if (!$u) {
  20. $u = rand(0,100000);
  21. }
  22.  
  23. $file = dirname(__FILE__).'/temp/'.md5($u);
  24. $file = str_replace('\\','/', $file);
  25. $this->cookiefile= $file;
  26.  
  27. }
  28.  
  29. function setCallback($func_name) {
  30. $this->callback = $func_name;
  31. }
  32.  
  33. function close() {
  34. curl_close($this->conn);
  35. if (is_file($this->cookiefile)) {
  36. //unlink($this->cookiefile);
  37. }
  38.  
  39. }
  40.  
  41. function doRequest($method, $url, $vars) {
  42.  
  43. $ch = $this->conn;
  44.  
  45. curl_setopt($ch, CURLOPT_URL, $url);
  46. if ($this->header) {
  47. curl_setopt($ch, CURLOPT_HEADER, 1);
  48. } else {
  49. curl_setopt($ch, CURLOPT_HEADER, 0);
  50. }
  51. curl_setopt($ch, CURLOPT_USERAGENT,$this->user_agent);
  52. curl_setopt( $ch, CURLOPT_HTTPHEADER, array("REMOTE_ADDR: ".$_SERVER['REMOTE_ADDR'], "HTTP_X_FORWARDED_FOR: ".$_SERVER['REMOTE_ADDR'])); // send users ip ???
  53.  
  54.  
  55. if($this->secure) {
  56. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  57. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  58. }
  59.  
  60. if ($this->cookie)
  61. {
  62. curl_setopt($ch, CURLOPT_COOKIE,$this->cookie);
  63. }
  64.  
  65. if ($this->follow) {
  66. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  67. } else {
  68. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
  69. }
  70.  
  71. if($this->dump) {
  72. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
  73. } else {
  74. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  75. }
  76.  
  77. if($this->range)
  78. {
  79. curl_setopt($ch, CURLOPT_RANGE,$this->range);
  80. }
  81.  
  82. if($this->timeout)
  83. {
  84. curl_setopt($ch, CURLOPT_TIMEOUT,$this->timeout);
  85. } else {
  86. curl_setopt($ch, CURLOPT_TIMEOUT,false);
  87. }
  88.  
  89. curl_setopt($ch, CURLOPT_COOKIEJAR, $this->cookiefile);
  90. curl_setopt($ch, CURLOPT_COOKIEFILE, $this->cookiefile);
  91.  
  92. if ($method == 'POST') {
  93. curl_setopt($ch, CURLOPT_POST, 1);
  94. curl_setopt($ch, CURLOPT_POSTFIELDS, $vars);
  95. curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect: ')); // lighttpd fix
  96. }
  97.  
  98. $data = curl_exec($ch);
  99.  
  100. if ($data) {
  101. if ($this->callback)
  102. {
  103. $callback = $this->callback;
  104. $this->callback = false;
  105. return call_user_func($callback, $data);
  106. } else {
  107. return $data;
  108. }
  109. } else {
  110. return false;
  111. }
  112. }
  113.  
  114. function get($url) {
  115. return $this->doRequest('GET', $url, 'NULL');
  116. }
  117.  
  118.  
  119. function processHeader($ch,$string)
  120. {
  121. if(preg_match('%Content-Range: bytes 0-1024/([0-9]+)%', $string,$match))
  122. {
  123. $this->size = $match[1];
  124. return false;
  125. }
  126.  
  127. if(preg_match('%Content-Length: ([0-9]+)%', $string,$match))
  128. {
  129. $this->size = $match[1];
  130. return false;
  131. }
  132.  
  133. return strlen($string);
  134. }
  135.  
  136. function getSize($url) {
  137.  
  138. $this->size = false;
  139.  
  140. $this->header = true;
  141. $this->range = "0-1024";
  142. $this->dump = true; // some sites dont echo in curl
  143.  
  144. curl_setopt($this->conn,CURLOPT_HEADERFUNCTION,array($this,processHeader));
  145. $this->doRequest('GET', $url,false);
  146. $result = ob_get_contents();
  147.  
  148. $this->dump = false;
  149. $this->header = false;
  150. $this->range = false;
  151.  
  152. return $this->size;
  153. }
  154.  
  155.  
  156. function getError()
  157. {
  158. return curl_error($this->conn);
  159. }
  160.  
  161. function post($url, $params = false) {
  162.  
  163. $post_data = '';
  164.  
  165. if (is_array($params)) {
  166.  
  167. foreach($params as $var=>$val) {
  168. if(!empty($post_data))$post_data.='&';
  169. $post_data.= $var.'='.urlencode($val);
  170. }
  171.  
  172. } else {
  173. $post_data = $params;
  174. }
  175.  
  176. return $this->doRequest('POST', $url, $post_data);
  177. }
  178.  
  179. function streamHeader($ch,$string)
  180. {
  181. if(empty ($string)) return;
  182.  
  183. header($string);
  184. return strlen($string);
  185. }
  186.  
  187. function stream($url)
  188. {
  189. $this->dump = true;
  190. curl_setopt($this->conn,CURLOPT_HEADERFUNCTION,array($this,"streamHeader"));
  191. $this->doRequest('GET', $url,false);
  192.  
  193. }
  194.  
  195. function getRedirect($url)
  196. {
  197. $this->follow = false;
  198. $this->header = true;
  199.  
  200. $html = $this->get($url);
  201.  
  202. if(preg_match('/Location: (.*?)[\r\n]+/',$html,$match) || preg_match('/http-equiv=\'Refresh\' content=\'[0-9]+;url=(.*?)\'/s',$html,$match))
  203. {
  204. return $match[1];
  205. }
  206.  
  207. $this->follow = true;
  208. $this->header = false;
  209. }
  210.  
  211. }
  212.  
  213. function getPage($url,$post = false,$cookie = false)
  214. {
  215. $pURL = parse_url($url);
  216.  
  217. $curl = new Curl($pURL['host']);
  218.  
  219. if (strstr($url,'https://'))
  220. {
  221. $curl->secure = true;
  222. }
  223.  
  224. if ($post) {
  225. return $curl->post($url,$post);
  226. } else {
  227. return $curl->get($url);
  228. }
  229.  
  230. }

9 antwoorden

Gesponsorde links
Offline avdg - 28/02/2012 19:35
Avatar van avdg PHP gevorderde Wat snap je niet? Wat wil je? Wat is er fout in de code?
Offline iky - 28/02/2012 21:08
Avatar van iky Lid In line 66

Ik weet niet wat er fout aan is ??
Offline Maarten - 28/02/2012 21:21 (laatste wijziging 29/02/2012 13:52)
Avatar van Maarten Erelid En welke foutmelding krijg je?

edit
Forum regels schreef:
Bedenk een duidelijke titel
Titels zoals ‘HELP MIJ!!’,‘fout’, ‘probleem’, enzovoort nodigen niet bepaald uit om het topic te gaan lezen. Daarom is het van belang om een duidelijke titel te bedenken die een korte omschrijving van je probleem geeft.
Offline Pieter - 28/02/2012 21:48 (laatste wijziging 29/02/2012 09:02)
Avatar van Pieter Gouden medaille

SEO guru
Seriously. 231 regels code. En een fout. Los het maar op.

stijn schreef:
Hij had het twee keer gepost in twee verschillende ubb tags.


@Stijn, thnx voor de correctie. 

We zijn geen helderzienden, op zijn minst kan je wat omkadering geven. Wat doe je exact? Welke fout? Is het een gekopieerd script? Wat heb je al geprobeerd? Heeft het al gewerkt voordien?
Offline vinTage - 28/02/2012 22:10 (laatste wijziging 28/02/2012 22:10)
Avatar van vinTage Nieuw lid er is geen fout op r66 en ja het script is gekopieerd Als ik het goed 'gegoogled' heb, is het een phpnuke youtube plugin geval.
Offline Stijn - 28/02/2012 23:08
Avatar van Stijn PHP expert lol phpnuke... bestaat dat cms nog .
Offline iky - 29/02/2012 22:01
Avatar van iky Lid Warning: curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when safe_mode is enabled or an open_basedir is set in /home/a3448534/public_html/youtube/curl.php on line 66

Daar zou ergens de fout moeten zitten volgens de php error ik zie allen de fout niet...


het is van mijn youtube donwload script...

MVG
Offline avdg - 29/02/2012 22:28
Avatar van avdg PHP gevorderde het lijkt me erop dat de curl extension niet zijn werk kan doen omdat php is ingesteld in safe_mode.

Als de code vaak gebruikt wordt, dan zou het script normaal ok zijn (noot: ik heb niet naar de code gekeken). Het is een kwestie van php correct in te stellen.

Als je aan de php.ini aan kan, zoek voor optie safe_mode en zet em af 
Tot zover de korte uitleg.
Offline Maarten - 29/02/2012 22:42
Avatar van Maarten Erelid De foutmelding zegt het echt letterlijk... CURLOPT_FOLLOWLOCATION kan niet worden geactiveerd omdat safe_mode aanstaat OF open_basedir is ingesteld.

Dus moet je even checken met phpinfo() of safe_mode aanstaat -> waarschijnlijk wel, en die uitschakelen. Wat dan weer enkel mogelijk is als je beschikt over een eigen server-omgeving dacht ik?
Gesponsorde links
Je moet ingelogd zijn om een reactie te kunnen posten.
Actieve forumberichten
© 2002-2024 Sitemasters.be - Regels - Laadtijd: 0.229s