Skip to main content

4 posts tagged with "PHP"

View All Tags

Installing XAMPP on Windows 10

· 3 min read

Installing XAMPP on Windows 10

XAMPP enables you to quickly and easily setup a fully functional local web server environment on your Windows 10 computer. This is useful if you often develop websites and web applications, as you can then do all your development work in the same environment as your public website.

Installing XAMPP is a straightforward process and can be done in just a few simple steps. We’ll take you through each step so you can get your local environment up and running in no time.

What You Will Need

Before you can install XAMPP on your computer, there are a few things you’ll need to make sure you have first. Here is a quick checklist of what you’ll need:

• A computer running Windows 10 • At least 100 MB of free space on your hard drive (the more, the better) • A functioning internet connection • An administrator account on the computer • An internet browser, such as Firefox or Chrome

Downloading XAMPP

The first step in setting up XAMPP is to download it from the official Apache Friends website. To do this, go to the download page on the official website and select the appropriate version for your computer; this should be the “Windows 10” version. Once you have downloaded the file, the next step is to open the installation wizard to start the installation process.

Installing XAMPP

To start the installation process, double-click on the installation wizard that you have just downloaded. This should open the installation window, which will ask you to specify the folder where you wish to install XAMPP. You can choose any folder you want, as it doesn’t matter exactly where XAMPP is installed.

After selecting the folder, the next step is to select the components you wish to install. XAMPP includes numerous components, all of which can be selected individually. But if you are new to XAMPP, it is recommended that you select the “Standard” installation, which will install the core components that are most commonly used.

Once you have selected the components, click “Next” to proceed with the installation. You may be asked to confirm that you are an Administrator on the computer. If so, click “Yes” to continue.

At this point, the installation wizard will start the installation process and you will see the progress as it extracts and installs the components. Once the installation is finished, click “Finish” to complete the process.

Testing your Installation

After you have completed the installation process, you can test that it was done correctly by means of a simple test. Open up a browser of your choice (we recommend Firefox or Chrome) and go to http://localhost/ in the address bar. If everything is set up correctly, you should see the XAMPP splash page, which means that your installation was successful.

At this point, you are free to start developing websites and web applications on your local machine. You can also install additional components with relative ease, such as databases and web servers.

So there you have it – a quick and easy guide to installing XAMPP on your Windows 10 computer. Now you can start developing websites and web applications without needing to set up an external hosting service.

PHP learning roadmap

· 2 min read

<div class="markdown prose w-full break-words dark:prose-invert dark"> <p>PHP learning roadmap:

</p><ol><li><strong>Start with the basics</strong>:</li></ol><ul><li>Learn the basic syntax of PHP, including data types, variables, loops, and control structures</li><li>Practice writing small programs to get a feel for how PHP works</li><li>Understand how PHP code is executed on the server</li></ul><ol start="2"><li><strong>Learn how to work with forms</strong>:</li></ol><ul><li>Learn how to use $_GET and $_POST to retrieve data from forms</li><li>Understand how to validate user input to prevent malicious attacks</li><li>Learn how to handle form submissions and redirections</li></ul><ol start="3"><li><strong>Learn about functions</strong>:</li></ol><ul><li>Learn how to use built-in PHP functions for working with strings, arrays, and other data types</li><li>Understand how to create your own custom functions</li><li>Learn about passing parameters and returning values</li></ul><ol start="4"><li><strong>Learn about object-oriented programming</strong>:</li></ol><ul><li>Learn about classes, objects, inheritance, and polymorphism</li><li>Understand how to use constructors and destructors</li><li>Learn about visibility and scope</li></ul><ol start="5"><li><strong>Learn how to work with databases</strong>:</li></ol><ul><li>Learn how to connect to databases using PDO or mysqli</li><li>Understand how to use SQL to retrieve and update data</li><li>Learn about database normalization and how to use transactions</li></ul><ol start="6"><li><strong>Practice building real-world projects</strong>:</li></ol><ul><li>Practice building more complex projects, such as a simple blog or a basic e-commerce website</li><li>Learn how to use templates and frameworks</li><li>Understand how to debug and troubleshoot your code</li></ul><ol start="7"><li><strong>Learn about security</strong>:</li></ol><ul><li>Learn about common security vulnerabilities and how to prevent them</li><li>Understand how to use prepared statements and how to prevent SQL injection attacks</li><li>Learn about authentication and authorization</li></ul><ol start="8"><li><strong>Stay up to date with the latest developments</strong>:</li></ol><ul><li>Follow PHP development blogs and participate in online communities to stay current</li><li>Learn about new libraries and frameworks</li><li>Understand new features and best practices</li></ul><ol start="9"><li><strong>Deploy your application</strong>:</li></ol><ul><li>Learn how to deploy PHP applications to a web server</li><li>Understand how to troubleshoot common deployment issues</li><li>Learn about scaling and performance optimization</li></ul><ol start="10"><li><strong>Keep learning and building</strong>:</li></ol><ul><li>Keep learning new features and libraries</li><li>Keep building and experimenting with new projects</li><li>Stay updated with latest trends and best practices.</li></ul></div>

Object Oriented PHP Programming A Beginner's Guide

· 6 min read

Introduction

Hey there, future Object Oriented PHP programmer! Do you want to learn all the fundamentals of OOP in PHP? Well, you've come to the right place. In this post, we'll cover classes, inheritance and encapsulation – the three core concepts of OOP.

But don't worry – we won't be going too deep into the theoretical concepts. Instead, we'll focus on showing you how to apply these concepts in a real-world programming context. With that said, let's get started!

Overview of Object Oriented Programming (OOP)

Let's face it, we all like to be organized. It just makes life a little less messy. Well, the same can be said for our computer programs – especially when it comes to Object Oriented Programming (OOP).

In OOP, we break our programs down into classes, which helps us keep our code neat and tidy. We can also use these classes to create objects, which act as containers for data and code. This makes our programs more efficient and easier to manage.

Plus, OOP makes it easy to reuse code, which is a real lifesaver when it comes to programming. So the next time you're feeling overwhelmed by your code, try using some OOP principles – it just might make your life a little less chaotic.

Understanding Classes in PHP

Classes are one of the fundamentals of object-oriented programming. In PHP, a class is a template for creating objects. It is a blueprint from which you can create an object.

A class contains the code that defines the data and behavior of an object. In other words, a class sets the rules for how an object should behave. It also defines the characteristics of an object, such as its data members (variables) and methods.

In this example, we will create a class for storing information about cars. The class will contain the data members (variables) and methods needed to store and retrieve information about cars.

Taking Advantage of Inheritance

When I was first learning about object oriented programming, I thought classes were a bit like castes in India. You were born into a specific class, and that's where you stayed for the rest of your life. But it turns out, classes in object oriented programming are more like families. You can create new classes that inherit the properties of older classes, and you can add your own methods and properties to those classes.

Inheritance is a powerful tool that you can use to create complex systems with just a few lines of code. For example, imagine you're creating a program that calculates the average score for a test. You could create a class called "Score" that contains all the properties (e.g. score, name, date) for a single score. But what if you want to calculate the average score for several different tests? You could create a new class called "AvgScore" that inherits from "Score", and then add a method called "average()" that calculates the average score for all the scores in the "AvgScore" class.

Exploring Encapsulation in OOP

I explore encapsulation in Object Oriented Programming by taking a closer look at an example in PHP, where all of the methods and properties are contained within a class, making it more secure and organized.

By using encapsulation, I am able to hide the details of my class from the rest of the program. It's the same concept that I use when going out – if I want to keep people from knowing how much I had to drink, then I'll use my own built-in container – AKA, myself – to hide it.

It's not only about security and organization, though – encapsulation also makes it easier for me to debug and maintain my program as a whole. And when it comes to writing code, being able to debug quickly is key.

Practicing Polymorphism

Before we get too deep into polymorphism, we need an example. Imagine a company of robots and humans working together in a web development shop. They all have their own unique capabilities, but the main goal is to produce the same kind of output: a functioning website.

In this case, polymorphism can be used to create a single interface for both the robots and humans that treat them as if they were the same type of coder – even though they’re not. This means that when you call certain methods, the correct ones will be executed depending on who’s receiving the call.

With our PHP skills in place, it’s time to practice polymorphism in an actual codebase! We can make sure that our code isn’t dependent on a specific type of coder (robot or human) by having classes that are interchangeable and easily extendable by each other.

Tips for Object Oriented PHP Programming

As I quickly found out when delving into object oriented PHP programming, there's more to it than just classes, inheritance and encapsulation. To be successful in your OOP endeavors, it's important to create a programmatic style with consistent formatting and structure. Think of it like writing an essay – having a structure helps you stay on track and find the information you need quickly.

Also take the time to document your code as you go along; this will help your future self understand the code much faster than if you had to start from scratch. And lastly, if you run into trouble, don't be afraid to ask for help – that's why the internet was invented! Just remember, you don't have to figure out everything by yourself.

Conclusion

So, those are the three core concepts of Object Oriented Programming with PHP: classes, inheritance, and encapsulation. It's a lot to take in, but with a little practice, you'll be able to create classes and objects like a pro!

Remember, inheritance enables you to create classes that are based on other classes, while encapsulation allows you to hide the details of a class from the outside world. And polymorphism lets you treat objects of different classes in the same way, thanks to their common ancestor.

With these basics under your belt, you're ready to start creating your own Object Oriented PHP programs!

So there you have it! A brief introduction to the four pillars of OOP. Remember, learning to code can be a lot of fun, especially when you're learning with bcahngu.live. Happy coding!

How To Send Mail From Localhost XAMPP Using PHP

· 3 min read

How To Send Mail From Localhost XAMPP Using PHP.

To send mail from localhost XAMPP using Gmail, configure XAMPP after installing it.

Steps to Send Mail From Localhost XAMPP Using Gmail:

Open XAMPP Installation Directory.

  • Go to C:\xampp\php and open the php.ini file.
  • Find [mail function] by pressing ctrl + f
  • Search and pass the following values:
php.ini
SMTP=smtp.gmail.com

smtp_port=587

sendmail_from = YourGmailId@gmail.com

sendmail_path = "C:\xampp\sendmail\sendmail.exe\"

Sign in with App Passwords to generate an app password for your account.

  • Go to Google Account and sign in with your Gmail account, Make sure you are signed in with the same account you want to generate the app password for and Turn on 2-Step Verification.
  • Under Select app, choose the app you want to generate the app password for. For example, Mail, Chrome, or Calendar.
  • Select the mail and device you want to generate the app password for.
  • Click Generate. You’ll see a 16-character app password. Copy it to your clipboard or write it down somewhere safe.
  • Click Done.

Now, go to C:\xampp\sendmail and open the sendmail.ini file.

Find [sendmail] by pressing ctrl + f Search and pass the following values

sendmail.ini
smtp_server=smtp.gmail.com

smtp_port=587 or 25 //use any of them

error_logfile=error.log

debug_logfile=debug.log

auth_username=yourgmail@gmail.com

auth_password= Paste the app password here

force_sender=YourGmailId@gmail.com(optional)

Now create a php file and paste the following code in it.

sendmail.php
<?php
$to_email = "receipient@gmail.com";
$subject = "Simple Email Test via PHP";
$body = "Hi, This is test email send by PHP Script";
$headers = "From: sender email";

if (mail($to_email, $subject, $body, $headers)) {
echo "Email successfully sent to $to_email...";
} else {
echo "Email sending failed...";
}

Now run the php file in your browser.

If you are using XAMPP, then run the php file in your browser by typing localhost/sendmail.php in the address bar.

Possible Errors and Solutions

  • If you are getting the error SMTP Error: Could not authenticate. then you have to generate an app password for your Gmail account. Go to https://myaccount.google.com/apppasswords and generate an app password for your Gmail account and paste it in the sendmail.ini file.

  • If you are getting the error SMTP Error: Could not connect to SMTP host. then you have to change the port number in the sendmail.ini file. Change the port number from 587 to 25 or vice versa.

Conclusion

In this article, we have learned how to send mail from localhost XAMPP using Gmail. We have also learned how to generate an app password for your Gmail account.

References