Welcome to LinuxScrew

A site for Linux lovers worldwide. For newbies, system engineers, administrators, and everybody in between. We cover all things Linux, plus various programming languages, including Python, Javascript, and PHP.

View our featured tutorials and projects in the slider below or scroll down to see all recent articles.

How to Convert a USB Printer to Wireless with a Raspberry Pi
How to Use a Raspberry Pi for Digital Signage
The Worst Things You’ll Probably Google As a Programmer on Linux
How to Build a Raspberry Pi Internet Kiosk
Browsing the Internet on a 1989 Macintosh II with a Web Rendering Proxy
previous arrow
next arrow
Slider

PHP_SELF – What It Is, and Why It’s Too Dangerous to Use [WARNING]

PHP_SELF

This article outlines the PHP_SELF attribute of the $_SERVER system information variable and why you should never, ever use it. What is _$SERVER? Check out our full article on $_SERVER here – but in short, it’s a variable containing an array with information about your PHP environment – including server and request details that are quite sensitive and shouldn’t be publicly accessible. What is $_SERVER[‘PHP_SELF’] ? $_SERVER[‘PHP_SELF’] contains the full path to the PHP script being executed, including any query parameters. This allows the party making the request to include arbitrary data. Displaying data … Read more

Categories PHP

JavaScript substr() and substring() – What’s the Difference?

JavaScript substring/substr Difference

JavaScript has two similar-looking methods for extracting substrings from strings – substr() and substring(). This article explains the difference. These two functions perform almost the same function and have almost the same name, and at a glance, even seem to have the same syntax – but they’re different! Here is the syntax for each function – side by side so that you can see the difference. A Quick Reminder about Indexes An index is the integer number representing the position of an item in a series. Indexes start counting at 0 – so the … Read more

What is the $_SERVER Superglobal Variable in PHP?

PHP _SERVER

This article will explain what the $_SERVER superglobal variable is in the PHP programming language. What is a ‘Superglobal’ Variable? A superglobal variable is a variable that is available to all scripts in all scopes in PHP. It is available from within any file, class, or function. What is the $_SERVER Superglobal Variable? The $_SERVER superglobal contains information about the server and execution environment PHP is running in/on. It contains information on the request made to the web server, file paths, and other information. It will provide little to no info … Read more

Categories PHP

How to Update/Upgrade Python in Linux [Ubuntu/RedHat]

Update/Upgrade Python in Linux

This article will show you how to update Python to the latest version on your Linux Operating system. Python is updated yearly with new features and big upgrades – these are called major updates. In addition to this, monthly updates are released which fix small issues and improve security – these are called minor updates. Major updates change how Python works a bit and may break compatibility with some code as features are added or removed, whereas minor updates are solely there to fix problems without altering any functionality. Updating From Python 2 … Read more

XOR (Exclusive Or) in Python

Python XOR Exclusive Or

This article explains XOR (Exclusive Or) – what it is, why it’s used, and how to implement it in the Python programming language. What is XOR / Exclusive OR XOR – Exclusive Or – is a logical operation commonly used in computer programming. Logically, an XOR condition is true only if the supplied arguments differ. XOR compares two inputs and outputs, true or false, only if they are different. Those inputs are usually true/false boolean values or the result of a logical operation that returns a boolean value. For example, XOR on two values – 1 and 1 is false – they do not differ. XOR on two values … Read more

Calculating the Absolute Value in JavaScript with Math.abs()

JavaScript Absolute Value abs()

This article will explain what absolute values are, how they are used, and how the JavaScript Math.abs() function can be used to calculate the absolute value of a number. What is the ‘Absolute Value’ of a Number? The absolute value of a number is that number’s value – without any regard to its sign. A numbers sign determines whether it is positive or negative – it’s the – symbol before a negative number. So, the absolute value of a number is never negative. Consider the absolute value of a number that numbers distance from 0. The absolute value of … Read more

A Trick for Validating JSON in PHP

PHP Validate JSON

Here’s a quick trick for validating JSON in PHP – with a reusable function, you can copy and paste it into your own project. JSON has pretty much become the standard format for transferring data between applications on the internet. So if you’re building an API to be consumed by others or just building a backend for your app, you’ll be sending and receiving a lot of JSON data. But, you can never trust the request – the data coming into your application. Users enter bad data. Hackers deliberately enter bad … Read more

Categories PHP

Capitalize the First Letter of Each Word in a String [JavaScript]

JavaScript Capitalize First Letter

This short article shows you how to capitalize the first letter in a string or all of the words in a string (title case) in the javascript programming language. Capitalizing the first letter in a string is useful if you’re capitalizing a single word or a whole sentence which you wish to display in a grammatically correct manner. Converting a string to title case – that’s where every word is capitalized in a string with multiple words – is useful for formatting text for use in an article … Read more

Python: View Documentation With the help() Function

Python help() Function

This short article will show you how to use the Python help() function to view the documentation (Docstring) for a Python module, class, or function. Documenting Your Python Code with Docstrings You can document your Python code with a special string called a docstring. We’ve got a whole article on that here. The short version of it is this: put a triple quoted string immediately after declaring a function, class, or module in Python: “”” Just like this “”” …and you can later read from it using the help() … Read more

How to Check if an Array is Empty in JavaScript [Examples]

Check if JavaScript Array is Empty

This quick tutorial will show you how to check whether an array is empty in the JavaScript programming language. What is an Array? An array is a type of variable that holds a collection of zero or more values. In JavaScript, arrays are ordered – each value in the array has a position (called the index) in the array, which is used to access it. Indexes start counting at 0, so the first value in an array is at index 0. Declaring an Array in JavaScript The quickest way to … Read more