danrox2004
03-06-2007, 10:42 AM
Here i will be doing a tutorial on how to create a function similar to AddToOnlineReport. You need basic php and scar knowledge. First i will show you the finished script:
scar part:
Php part:
program New;
Const
Username = 'danrox2004';
Password = 'mypass';
function AddToOnlineReport(text: String): Boolean;
var
Site: Integer;
S: String;
begin
Site := InitializeHTTPClient ( false, false );
ClearPostData( Site );
AddPostVariable( Site, 'report', Text);
AddPostVariable( Site, 'username', Username);
AddPostVariable( Site, 'password', Password);
S := PostHTTPPageEx ( Site, 'http://danrox2004.byethost32.com/scarreport/index.php' );
if(S <> '') then
begin
if(S = 'Authentication Successful') then
Result:=True
else
Result:=False;
end else
Result:=False;
Writeln(S);
end;
begin
AddToOnlineReport('Line 3')
end.
-username and password are global vars
Okay first of - the scar side.
First we create the function-
function AddToOnlineReport(text: String): Boolean;
begin
end;
Now we will need some variables - Site is the variable to hold the connection and S is the result from the page. We declare them like so-
var
Site: Integer;
S: String;
Now to connect to a site we use the function InitializeHTTPClient. We are not using cookies or redirects so we will put both things as false-
InitializeHTTPClient( false, false );
We assign it to the variable Site. Now we want to clear the post data off site to make sure there is none left -
ClearPostData( Site );
Now we need to assign the things we are going to send to the server. We are including a simple auth system so we will need to send a username, a password as well as the text we are going to write to it. To do this we add a postvariable. This sends the information in the headers of the request, not in the url.
AddPostVariable( Site, 'report', Text);
AddPostVariable( Site, 'username', Username);
AddPostVariable( Site, 'password', Password);
Now we want to send the request. To do so we use the function PostHttpPageEx. This sends the information and returns the data on the page. We want to store that data in the variable S so we can check if the request was succesful.
S := PostHTTPPageEx ( Site, 'http://danrox2004.byethost32.com/scarreport/index.php' );
Replace that with the site you are hosting on.
Now we are going to analyse the result. The possible results are -
Invalid username/password
or Authentication succesful
or no result at all (something didnt work)
So we check if S is not equal to nothing, and if it isnt then we check if it says Authentication Succesful. If it does we know it has worked. To do this we use some if statements:
if(S <> '') then
begin
if(S = 'Authentication Successful') then
Result:=True
else
Result:=False;
end else
Result:=False;
Now for debugging purposes we are going to write in what the php script returned
Writeln(S);
That is the finished scar side of the script
PART TWO - the php side
There are two parts to the php side - the receiving of data and the showing of data.
First we get each of the post variables and assign them to global variables, while trimming of whitespace:
$Text = Trim($_POST['report']);
$Username = Trim($_POST['username']);
$Password = Trim($_POST['password']);
Now if we are recieving data from scar the variable report in the post data should be set, if not we are to write in the report so far.
to do this we check if the report var has been set
<?
if(isset($_POST['report'])){
}else{
}
Now if report has been set we want to authenticate the user. We use a series of if statements to check if the username and password match the one specified.
if($Username == 'danrox2004' and $Password == 'mypass'){
}else{
echo('Invalid Username / Password');
}
If the authentication was succesful we want to write the data to a text file -
$fp = fopen("report.txt", "a");
fwrite($fp, '
'.$Text);
fclose($fp);
echo('Authentication Successful');
We add a new line in for ease later - we could have seperated the lines by a comma or something but this way is easier for this task.
That is the finished receiving side of the script.
Now we will work on the returning results to the user.
First we want to open the file. This returns the results as an array - each line a seperate part of the array. Next we reverse the array so that the newest results are at the top. Then we put the array together so we can send it to the viewer.
$file = file('report.txt');
$file = array_reverse($file);
$file = implode('<br>',$file);
echo($file);
I hope you like this tutorial - my second one
scar part:
Php part:
program New;
Const
Username = 'danrox2004';
Password = 'mypass';
function AddToOnlineReport(text: String): Boolean;
var
Site: Integer;
S: String;
begin
Site := InitializeHTTPClient ( false, false );
ClearPostData( Site );
AddPostVariable( Site, 'report', Text);
AddPostVariable( Site, 'username', Username);
AddPostVariable( Site, 'password', Password);
S := PostHTTPPageEx ( Site, 'http://danrox2004.byethost32.com/scarreport/index.php' );
if(S <> '') then
begin
if(S = 'Authentication Successful') then
Result:=True
else
Result:=False;
end else
Result:=False;
Writeln(S);
end;
begin
AddToOnlineReport('Line 3')
end.
-username and password are global vars
Okay first of - the scar side.
First we create the function-
function AddToOnlineReport(text: String): Boolean;
begin
end;
Now we will need some variables - Site is the variable to hold the connection and S is the result from the page. We declare them like so-
var
Site: Integer;
S: String;
Now to connect to a site we use the function InitializeHTTPClient. We are not using cookies or redirects so we will put both things as false-
InitializeHTTPClient( false, false );
We assign it to the variable Site. Now we want to clear the post data off site to make sure there is none left -
ClearPostData( Site );
Now we need to assign the things we are going to send to the server. We are including a simple auth system so we will need to send a username, a password as well as the text we are going to write to it. To do this we add a postvariable. This sends the information in the headers of the request, not in the url.
AddPostVariable( Site, 'report', Text);
AddPostVariable( Site, 'username', Username);
AddPostVariable( Site, 'password', Password);
Now we want to send the request. To do so we use the function PostHttpPageEx. This sends the information and returns the data on the page. We want to store that data in the variable S so we can check if the request was succesful.
S := PostHTTPPageEx ( Site, 'http://danrox2004.byethost32.com/scarreport/index.php' );
Replace that with the site you are hosting on.
Now we are going to analyse the result. The possible results are -
Invalid username/password
or Authentication succesful
or no result at all (something didnt work)
So we check if S is not equal to nothing, and if it isnt then we check if it says Authentication Succesful. If it does we know it has worked. To do this we use some if statements:
if(S <> '') then
begin
if(S = 'Authentication Successful') then
Result:=True
else
Result:=False;
end else
Result:=False;
Now for debugging purposes we are going to write in what the php script returned
Writeln(S);
That is the finished scar side of the script
PART TWO - the php side
There are two parts to the php side - the receiving of data and the showing of data.
First we get each of the post variables and assign them to global variables, while trimming of whitespace:
$Text = Trim($_POST['report']);
$Username = Trim($_POST['username']);
$Password = Trim($_POST['password']);
Now if we are recieving data from scar the variable report in the post data should be set, if not we are to write in the report so far.
to do this we check if the report var has been set
<?
if(isset($_POST['report'])){
}else{
}
Now if report has been set we want to authenticate the user. We use a series of if statements to check if the username and password match the one specified.
if($Username == 'danrox2004' and $Password == 'mypass'){
}else{
echo('Invalid Username / Password');
}
If the authentication was succesful we want to write the data to a text file -
$fp = fopen("report.txt", "a");
fwrite($fp, '
'.$Text);
fclose($fp);
echo('Authentication Successful');
We add a new line in for ease later - we could have seperated the lines by a comma or something but this way is easier for this task.
That is the finished receiving side of the script.
Now we will work on the returning results to the user.
First we want to open the file. This returns the results as an array - each line a seperate part of the array. Next we reverse the array so that the newest results are at the top. Then we put the array together so we can send it to the viewer.
$file = file('report.txt');
$file = array_reverse($file);
$file = implode('<br>',$file);
echo($file);
I hope you like this tutorial - my second one