 |
Forum PHP Romania - Discutii despre PHP, MySQL, Javascript, AJAX, etc Comunitatea PHP Romania
|
| Subiectul anterior :: Subiectul următor |
| Autor |
Mesaj |
irinel
Data înscrierii: 27/Oct/2005
Mesaje: 10
|
| Trimis: Lun Feb 13, 2006 10:25 pm Titlul subiectului: Problema cURL |
|
|
Salutare.
Ma comfrunt cu o problema oarecum ciudata si am nevoie de ceva sfaturi de la cunoscatorii de cURL.
Se da urmatorul cod:
Cod:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "www.google.ro");
curl_exec($ch);
curl_close($ch);
acesta nu are nici o problema pe server-ul testat.
Se da si urmatorul cod:
Cod:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "url/cpanel");
curl_setopt($ch, CURLOPT_USERPWD, "username:parola");
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1");
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_exec($ch);
curl_close($ch);
acesta din urma nu imi returneaza nimic. Testat pe o alta masina merge fara probleme.
Pe masina in cauza avem php 4.4.1 cu libcurl/7.12.0.
Multumesc anticipat. |
|
| Sus |
|
aurelian
Data înscrierii: 01/Iun/2003
Mesaje: 833
Locație: Bucuresti
|
| Trimis: Mar Feb 14, 2006 10:07 am Titlul subiectului: |
|
|
Din cate stiu, cpanel ruleaza pe https.
Pentru asta, php-ul trebuie compilat cu
Cod:
--with-openssl
in phpinfo, la intrarea corespunzatoare cURL, trebuie sa scrie (de ex.):
Cod:
CURL Information: libcurl/7.15.1 [b]OpenSSL/0.9.8a[/b] zlib/1.2.3 libidn/0.6.1
Informatiile astea se gasesc si in manualul de php, deci nu cred ca este chiar asa de php-avansat. |
|
| Sus |
|
irinel
Data înscrierii: 27/Oct/2005
Mesaje: 10
|
| Trimis: Mar Feb 14, 2006 4:54 pm Titlul subiectului: |
|
|
Extras din phpinfo();
Citat: CURL support enabled
CURL Information libcurl/7.12.0 OpenSSL/0.9.7a zlib/1.1.4 |
|
| Sus |
|
aurelian
Data înscrierii: 01/Iun/2003
Mesaje: 833
Locație: Bucuresti
|
| Trimis: Mar Feb 14, 2006 5:12 pm Titlul subiectului: |
|
|
cu:
Cod:
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
merge? |
|
| Sus |
|
irinel
Data înscrierii: 27/Oct/2005
Mesaje: 10
|
| Trimis: Mar Feb 14, 2006 7:18 pm Titlul subiectului: |
|
|
Mda, e destul de ciudat ce se intampla.
O sa explic mai pe larg care si cum sta treaba.
Pentru inceput este vorba de 2 servere (A si B), ambele cpanel pe ele si un script care adauga Cron jobs-uri.
A - PHP Version 4.3.11 / CURL support enabled / CURL Information libcurl/7.12.0 OpenSSL/0.9.7a zlib/1.1.4
B - PHP Version 4.4.1 / CURL support enabled / CURL Information libcurl/7.12.0 OpenSSL/0.9.7a zlib/1.1.4
Scriptul ...
Cod: <html>
<head>
<title>Quick Cron - The Easy Cron Creator
</title>
<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>
<style type='text/css'>
<!--
body, th, td, input, select
{
font-family: Verdana;
font-size: 12px;
}
body (background:#EEEEEE;)
td (width:100%;)
-->
</style>
</head>
<body>
<div align='center'>
<font size='7'><strong>Quick Cron</strong></font>
<br />
<font size='5'><strong>The Easy Cron Creator</strong></font>
<br /><br />
<form method='post' action='<?php echo $PHP_SELF; ?>' method='post' enctype='multipart/form-data'>
<table border='1' cellpadding='4' cellspacing='0' width='700' bordercolor='black'>
<tr>
<td bgcolor=#cccccc align='center' >
</td>
<td bgcolor=#cccccc align='center' >
<strong>
Domain Name (www.domain.com)
</strong>
</td>
<td bgcolor=#cccccc align='center' >
<strong>
CPanel username
</strong>
</td>
<td bgcolor=#cccccc align='center' >
<strong>
CPanel password
</strong>
</td>
</tr>
<tr>
<td bgcolor=#cccccc align='center' >
http://
</td>
<td bgcolor=#dfdfdf >
<input type='text' name='domainname' value='' style='width:100%;' maxlength='100'>
</td>
<td bgcolor=#dfdfdf >
<input type='text' name='uname' value='' style='width:100%;' maxlength='50'>
</td>
<td bgcolor=#dfdfdf >
<input type='text' name='pword' value='' style='width:100%;' maxlength='50'>
</td>
</tr>
<tr>
<td colspan=4 bgcolor=#cccccc>
<table width='100%' align='center'>
<tr align='center'>
<td><strong>EMAIL</strong></td>
<td><strong>MINUTE</strong></td>
<td><strong>HOUR</strong></td>
<td><strong>DAY</strong></td>
<td><strong>MONTH</strong></td>
<td><strong>WEEKDAY</strong></td>
<td><strong>COMMAND</strong></td>
</tr>
<tr align='center'>
<td><input type=text name="email" size=25 value=""></td>
<td><input type=text name="minute" size=2 value="0"></td>
<td><input type=text name="hour" size=2 value="0"></td>
<td><input type=text name="day" size=2 value="*"></td>
<td><input type=text name="month" size=2 value="*"></td>
<td><input type=text name="weekday" size=2 value="*"></td>
<td><input type=text name="cmd" size=45 value=""></td>
</tr>
</table>
</td>
</tr>
<tr>
<td bgcolor=#cccccc colspan=4 align='center'>
<input type='hidden' name='frmAction' value='<?php echo $PHP_SELF; ?>'>
<input type='submit' name='action' value='Create Cron!'>
</td>
</tr>
</table>
</form>
</div>
</body>
</html>
<?php
if ($frmAction)
{
function get_input_vars()
{
global $HTTP_SERVER_VARS;
$REQUEST_METHOD = $HTTP_SERVER_VARS['REQUEST_METHOD'];
global $HTTP_POST_VARS;
global $HTTP_GET_VARS;
$vars = $REQUEST_METHOD == 'POST' ? $HTTP_POST_VARS : $HTTP_GET_VARS;
foreach ($vars as $k=>$v)
{
if (is_array($v)) continue;
if (get_magic_quotes_gpc()) $v = stripslashes($v);
$vars[$k] = trim($v);
}
return $vars;
}
$vars = get_input_vars();
foreach ($vars as $value)
{
if ($value=="")
{
echo "<br /><div align='center'><strong>You have not filled in all the fields</strong></div><br />\n";
exit();
}
}
$cpurl=$vars['domainname'];
$cpuser=$vars['uname'];
$cppassword=$vars['pword'];
$cmd=$vars['cmd'];
$minute=$vars['minute'];
$hour=$vars['hour'];
$day=$vars['day'];
$month=$vars['month'];
$weekday=$vars['weekday'];
$email=$vars['email'];
$cpurl=($cpurl.'/cpanel');
function createcron($cpurl,$cpuser,$cppassword,$cmd,$minute,$hour,$day,$month,$weekday,$email)
{ $ch=curl_init(); curl_setopt($ch,CURLOPT_URL,$cpurl);
curl_setopt($ch,CURLOPT_USERPWD,"$cpuser:$cppassword");
curl_setopt($ch,CURLOPT_HEADER,1); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)');
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,FALSE);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$html=curl_exec($ch); $error='';
$a=strpos($html,'Location:')+9; $b=strpos($html,"\n",$a); $baseurl=trim(substr($html,$a,$b-$a));
$a=strpos($html,'/frontend'); $b=strpos($html,'index.html',$a); $baseurl.=substr($html,$a,$b-$a);
if (strpos($baseurl,'http')===false) $error='Cannot login to CPanel';
if ($error=='')
{ curl_setopt($ch,CURLOPT_URL,$baseurl."cron/advcron.html?");
$html=curl_exec($ch); $query=ParseFORM($html);
$query['mailto']=$email; $query['0-minute']=$minute;
$query['0-hour']=$hour; $query['0-day']=$day;
$query['0-month']=$month; $query['0-weekday']=$weekday;
$query['0-command']=$cmd;
curl_setopt($ch,CURLOPT_URL,$baseurl."cron/editcron.html");
curl_setopt($ch,CURLOPT_POST,1); curl_setopt($ch,CURLOPT_POSTFIELDS,build_query($query));
$html=curl_exec($ch); }
curl_close($ch);
if ($error=='') return true; else return $error; }
function build_query($args)
{ $query=array(); foreach ($args as $key=>$value) $query[]=$key."=".urlencode($value);
return implode("&",$query); }
function ParseFORM($html)
{ $lhtml=strtolower($html); $query=array(); $pos=0;
while ($pos!==false)
{ $pos=strpos($lhtml,'<input',$pos);
if ($pos!==false)
{ $p=strpos($lhtml,'name=',$pos);
if ($p!==false)
{ $p+=5; $p2=strpos($html,' ',$p); $name=substr($html,$p,$p2-$p);
if ($name[0]=='"') $name=substr($name,1);
if ($name[strlen($name)-1]=='"') $name=substr($name,0,strlen($name)-1);
$p=strpos($lhtml,'value=',$p2);
if ($p!==false)
{ $p+=6; $p2=strpos($html,'>',$p); $value=substr($html,$p,$p2-$p);
if ($value[0]=='"') $value=substr($value,1);
if ($value[strlen($value)-1]=='"') $value=substr($value,0,strlen($value)-1);
$query[$name]=$value; } } }
$pos++; }
return $query; }
$res=createcron($cpurl,$cpuser,$cppassword,$cmd,$minute,$hour,$day,$month,$weekday,$email);
if ($res===true)
{
//echo "OK\n";
}
else
{
echo "Error: ".$res;
exit();
}
###########################
$cpaneluser=$vars['uname'];
echo "
<html>
<head>
<title> Quick Cron - The Easy Cron Creator
</title>
<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>
<style type='text/css'>
<!--
body, th, td, input, select
{
font-family: Verdana;
font-size: 12px;
}
body (background:#EEEEEE;)
td (width:100%;)
-->
</style>
</head>
<body>
<table border='0' width='100%' align='center'>
<tr>
<td align='center'>
<form name='it'>
<div id='all-code'>
<h2>
CRON CREATED!
</h2>
<script type='text/javascript'>
document.write(' ');
</script>
<p>
<input type=button value='Highlight All'onClick='javascript:this.form.txt.focus();
this.form.txt.select();'>
</p>
<textarea name='txt' rows='6' cols='80' id='code' scrollbar='no'>
URL: $cpurl
USER: $cpuser
PASSWD: $cppassword
EMAIL: $email
MINUTE: $minute
HOUR: $hour
DAY: $day
MONTH: $month
WEEKDAY:$weekday
COMMAND:$cmd
</textarea>
</div>
</form>
</td>
</tr>
</table>
</body>
</html>
";
}
?>
Problema e asa.
Scriptul pus pe A. Vreau sa adaug un cron job pe B merge fara probleme.
Scriptul pus pe B. Vreau sa adaug un cron job pe A ...
Cod: PHP Warning: strpos(): Offset not contained in string. in file.php on line 154
Din cate mi-am dat eu seama, problema pleaca de la cURL ... insa ce anume poate cauza asta nu pot sa-mi dau seama.
Need advice.
Multumesc anticipat. |
|
| Sus |
|
PHPRomania Bot
Bot Member
Data înscrierii: 27/Dec/2007
Mesaje: 1
Locaţie: Server Google |
| Trimis: Mie Dec 26, 2007 7:01 pm Titlul subiectului: Ad |
|
|
|
|
|
| Sus |
|
| |
|