SEC S20W5|| Sharing resources and OOP using PHP Part -3

1000237211.png

Dear Steemians,

After four weeks of learning and discoveries about databases, SQL language, and PHP, we are pleased to invite you to participate in the SEC S20W5 competition for the fifth week, continuing this exciting journey.

In this fifth part, we will educate you on PHP, another important scripting language that is crucial for your journey as a web developer. We will teach you how to add API to your code and host your page online.



Class, Object and Constructor

Classes are very important aspects of object-oriented programming also known as OOP, the act as containers are variables that can contain a large amount of data. It is usually used as a real-life instance that has so many properties or characteristics. For example, if human beings are classes then their height, their name, their complexion, and their hobby are all their properties.

A normal variable container would not be able to contain such an amount of data which is why the OOP was introduced to help programmers work with real-life instances, just as his name implies object-oriented programming is a type of programming that is used in anything relating to object that has so many properties.

it is usually stated with the Class keyword

For example, this is the syntax to create a class.

<?php

class Football {
public $club = 'Manchester United'
public $coach 'Eric';
public $owner = 'Glazers';
?>

But living just like this would be useless to the developer or any programmer so therefore it is supposed to be called using an object which we all know is an instance of a class. Below is a syntax to create an object

A VariableName = new NameOfTheClass

Using the class above:

$Example = new Football;

echo $Example -> club . <br>;
echo $Example -> coach . <br>;
echo $Example -> owner. ;

Output would be

Manchester United
Eric
Glazers


This particular step is really too long and stressful, so developers came up with an easier way to work with a class, the easier way turned out to be a constructor.


class Football {

public $club
public $coach;
public $owner ;

// Constructor

public function __construct($club,$coach, $owner){
$this-> club = $club;
$this-> coach = $coach;
$this-> owner = $owner;
}

$Example = new Football ('Manchester United', 'Eric', 'Glazers');

$Example = new Football ('Chelsea', 'Maserca', 'Bobby');



API


Application Programming Interface is a self-explanatory terminology that acts as a middleman interface between servers and clients, for resources to be shared between servers and clients there is a need for a middleman that can properly communicate with the server and with the client to make sure everything is working perfectly.

That is to say, an application program interface is a tool that helps send requests from a client and also helps in sending back responses to the respective client who made a request. So therefore in the web ecosystem, the importance of API cannot be underestimated this is because it is vital for any successful web Project on the internet.

There are different types of API in the web ecosystem, I will be listing just a few famous ones below:
1 • Partner API:

As the name replies this type of API can only be accessed by people who have common goals or business partners, these sorts of apis are only accessed by people who have special permissions. For example, a traveling agency can set up a partner API that only an approved booking agency can access, this is because the booking agency needs constant data from the travel agent to work successfully.

2• Internal API:

This sort of API is sometimes called the private API this is because they are usually protected by an organization firewall, so, therefore, everything that goes in and goes out through that API must be within that organization. For example, Apple can have an internal API that can only be assessed by the departments inside the Apple organization.

3• Rest API:

The rest API is one of the famous and most used APIs on the internet this is because it is very simple and easy to use, its security is also good enough for basic resource-sharing activities on the internet, and it can be used to easily share data from a web page to a database, also it can be used to send form data to another web page efficiently as you can see in most e-commerce sites.

4• Public Api:

This is another popular type of API this is because it is readily available to the public most times it is usually even free to use on anywhere page, although the security is not too strong it can be said to have a moderate security feature and this is because these APIS created to be easily assessed from any part of the world.



cURL


cUrl is a very powerful tool in PHP who is because it has proven to be very helpful in the exchange of resources through HTTPS and FTP, it could be used for easy communication with different APIS or domains on the internet.

When you're trying to communicate with other devices on the internet calls can be helpful and can make your job easier and faster, they can also be used in the development of cookies for your website.

cUrl syntax

• First of all you must initialize your curl using the curl_init() syntax, as the name implies this code starts up the curl functions, that is to say, every curl activity must start with this code.

• Secondly You set the curl opinions using curl_setopt_array

//You can add more features depending on what you want to work on. In this stage of your cUrl, you are trying to create a working rule that will guide the activities while using cUrl.

• Thirdly you are to execute the curl, using curl_exec() as the name implies this is the exact state where the cUrl begins to perform its duties.

• Fourthly make sure you close your curl activities with the syntaxcurl_close(), this should be the last syntax you have because this is the closest down all the curl activities.

Note: you might need some more syntax but that will depend on the complexity of your project, the stage I give above at the basic and compulsory stage every curl must have.



hosting of our web page on the internet vs your local host

This is one of the most interesting parts because after developing so many beautiful Projects you would love it to be accessible from all over the world, there are different hosting companies that carry out such activities. But unfortunately, most of them are expensive to use while the remaining few are free with limited permissions.

What motivated me to talk about this topic was, I remember going through someone's article and the person dropped his localhost link on the post thinking I could access it from a different device but unfortunately that is impossible.

• Gives your article global visibility, which makes it easier to access from a different device.

• It gives you recognition and helps you get more visitors to your website.

• Web hosting is just storing your data in someone else's system that would rarely have downtime.

What is localhost?

As the name implies local host is a popular way in which your system works, to help developers host their sites locally. With the help of the browser and my Apache server, developers can easily view their code to check out the progress while working, these browsers and Apache servers create a local server that automatically hosts this site locally on our machines. This means that someone else with a different device can't access your web page using the local host on your browser so therefore you need to host your web page on the internet for everyone to easily view through an online server or cloud server in most cases.

• While using a local host you get unlimited resources to view your web page as you wish and when you wish.

• It's usually more secure because it can only be accessed locally, cyber threats can't easily get to this set of projects because they are hosted offline.

• It's totally free that's to say you won't be charged for using it.

• It helps developers improve their projects before hosting them globally.

Section 1: Theoretical Questions

-Object Oriented Programming: Explain in detail what Object Oriented Programming is, what they are used for and some of their use cases.

-Application Programming Interface: Write intensively on what you understand by API, Give five different examples and their use cases.

-Web Hosting Vs Local Host: Explain What you understand about local host? What do you understand by web hosting? Give five Advantages and five disadvantages of web hosting and local host.

-cUrl: Why do developers use curl, list, and explain all the use cases of curl

Section 2: Practice Questions

-Hosting: Host your sign-up page, login page, and the page we created last week on a hosting site. ( Note: Infinityfree or 000webhost host pages for free but you are free to use any site you wish )

- API : Get news data from a News API of your choice, post the news on your web page.


Contest Guidelines

Post can be written in any community or your own blog.

The post must be #steemexclusive.

Use the following title: SEC S20W5|| Sharing
resources and OOP using PHP Part -3

Participants must be verified and active users on the platform.

The post must be more than 350 words. (350 to 500 words)

The images used must be the author's own or free of copyright. (Don't forget to include the source.)

Participants should not use any bot voting services, do not engage in vote buying.

The participation schedule is between Monday, October , 7, 2024 at 00:00 UTC to Sunday, - October 13, 2024 at 23:59 UTC.

Community moderators would leave quality ratings of your articles and likely upvotes.

The publication can be in any language.

Plagiarism and use of AI is prohibited.

Participants must appropriately follow #club5050 or #club75 or #club100.

Use the tags #dynamicdevs-s20w5, #country (example- #tunisia, #Nigeria) #steemexclusive.

Use the #burnsteem25 tag only if you have set the 25% payee to @null.

Post the link to your entry in the comments section of this contest post. (very important).

Invite at least 3 friends to participate in this contest.

Strive to leave valuable feedback on other people's entries.

Share your post on Twitter and drop the link as a comment on your post.

Your article must get at least 10 upvotes and 5 valid comments to count as valid in the contest, so be sure to interact with other users' entries

Rewards

SC01/SC02 would be checking on the entire 16 participating Teaching Teams and Challengers and upvoting outstanding content. Upvote is not guaranteed for all articles. Kindly take note.

At the end of the week, we would nominate the top 5 users who had performed well in the contest and would be eligible for votes from SC01/SC02.

Important Notice: The selection of the five should be based solely on the quality of their post. Number of comments is no longer a factor to be considered.


Best Regards,
Dynamic Devs Team
@kouba01
@starrchris

Sort:  

Upvoted! Thank you for supporting witness @jswit.

@starrchris, I wish I could understand all these IPs. But apparently it's not my thing). Good luck in the competition.

😂😂, If you put interest you might understand, thank you for the good wishes 🙏🏻

I had written the theory to participate in this contest, and when I moved on to the practical part, I created an account on InfinityFree. I also created the database there, but due to some errors, my laptop reset, which caused a lot of difficulties for me, and my post remains incomplete.

I am unable to connect to the host, and the files are not connecting to the database, which is why I am sad that I won't be able to participate. I hope to start preparing in advance next week and participate in the contest then.🥲🙂

Sorry for the setback, after the contest you can forward your errors. Hopefully we will resolve them together.

Coin Marketplace

STEEM 0.19
TRX 0.18
JST 0.033
BTC 88172.86
ETH 3116.36
USDT 1.00
SBD 2.77