Trending December 2023 # Why Do We Use Filter In Php? # Suggested January 2024 # Top 21 Popular

You are reading the article Why Do We Use Filter In Php? updated in December 2023 on the website We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested January 2024 Why Do We Use Filter In Php?

Introduction to PHP Filters

There are very few languages that have filter features. Filters are one of the value-added features of programming languages. This helps us to filter the data or the string before processing. This is the call of the time to use this to prevent some vulnerability issues in the system. PHP filters can be used to validate or sanitize external inputs. The PHP filter is an extension with various functions and features we can use while coding. For example, if we take client input from a form as an email id, we should validate or sanitize it before database-related operation. As coders or developers, we should use these filters in PHP per our business needs and requirements.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others


Sanitizing and filters are the most common operations in the web application environment. Here is the basic syntax:

filter_var(variable, filter, options)

This function filter_var takes 3 parameters. The last 2 parameters, the filter and the options are optional. The first one is a variable or the identifier itself. This is the one, we want to filter, the second is what we want to do (in this, we pass the ID of the available options in PHP), and the last is the filter-related options. Let’s understand the same with a quiz example:

<?php $int_val = 200; if(filter_var($int_val, FILTER_VALIDATE_INT)){ } else{ }

In the above example, we are using a filter and checking whether we have an integer value in the variable $int_val. So, here is the output for the same.


Why do we Use Filter in PHP?

Many PHP web applications receive external input from the client side. The idea is to clean the user input before processing, as we can’t expect the user to put all the data correctly. Any external user or system input or data can lead to a critical security issue.

We can filter here to sanitize the data entered from the various external sources like:

Direct client user input from the form

Data of Cookies

Data from the Web services

Data of the server variables

Database query results

Together, PHP filters and sanitizers enable us to get whether an input is valid. If not a valid input, in this case, we can sanitize that to make a valid one. In the coming example section, we will discuss various examples related to this.

Examples of Filters in PHP

There are various types of filters available in PHP. We can check that list using the filter_list() function. These functions filter the URL, String, number, IP address, etc.

Example #1

In this section, we will see the various filter example programs individually.

Sanitize a String

To check whether a string is valid or not


<?php } else{ }

In the above example, we can see a valid string; that’s why it gives the valid one.


Get the sanitized string as an output



Example #2

Validate an IP Address

The PHP filter function can do this job for us. Let’s see the example.


<?php $ip_address = ""; if(filter_var($ip_address, FILTER_VALIDATE_IP)){ } else{ }


Example #3

Sanitizing and validating an email address


<?php if(filter_var($email_address, FILTER_VALIDATE_EMAIL)){ } else{ } echo "After Sanitizing: " .  filter_var($email_address, FILTER_SANITIZE_EMAIL);

In the above example, we have an invalid email id value, as we get this output by using the filter function. But the moment we sanitize, it gives the correct email.



<?php $email_address = "[email protected]"; if(filter_var($email_address, FILTER_VALIDATE_EMAIL)){ } else{ }

In the above example PHP code, we check whether the email is valid.


Example #4

Sanitize and Validate the URL

In this example, we will see whether an input URL is valid. If not a valid URL, it will sanitize that to correct it.


<?php if(filter_var($URL, FILTER_VALIDATE_URL)){ } else{ } echo "After Sanitizing: " . filter_var($URL, FILTER_SANITIZE_URL);



We should use the PHP filter to validate or sanitize the user input. This way, we can restrict vulnerable user input. We can use the various PHP filter function for validating the user inputs and the value. We can also use sanitizing to clean the value (either the user input or the directly assigned). We should always use the PHP sanitizer before using any cookies data for the data processing.

Recommended Articles

This has been a guide to PHP Filters. Here we have discussed the basic concept, why do we use Filter in PHP? and examples. You may also have a look at the following articles to learn more–

You're reading Why Do We Use Filter In Php?

Why Do We Use Su – And Not Just Su


The Linux operating system is a powerful tool that offers a wide range of features and functionalities to its users. One of most common tasks performed by system administrators on Linux systems is to switch to root user account using su command. However, in some cases, it is recommended to use su – instead of just su. In this article, we will explore reasons behind using su – and provide examples of how it can be beneficial.

What is difference between su and su –?

The su command is used to switch to another user account on system, typically root account. When you type su followed by name of user you want to switch to, system prompts you for password of that user. Once you enter correct password, you are granted access to that user’s account.

The su – command, on other hand, not only switches to target user account but also creates a new shell environment with that user’s environment variables. This means that any changes made to environment variables, such as PATH or HOME, will be applied to new shell.

Why use su – instead of just su?

There are several reasons why using su – can be more beneficial than just su. Let’s explore some of these reasons below.

Environment Variables

As mentioned above, su – creates a new shell environment with target user’s environment variables. This is useful if you need to run commands that rely on specific environment variables. For example, let’s say you need to run a command that is located in a directory that is not in system’s PATH variable. If you just use su, command will not be found because PATH variable has not been updated to include directory. However, if you use su –, new shell environment will have updated PATH variable, and command will be found.

Home Directory

When you use su –, new shell environment will have target user’s home directory as its current working directory. This can be useful if you need to perform operations that require access to target user’s home directory. For example, if you need to edit a file that is located in target user’s home directory, it is easier to just use su – and have home directory already set as current working directory.

Resource Allocation

When you use su –, new shell environment will also have target user’s resource limits and ulimit values. This can be useful if you need to run a command that requires more resources than current user account is allowed. For example, if you need to run a process that requires more open files than current user account is allowed, you can use su – to switch to root account and have access to more resources.


Let’s take a look at some examples of when using su – can be more beneficial than just su.

Example 1: Running a command with updated environment variables

Suppose you need to run a command that is located in a directory that is not in system’s PATH variable. If you just use su, command will not be found because PATH variable has not been updated to include directory. However, if you use su –, new shell environment will have updated PATH variable, and command will be found.

To illustrate this, let’s say you have a command called mycommand located in directory /opt/myapp/bin. If you just use su, you will not be able to run command because system’s PATH variable does not include directory /opt/myapp/bin. However, if you use su –, new shell environment will have updated PATH variable, and you can run command like this −

su - root password: mycommand Example 2: Accessing a file in target user’s home directory

Suppose you need to edit a file that is located in target user’s home directory. It is easier to just use su – and have home directory already set as current working directory.

To illustrate this, let’s say you need to edit a file called chúng tôi that is located in home directory of user ‘user1’. If you just use su, you will be switched to ‘user1’ account, but current working directory will be same as previous user’s working directory. However, if you use su –, new shell environment will have ‘user1’ home directory as current working directory, and you can edit file like this −

su - user1 password: cd ~ vi myconfig.txt Example 3: Running a process with more resources

Suppose you need to run a process that requires more resources than current user account is allowed. You can use su – to switch to root account and have access to more resources.

To illustrate this, let’s say you need to run a process that requires more open files than current user account is allowed. If you just use su, you will be switched to root account, but resource limits and ulimit values will be same as previous user’s account. However, if you use su –, new shell environment will have root account’s resource limits and ulimit values, and you can run process like this −

su - password: ulimit -n 5000 myprocess Best Practices for Using su

While su – can be very useful, it is important to be careful when using it. Here are some best practices to follow when using su – 

Use su – only when necessary − While su – can be helpful, it is not always necessary. If you just need to run a command as root user, then using su is sufficient.

Use sudo instead of su –  In many cases, it is better to use sudo command instead of su –. sudo allows you to run a command with elevated privileges without switching to root user account.

Use su – with caution − When you use su –, you are essentially running commands as root user. This can be dangerous if you are not careful. Make sure to double-check any commands you run with su – to make sure they are safe.

Keep track of environment changes − When you use su –, environment variables can change, which can cause unexpected behavior. Be sure to keep track of any changes made to environment variables and make sure they do not cause problems.

Log out of root user account − When you are finished using root user account, be sure to log out of it. This will prevent any accidental changes from occurring while you are not paying attention.

Examples of When Not to Use su

While su – can be useful, there are times when it is better not to use it. Here are some examples of when not to use su – −

Running a simple command − If you just need to run a simple command with elevated privileges, then using su is sufficient. There is no need to use su – if you do not need to change environment variables or access root user’s home directory.

Running a command with a specific environment − If you need to run a command with a specific environment, it is better to use env command instead of su –. This allows you to set environment variables without changing user account.

Running a command that does not require elevated privileges − If command you need to run does not require elevated privileges, then using su – is unnecessary.


In conclusion, su – command is more beneficial than just su in several cases, as it creates a new shell environment with target user’s environment variables, home directory, and resource limits. This can be useful for running commands with updated environment variables, accessing files in target user’s home directory, and running processes with more resources. As a system administrator, it is essential to understand differences between su and su – and when to use each command to perform your tasks efficiently.

Why Do We Feel Cold When We Have Fever?

Have you ever noticed that despite having a fever and a higher body temperature, you frequently feel cold? Although it can be perplexing and unpleasant, this phenomenon is actually your body’s immune system’s normal reaction to an infection.

In this article, we’ll look into why having a fever makes us feel cold. It sounds strange, but your body is actually trying to speed up your recovery by making you shiver while you’re sweltering with fever.

The Fever Sensation

We have all experienced the sensation of having a fever while also shivering with chills. In fact, what appears to be an odd internal thermostat issue is your body’s attempt to fight off an infection.

Although the normal human body temperature can vary depending on age, activity level, and time of day, it is generally accepted to be 98.6 degrees F. It is important to note that most viruses and bacteria struggle to survive above this temperature.

In fact, a temperature increase of just one or two degrees can halt many invasive microorganisms in their tracks. Therefore, it makes sense that over millions of years, fever evolved as a way for the body to defend itself.

How Do Fevers Occur?

A fever is a brief rise in body temperature that’s frequently brought on by an infection. It is the body’s natural defense mechanism against dangerous organisms like viruses and bacteria. The severity of fever might vary from a slight rise in body temperature to one that reaches 103°F or higher.

Why do you Feel Colder Even When you’re Hotter?

It is a typical physiological reaction, in fact. Your body starts working extra hard to produce more heat as soon as your brain raises the set point of your internal thermostat to a higher level to combat an infection. You feel cold because your core temperature has abruptly dropped below your new “ideal” level.

When you feel cold, your body attempts to generate heat to raise your temperature by contracting your muscles, which causes you to start shivering and even shaking.

How Long do Adult Fevers and Chills Last?

Depending on the reason, a fever’s duration and any associated chills can change dramatically. A fever can occasionally only last a day with simple viral illnesses or linger for weeks or months with systemic infections. The best thing to do is to identify the cause of your fever based on other illness-related symptoms and indicators.

Colds and the flu, bronchitis, pneumonia, appendicitis, gastroenteritis, mononucleosis, ear infections, sinus infections, and urinary tract infections are just a few of the many potential causes (UTIs).

Why do we Experience Cold When we are Feverish?

The hypothalamus of the brain houses the body’s internal thermostat, which monitors when your body temperature increases as a result of fever and attempts to lower it by inducing a number of responses. The contraction of your muscles and the production of heat during shivering is one of these reactions.

Sadly, shivering also makes you feel cold despite your body’s efforts to raise your body temperature. The reason for this is that when you shiver, your body’s blood vessels constrict, reducing the amount of blood that reaches the skin’s surface. By limiting the quantity of heat loss from your body, conserves heat.

What Other Signs and Symptoms Accompany a Fever?

A fever can result in additional symptoms in addition to feeling cold, such as −


Muscle pains and joint pain


Sweating Chills

Reduced appetite

How is a Fever Treated?

The majority of fevers subside naturally as your body fights the underlying infection. There are several things you can do to help with symptom relief and feel more comfortable, though −

Rest! When you have a fever, it’s crucial to get lots of rest. Your body will be able to save energy and concentrate on battling the infection as a result.

Maintaining adequate hydration can assist to prevent dehydration and lower your risk of experiencing shivering and chilly symptoms.

Take medicine to lower your fever. Acetaminophen (Tylenol) and ibuprofen (Advil) are two over-the-counter drugs that can assist to lower fever and relieving other symptoms like headache and muscular aches.

Use cool compresses on your forehead or the back of your neck to lower your body temperature and ease headaches.

Seek medical help. If your fever is extremely high (above 103°F) or if you are experiencing other symptoms like breathing difficulties, chest pain, or confusion, you should see a doctor right away.


Experiencing coldness while having a fever is a typical immune system reaction to an infection. Your body’s natural thermostat tries to lower your body’s temperature when it increases by causing shivering, which can make you feel cold and shivery.

While your body fights off the underlying condition, staying hydrated, getting plenty of rest, and using fever-reducing medicine might help to ease your symptoms and make you feel more comfortable. If you have a high fever or other concerning symptoms, seek medical attention immediately.

Why Do We Clip Young Girls’ Wings?

By the time I had finished my surgical training, 16 years after starting medical school, only 4% of surgeons in Australia were female.

Image source: Getty Images

Don’t you want to have children? I recall many people asking when I declared my aspirations to become a surgeon in the 1980s. This was in stark contrast to the response my male colleagues, with ambitions for a surgical career, received.

Despite an almost equal gender split in medical students, this distribution did not follow through to specialty training, especially surgery. Different paths were perceived as more suitable for combining a career with parenting, more feminine, and more aligned with being a ‘good’ mother by society. This perception seems inversely related to job power, authority and remuneration. It contributes to the glass ceiling for women.

My desire to pursue my interest and passion was strong enough to overcome barriers, not follow what others wanted or expected, and chart my own course to become the first female to train in urological surgery in South Australia. All the while, feeling as if I was making a sacrifice, a compromise in my expected role of motherhood. By the time I had finished my surgical training, 16 years after starting medical school, only 4% of surgeons in Australia were female.

Fast forward 20 years, and still less than 14% of surgeons in Australia are female. Although there remains much ground to gain, The Royal Australasian College of Surgeons has prioritised efforts and policy to attract and retain female candidates, including part-time and flexible training.

Yet surgery is one example of high-paid male-dominated careers. STEM careers are higher paid and predicted to grow. Less than a third of STEM workers and only one in 5 in the space industry are women, with lower rates at senior levels. Only 4% of venture capital funding goes to solely female-founded companies in Australia.

When I embarked on my surgical training, little did I know that my career would be far from a compromise and instead present incredible opportunities to elevate my role as a mother. The ability to be self-employed created flexibility around start and finish times, time off for events like sports days, and annual leave during school holidays. My income afforded help with housework allowing free time to be filled with play and parenting activities rather than domestic duties. My level of education improved the skills I could pass on as a mother. As Queen Rania of Jordan famously said, “If you educate a woman, you educate a family”.

With time, I appreciated my career has provided skills in leadership, managing stress and sleep deprivation, business and financial literacy, years of teaching and training others, managing staff, negotiating, scientific methods, problem-solving, and public speaking, to name a few. These are all skills I have repeatedly drawn upon in my role as a mother. My self-esteem, role modelling, recognition and professional network added value to my role as a parent and gained respect from my son. I learned to replace working mother guilt with an understanding that my career made me a better parent than if I was not pursuing my dreams, and I have led by example.

I now see my career choice as an asset, not a compromise, in my role as a mother and woman. The future requires our children to live in a world of information, influence, and stressors. They will need a broad range of complex skills. For women who choose a career, our greatest achievements should not be inversely proportional to our success as mothers.

The messaging we send to young girls at an early age, that a career will be at odds with their ability to be the best mother, impacts their self-belief, dreams, and values and will clip their wings before they fly.

Samantha Pillay overcame physical limitations from congenital hip dysplasia and smashed the glass ceiling to become South Australia’s first female urological surgeon. She is a passionate businesswoman, founder, and entrepreneur and has published several books. Find out more at Home – Dr Samantha Pillay

How To Do Gender Swap Filter On Capcut?

Did you know you can change your gender in CapCut using a swap filter? Isn’t it interesting?

You can use a gender swap filter on the CapCut with the relevant templates.

To use the gender swap filter on CapCut, you need to download the CapCut app and use the template for the gender swap filter. However, before proceeding, you must install another app called FaceApp.

Continue reading the article to learn how to use the gender swap feature filter on the CapCut and why it is so popular nowadays.

Why Is A Gender Swap Filter Popular Yet Controversial?

Gender Swap filter is a feature developed for fun where a boy can change his face into a girl’s and vice-versa.

This feature is available on the applications such as Snapchat, CapCut, and TikTok. You can use this feature if you want to prank somebody.

With the popularity gaining after the intervention of this feature, it also has been gaining some sort of controversies due to a few sensitive issues.

Sometimes, it may help you to restrict yourself from being exposed. However, some controversy has been created regarding this feature.

Using a Gender Swap filter isn’t a big deal, but somewhere, swapping up the face has been taken as a mock for lots of people.

The popular gender swap challenge seems to have drawn criticism when some online users claimed that the app’s Gender Swap filter triggered gender dysphoria.

How To Do A Gender Swap Filter Using CapCut???

Before proceeding into a Gender Swap Filter, you must install the CapCut and a FaceApp.

Follow the steps below to do a Gender Swap Filter using CapCut;

A worthy face editing app such as FaceApp, Snapchat, or Portrait AI is required; you can download them from the google play store or Apple app store.

Then, upload a selfie or an already captured photo.

Next, choose the option you feel is relevant and save the picture onto the gallery.

Further, open the TikTok app on your phone and type the gender swap filter on the search bar. Lots of videos with people using this filter will pop up.

Choose a preferred video, and tap CapCut- Try this template.

If it isn’t available on your device, you can download it.

Then, edit the video similarly add music, text, etc.

Now save the created video, and post it on Tiktok.

The Bottom Line

It is worth using CapCut, a professional editing app that provides free editing filter effects for users.

Hence, it is much more fun and makes your videos more dazzling and realistic.

Continue reading to learn how to fix tiktok not showing analytics issues and bypass the tiktok ban.

Frequently Asked Questions How To Add Effects And Filters On CapCut?

You should follow a few steps to add effects and filters on CapCut as below:

You should upload wished media files from your drive, QR code, or other libraries.

Next, go for your preferred effects or filters for the video. Now you can export the special effects or filters to your video timeline.

Finally, You can export your video after saving it with its name, format, resolution and quality guidelines.

Are CapCut Video Effects Free?

Yes, CapCut Video effects are free on CapCut.

You must use a professional video editor if you want free video effects.

And, CapCut itself is a professional video editor with free video effects that provide access to your video clips, making them more lovable and exciting.

What Is A Vpn, And Why Should We Use A Vpn?

If you are like most people, you spend a lot of your time online. Finding a way to keep your identity and your personal information safe should be something you are passionate about. Failing to take cyber-security seriously can lead to a variety of problems.

What is a VPN

A VPN, or Virtual Private Network, allows you to create a secure connection to another network over the Internet. VPNs can be used to access region-restricted websites, shield your browsing activity from prying eyes on public Wi-Fi, and more.

In very simple terms, a VPN connects your PC, smartphone, or tablet to another computer (called a server) somewhere on the internet, and allows you to browse the internet using that computer’s internet connection. So if that server is in a different country, it will appear as if you are coming from that country, and you can potentially access things that you couldn’t normally.

Related: It is now time to use VPN software also for Security and Privacy.

So how does a VPN help you?

Good question! You can use a VPN to:

Hide Your IP – Your original IP address will be replaced with another one from the VPN network, making it impossible for third parties to track you online.

Bypass geographic restrictions on websites or streaming audio and video.

Watch streaming media like Netflix and Hulu.

Safe Online Transactions – With VPN, nobody will be able to pry into your personal conversations, browsing history or online transactions, even on public WiFis.

You can see different prices for the same ‘sit’ on a flight by choosing different countries.

Gain at least some anonymity online by hiding your true location.

Protect yourself from being logged while torrenting.

So for the summary, from all the risks online we can say that today, everybody needs a VPN.

How do you get a VPN, and Which one should you choose?

With all of the different programs out there geared towards keeping your online transactions safe, selecting the right one can be a bit difficult. For years, people have used a VPN to stay anonymous while online. Over 30 million people have used this service loyally and for good reasons.

So, how do you choose the best VPN for your Windows PC? Here are just some of the benefits that come with using a VPN.

Strict No Logs Policy

DNS and IP Leak Protection

Highest possible speed

Automatic Kill Switch

Apps for Windows, Mac, iOS, Android, Linux, Routers

Simultaneous connections on multiple devices.

Related: Which VPN is the best to buy? VPN Comparison Chart.

Easily Hide Your IP Address

The only way you are identified when surfing around online is by your internet protocol (IP) address. This is a numeric value that is assigned to your home’s network.

If you are tired of being tracked with this number, then using a VPN program is a great option. With a VPN, your IP address will be replaced with one from the VPN team.

This means you will not have to worry about third-party apps or even your internet provider knowing where you have been online. The whole idea behind the internet was to remain anonymous, which is why using a VPN is essential.

Read: Difference between VPN and Antivirus explained

VPN allows you to access Restricted Websites

Are you having trouble getting on certain websites due to censored materials or geo-restrictions?

Not being able to go to the places you want to on the internet can be downright frustrating. Failing to mask your IP address will only create more problems if you try to access these restricted sites. There are a number of internet service providers who may suspend your service if you visit or download content from restricted sites.

Make your Online Transactions safer

Most people fail to realize just how easy it is for a hacker to access their browsing history, view their online conversations and take a peek at their online transactions. If a hacker can get their hands on your IP address, it is only a matter of time before they know intimate details about your life.

Instead of leaving your personal information at risk, you can use a VPN to prevent these problems. By getting rid of your IP, you can stay protected even if you are using a public WIFI network.

These days, you can never be too careful when it comes to cyber-security, which is why using this program makes sense. The money paid for a VPN program will be worth it considering how much protection it can offer you online.

Read: What is a VPN tunnel?

You can block Malicious Content with VPN

With a VPN program on your computer, you will have no problem blocking out malicious content. Each time you access a website, this program will run it through a database to make sure it is safe.

Their dedicated database is updated constantly, which means they will be able to let you know if a website has been flagged as unsafe. The last thing you want to do is get a virus on your computer due to visiting a malicious website. You can avoid these problems by getting this program today.

Read: VPN vs GPN – Differences Explained.

Get Protection for all of your Devices

Another benefit that comes with using a VPN program is that it allows you to protect multiple devices for one price. The software can be downloaded on Windows, Mac, Android, and iOS platforms. This means that all of your personal data will be kept away from the prying eyes of hackers and third parties.

Can anyone track you if you use a VPN?

If you use a good quality VPN your web traffic and IP address cannot be tracked. But if you use a poor-quality VPN, you could still be tracked. But if you are asking for the Polivce, yes, they can track you irrespective of which VPN you are using.  If the Police get an order from the court, they collect your network information and usage logs from your ISP. The usage logs help Police track the person connected to VPN.

Will VPN stop hackers?

VPN stands for Virtual Private Network. A VPN not only hides your IP address while surfing the internet but also protects you from hackers. When you are connected to a VPN, the transfer of data is encrypted. This means your activity cannot be tracked or mishandled by third parties.

That’s it.

Update the detailed information about Why Do We Use Filter In Php? on the website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!