Sunday, June 21, 2015

File Read and Write in PHP


Hello guys, how are you?

Today we will look in to the File Operations in PHP.

Whether to read or a write to a file, first of all we must open the file using PHP. The function that we use to open a file in PHP is fopen() function. This function accepts two parameters:-

  • file path
  • the mode that the file should be opened
$fp = fopen("input.txt", "r");

Here file is opened and assigned to a variable. This variable is usually called as file pointer. This will make our operations easy.



Modes that we can open a file :-
  • r - read only
  • w - write only(existing data will be re-written)
  • a - write only(new text will be added to the end of the existing text)
  • x - creates a new file for write only
  • r+ - opens a file for read and write
  • w+ - opens a file for read and write
  • a+ - opens a file for read and write
  • x+ - creates a new file for read and write

After opening the file in read  mode we can read the text which is existing in the file and assign it to a PHP variable. To do that we can use fread()  function. This function accepts two parameters.
  • file path
  • maximum bytes to read
$content = fread("input.txt",1024);

Or else we can use the file pointer variable as parameter. If we use that as a parameter it will read the file till it reach the end of the file.

$content = fread($fp);

If we want to read a single line of the file we can do it using fgets() function. This function also accepts two parameters. 
  • file path
  • file open mode
$content = fgets("input.txt","r");
$content = fread($fp);

In some context we maybe want to check whether the file pointer has reached the end of the file. So we can do it using feof() function. This function accepts one parameter which is the file pointer variable.

if(feof($fp)){
     echo("End of the file has reached!");
}

After opening a file for reading or writing purpose we have to close the file. Otherwise the file pointer will keep the file open and that will lead for errors and unexpected problems. To close a file we can use fclose() function. This function accepts one parameter which is also the file pointer variable.

fclose($fp);

These are the basic and most used file handling functions in PHP and there are plenty of more functions available to do various tasks.
Below link will show some more functions :-


Past Topics :-
Like us on Facebook:



Comment box is open for your comments, ideas and suggestions!

Friday, May 8, 2015

Creating PDF Reports and Files in PHP


Hello everyone, how are you guys??
Sorry for my silence in past few days, had some projects and assignments to complete!

Well this article will focus on creating a PDF report or a PDF file using PHP.

So first of all we have to download the FPDF support library to generate PDF files. Visit  http://www.fpdf.org/ and go to downloads and download the latest version.

Well now we are ready to go.

Step 1 :- Import the library to our PHP file.
              include("includes/fpdf/fpdf.php");

Step 2 :- In order to use the functions in FPDF library we have to create a object of fpdf class.
                         $pdf = new FPDF('P','pt','A4');
 In here $pdf is our object name and P is for the page orientation, A4 is for page size.

Step 3 :- Now we have created the object and we have to open the pdf file.
                        //opening the pdf file
              $pdf->Open();

Step 4 :- Then add the first page of the PDF file.
                       //add the first page
             $pdf->AddPage("P","A4");

Step 5 :- Set the X and Y axis for the content in the PDF file
             //setting y axis through a variable
             $Yax = 30;
             $pdf->SetY($Yax);
             //setting X axis directly
             $pdf->SetX(40);



Well now, we have created our pdf file. Remember not to add PHP closing tag in the PDF generating code.

Lets see some functions that we can use to add some text and decorate them.

//setting title
$pdf->SetFillColor(234,44,234);
Above lines will add background color to the text.

//setting font $pdf->SetFont('Arial','B',25);
Above lines will define the font that we want our text to be printed in the PDF file

//adding the text to the pdf file $pdf->Cell(0,30,"Book Catalogue",0,1,"C",1);
Above lines will add the text or the line of text to the PDF file. 
$pdf->Cell(a,b,c,d,e,f,g);
a - X value of the position
b - Y value of the position
c - text that we want to print
d - border value of the text cell
e - line number
f - alignment of the text
g - indicates if the line cell background is filled(true,1) or not(false,0). Default value is false.

//adding more text to the pdf file(paragraphs)
$pdf->Write(0,"Error selecting values from database! ".mysql_error());
$pdf->Write(0,"your paragraph here");
Above lines will add text to pdf file.


At the end of the PHP code we have to add $pdf->Output(); function to make our PDF file visible. Without this function our PDF file will not be generated and printed to the screen.
Well hope you guys got some basic knowledge about generating a PDF file using PHP.
Comment box is open for your ideas, suggestions..
Thank You!

See you guys.. :)


Tuesday, March 31, 2015

System Development Life Cycle (part 1)



System Development Life Cycle(SDLC) is a series of steps or phases that provide a model for the development and life cycle management of an application or a software.
SDLC has 5 major steps or phases :-

  • Evolution
  • Requirement Analysis
  • System Design
  • System Implementation
  • System Testing
Evolution phase includes the identification and defining the need of a new system.
Requirement Analysis phase includes problem identification and analyzing the information need of the end users.
System Design phase includes designing or creating a blueprint with necessary hardware and software requirements.
System Implementation phase includes  creating or coding the final system.
System Testing phase includes evaluating the system's actual functionality in relation to expected functionality.

System Maintenance includes keeping the system up to date with the changes in the organization and technology and ensuring it meets the goals of the organization.


To develop a successful system these phases must be carried out in a certain manner. To full fill this requirement people built models for system development. These models eased the management of the each phase of the life cycle.
Some popular SDLC models are :-
  • Waterfall Model
  • Modified Waterfall Model
  • Iterative Model
  • Spiral Model
  • V Model
  • Big Bang Model
  • Agile Model
  • RAD Model
  • Software Prototyping
  • Incremental Model

Let's discuss some of these models in detail in the next article..!

Comment box is open for your suggestions,ideas and comments.... :)

Sunday, March 29, 2015

System Analysis and Design(SAD) - Part 2 (Types of Information Systems)



System Analysis and Design - Types of Information Systems

Well our today's topic is about Information System Types. We can divide information systems into 3 basic categories. 
  1. Operational Level Information Systems
  2. Middle Level Information Systems
  3. Top Level Information Systems

Operational Level Information Systems are used by Operational level managers and staff which will help in their decision making and making their work easier.
Middle Level Information Systems are used by Middle level managers and staff which will help them in decision making,summarizing data and creating daily,monthly and yearly reports and making their work easier.
Top Level Information Systems are used by the personals which are in the top levels of the organizational hierarchy. They use these kind of information systems to ease their decision making because the behavior and the future of the organization will depend on these decisions so the information which is provided by these kind of information systems must be reliable and accurate.



We can also categorize information systems according to their operational functionality.

  1. Transaction Processing Systems(TPS)
  2. Management Information Systems(MIS)
  3. Decision Support Systems(DSS)
  4. Executive Information Systems(EIS)
  5. Expert Systems(ES)
  6. Communication and Collaboration Systems(CCS)
  7. Office Automation Systems(OAS)

Transaction Processing Systems are designed to capture and process data about day today transactions. 

Management Information Systems are designed for management oriented reporting. These information systems generates reports based on the data which is captured from the Transaction Processing Systems.

Decision Support Systems helps to identify decision support opportunities for top level managers. It provides relevant information to help make decisions and provides its users or the top level managers with decision oriented information whenever decision making situation arises.

Executive Information Systems are also designed for the use of top level managers. These information systems will  support the planning and assessment needs of executive managers. These systems are capable of integrating of data all over the organization into a graphical indicators and controls.

Expert Systems is a programmed decision making information system. It is capable of capturing and reproduce knowledge and expertise of a human expert. It stimulates thinking of the expert. This is a best and an effective way to keep the knowledge of a human experts inside the organizations even though expert have left the organization.

Communication and Collaboration Systems helps to enable more effective  communication between workers,partners,customers and suppliers. Enhances their ability to collaborate.
Office Automation Systems supports wide range of business office activities. It provides improved workflow between workers.

If you haven't read the Introduction - Introduction to Information Systems


Well thanks for reading..Bellow comment box is open for your ideas,comments,suggestions...

Monday, March 23, 2015

Power Button එක නැතුව phone එක on කරන්න






ඔයලා දන්නවද  power button එක නැතුව කොහොමද screen එක on කරන්නේ කියලා?

මොකද කට්ටිය බයවෙලා, screen එක on කරන්න power button එක ඔබන ඔබන සැරේට power button එක කැඩෙයි කියලා. 
tongue emoticon ඒත් බයවෙන්න එපා. එහෙම power button එක ලේසියෙන් කැඩෙන්නේ නෑ. :D

ඒ කිව්වටත් හිතට හරි මදි වගේ නේ. tongue emoticon එහෙමනං මෙන්න ඒකට නියම විසදුම. Klick button එක.
මේක ඇවිල්ලා අපේ ෆෝන් එක headset පොර්ට් එකට ගහන්න පුලුවන් switch එකක්. මේක plug කරලා, මේකට අදාල app එක ෆෝන් එකට දැම්මම, ෆෝන් එක ගණන් ගන්නේ මේක button එකක් හැටියට. කොහොමද වැඩේ. නියමයි නේද?
හරි එහෙනන්. කරන විදිය මුල ඉදන්ම කියංනංකෝ.

1. මුලින්ම මේ gadget එක ebay එකෙන් ගෙන්න ගන්න. වැඩි ගානක් වෙන්නේ නෑ. රුපියල් 120ක් වගේ වෙන්නේ. හැබැයි මේක එන්නනම් සති 2ක් වගේ යනවා. එතකන් ඉවසන් ඉන්න වෙනවා. smile emoticon මෙන්න මේ link එකෙන් ගිහිල්ලා order කරන්න.

2. ඊට පස්සේ මේක ආවම playstore එකෙන් මේක run වෙන්න ඕනේ වෙන app එකක් ඩවුන්ලෝඩ් කරගන්න. හැබැයි මේකට apps ගොඩක් තියෙනවා. මං link ඔක්කොම දාන්නේ නෑ. playstore එකේ Klick කියලා සර්ච් කලාම එන apps ගොඩක් මේකට ගැලපෙනවා. එහෙම එන හොදම apps 3 link මං පහලින් දාන්නම්. මේ apps දැම්මේ නැත්තන්, ෆෝන් එක මේක detect කරන්නේ headset එකක් විදියට හොදේ.


3. ඊට පස්සේ, අර gadget එක 3.5mm පොර්ට් එකට (headset පොර්ට් එකට) plug කරලා, app එක run කරලා අපිට කරන්න ඕනේ වැඩේ ඒ app එකෙන් assign කරන්නයි තියෙන්නේ. ඊට පස්සේ ඉතින් වැඩ කරන්නයි තියෙන්නේ.
මේකෙන් අපිට ඕනේ විදියට screen එක on/off කරන්න. apps launch කරන්න. camera button එකක් හැටියට use කරන්න. තව වැඩ ගොඩාක් කරන්න පුලුවන්.
(මං පහල ෆොටෝස් දාල තියෙන්නේ මං use කරන iKey app එකේ ඒවා. ඒ app එකේනම් 3.5 පොර්ට් එකට මොකක් හරි plug කරපු ගමන්ම ඔය screenshot එකේ වගේ අහනවා headset එකක්ද, නැත්තන් මේ button එකද plug කලේ කියලා. එතකොට එතනින් තෝරලා දෙන්නයි තියෙන්නේ.






මං නම් මේකට assign කරලා තියෙන්නේ,
එකපාරක් press කලාම screen එක on/off වෙන්න,
දෙපාරක් press කලාම running apps clean වෙන්න,
ඔබාගෙනම හිටියම sound record වෙන්න)
මං මේක ටෙස්ට් කලේ android සහ windows mobiles වල විතරයි. එකෙනුත් මේක වැඩ කලේ android එකේ විතරයි. මොකද windows වලට මේ වගේ apps නෑ. මේක plug කලාම windows ෆෝන් මේක headset එකක් විදියටයි ගන්නේ.

ඇත්තම කියනවා නම් මම මේ පොස්ට් එක facebook එකෙන් copy කරගත්ත එකක්. වටිනවා කියලා හිතුන නිසයි හැමෝටම කියවන්න කියලා පොස්ට් කරේ.

මේක originally ලියුවේ Gevindu Aloka.

ප්‍රශ්න තියෙනවනම් අහන්න.

Monday, March 16, 2015

System Analysis and Design(SAD) - Part 1(Introduction to Information Systems)


System Analysis and Design - Introduction to Information Systems




Computers are now becoming part of virtual reality in every action in an organization, even in our personal lives. Every computer system consists of  six (6) basic components.
  • People
  • Interface
  • Data
  • Information Technology
  • Network
  • Process


System Stakeholders

System Stakeholder is any person who has an interest in an existing or proposed information system. Stakeholders can be divided into 5 major categories. It maybe include technical people, non-technical people and external and internal workers.

  1. System User
  2. System Owner
  3. System Builders
  4. System Designers
  5. System Analysts

System User is a person is a person who will use or affected by an information system on a regular basis in many ways.

System Owner is the person who owns the system, sponsor and advocate, set the vision and priorities,determine the policies ane responsible for the funding the project.

System Designer is a technical specialists. He can translate system user's business requirements and constraints to technical solutions. Designs the computer files, databases, inputs, outputs, user interfaces, networks and programs that will meet the user requirements.

System Builder is the person who construct, test and deliver the information system based on design specifications generated by the system designer.

System Analysts are the people understand both business and computing. Studies the problems and needs of the organization and determine how people, data, processes and information technology can best accomplish improvements for the business. 

Legacy Systems

Legacy System is an existing computer system or a application program which continues to be used because users does not want to replace of redesign it. (Antique System)
There are some potential problems in using these kind of systems.
  1. Often run on obsolete hardware which is usually slow
  2. Hard to maintain, improve and expand because there is a general lack of understanding of the system
  3. Ones who developed and designed the system may have left the organization, so there is no one to explain how it works
  4. Difficult to integrate with new systems because technology difference may occur
There are some difficulties also when upgrading or replacing these systems.
  1. The technology and the programming languages which are used in these systems may obsolete and there maybe no skilled personal to understand the system.
  2. Maybe these systems are still working fine and the processes which are done by the system are critical, so stakeholders can not afford a chance of occurring an error during the upgrading process.


Sources - University of Colombo School of Computing Teachers Notes(BIT Degree Program)



Comment box below is open for your ideas, suggestions and discussions...

Tuesday, February 17, 2015

Administrator Password Hack

අද මම අරගෙන ආවේ hacking වැඩක්. ඇත්තම කියුවොත් මේක hacking වලට වඩා back door එකක් use කරනවා කියුවොත් හරියටම හරි.

එහෙනම් අපි වැඩි කතාවට යන්නෙ නැතුව බලමු කොහොමද කරන්නෙ කියලා.


  • Step 1 - Open CMD as Administrator. 

මුලින්ම Command Prompt icon එක උඩ right click කරලා Run as Administrator select කරන්න ඔනි. එතකොට computer default admin විදියට තමයි command prompt එක run වෙන්නෙ.. අපිට මේක ඔනිම account එකක ඉදන් කරන්න පුලුවන්.




  • Step 2 - Type 'net user' in CMD
දැන් net user කියල type කරල enter කරන්න. එතකොට computer එකේ තියෙන user account list එකක් display වෙනවා.



  • Step 3 - Type 'net user ACCOUNT NAME'
මේ කියන්නෙ net user එකත් එක්ක computer එකේ තියෙන user account එකේ name එක type කරන්න කියල. මගේ computer එකේ විදියට නම් Acer1 හෝ guest. අපි Guest එක use කරමු.




  • Step 4 - To delete current password 'net user ACCOUNT NAME *'
මේ command එකෙන් ඔයාලට පුලුවන් net user list එකෙන් ආපු ඔනිම account එකක password එක replace කරන්න. අපි මගේ computer එකේ guest එක ගත්තොත් command එක එන්න ඔනි net user guest * කියලා. මේක type කරලා enter කරාම password reset කරන්න අහනවා. ඔයාලට අලුත් password එකක් ඔනි නැත්තම් නිකන්ම enter කරගෙන යන්න.



  • Step 5 - To assign a new password or change password
අපිට ඕනි නම් single command එකෙන් password එක වෙනස් කරන්නත් පුලුවන්. ඒකට use කරන්න ඔනි net user ACCOUNT NAME NEW PASSWORD command එක.
මගේ computer එකේ නම් අපිට use කරන්න වෙන්නේ guest account එකනේ. Guest account වලට password දාන්න දෙන්නේ නෑ නේ. එත් අපි කරලම බලමු.
ඔයාලට පුලුවන් වෙන ඔනිම account එකකට මේ method එක use කරන්න.


අහ්හ්..වැඩ කරා නෙ! ;)



අන්තිමටම කියන්න තියෙන දේ තමයි   අනිත් අයගෙ computer වලට හොරෙන් යන එක, password හොරෙන් ගන්න එක, hack කරන එක එහෙම හරිම නරක වැඩ. (මම නම් ඕවා මුකුත් දන්නෙ නෑ. ;) :p )

ඔයාලගෙ computer එකෙ password එක අමතක වෙලා log වෙන්න බැරි වුනාම විතරක් වගේ මේවා use කරන්න.


අහ්හ්..අමතක වුනා නෙ කියන්න, මේ  method එක හරියන්නෙ Windows Operating  System  එකට විතරයි.



එහෙනම් see you with the next tutorial.. :)