Follow me on Twitter to receive updates, free scripts and ongoing announcements!

Delphi http post

Written by Codes Tips on June 2, 2009 – 9:42 am -

To post some data through http protocol in Delphi you can use TIDHttp component.
TIDHttp has a function Post that takes 2, first parameter is the url where you wanna post data and the second is the data you need to post.
The first parameter of Post function is a string and the second one is a TStringList.

Delphi sample code to post data through http. First put in the uses clause IdHTTP

function PostData:string;
var    param:TStringList;
       valid:boolean;
       url,text:string;
       http:TIDHttp;
begin
http := TIDHttp.Create(nil);
http.HandleRedirects := true;
http.ReadTimeout := 5000;
param:=TStringList.create;
param.Clear;
param.Add('parameter1=1');
param.Add('parameter2=2');
param.Add('parameter3=3');
valid:=true;
url:='http://www.examplesite.com/script.php';
 try
   text:=http.Post(url,param);
 except
  on E:Exception do
   begin
    valid:=false;
   end;
 end;
if valid then
 PostData:= text
else
 PostData := '';
end;

You can call the function like this:

textPostData := PostData();

This function returns empty string if it was an error posting data, if not it returns the text that is returned from the url that we posted data.

We created a new TIDHttp variable at runtime and put the properties ReadTimeout to 5 seconds(timeout of the connection) and HandleRedirects to true, because the url where we post data can redirect us to other page from where we get the result.


Tags: ,
Posted in Codes, Delphi | No Comments »

PHP cpanel scripts

Written by Codes Tips on June 1, 2009 – 8:50 am -

Intro

To automate an action in PHP for cpanel it’s very easy. You just need to know some information about your cpanel. You can find this information on your browser link bar.

$cpanel_user - the username that you use to log into your cpanel
$cpanel_password - the password for cpanel.
$cpanel_host - your cpanel host. You can find this after you login to cpanel, right before ‘http://’ until ‘:’.
$cpanel_skin - cpanel skin. You can find this after ‘/frontend/’, default is ‘x’.

HTML Form

You can use this html forms to make the scripts for cpanel, you can add your own fields that you need.

<form action="cpaneladd.php" method="POST">
<table>
<tr><td colspan="2" align="center">
<b>Cpanel info</b></td></tr><tr><td align="right">Cpanel host:
</td><td align="left">
<input type="text" name="cpanelhost"></td></tr>
<tr><td align="right">Cpanel username:</td><td align="left">
<input type="text" name="cpaneluser"></td></tr>
<tr><td align="right">Cpanel password:</td><td align="left">
<input type="text" name="cpanelpass"></td></tr>
<tr><td align="right">Cpanel skin:</td><td align="left">
<input type="text" name="cpanelskin" values="x"></td></tr>
</table>
</form>

I made a list with some useful functions that you can use for cpanel:

1. Adding a database in cpanel

 $newdb = "db_name";
 $curl = curl_init();
 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
 curl_setopt ($curl, CURLOPT_URL, "http://$cpanel_user:
$cpanel_password@$cpanel_host:2082/frontend/$cpanel_skin
/sql/adddb.html?db=$new_db");
 $result=curl_exec ($curl);
 curl_close ($curl);

2. Adding a user to database in cpanel

      $db_user = "dbuser";
      $db = "database";
      $curl = curl_init();
      curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt ($curl, CURLOPT_URL, "http://$cpanel_user:
$cpanel_password@$cpanel_host:2082/frontend/$cpanel_skin/
sql/addusertodb.html?user={$cpanel_user}_{$db_user}
&db={$cpanel_user}_{$db}&ALL=ALL");
      $result=curl_exec ($curl);
       curl_close ($curl);

3. Delete a user in cpanel

     $userdb="userdb";
     $curl = curl_init();
     curl_setopt ($curl, CURLOPT_URL, "http://$cpanel_user:
$cpanel_password@$cpanel_host:2082/frontend/$cpanel_skin/
sql/deluser.html?user=".$cpanel_user."_".$userdb);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
     $result=curl_exec ($curl);
     curl_close ($curl);

4. Delete a database in cpanel

     $db="db";
     $curl = curl_init();
     curl_setopt ($curl, CURLOPT_URL, "http://$cpanel_user:
$cpanel_password@$cpanel_host:2082/frontend/$cpanel_skin
/sql/deldb.html?db=".$cpanel_user."_".$db);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
     $result=curl_exec ($curl);
     curl_close ($curl);

Tags: ,
Posted in Codes, PHP/MYSQL, Scripts | No Comments »

Plugintaylor.com - Plugintaylor and Custom Field