Posts marked with "PHP" in categories

Encode/Decode URL in Javascript and PHP

URL encoding and decoding can be done in both Javascript and PHP. In this post I’m going to tell you the functions used in both languages for url encoding/decoding. Javascript Encoding encodeURIComponent(url); Decoding decodeURIComponent(url); PHP Encoding urlencode(url); Decoding urldecode(url); There is an encodeURI and decodeURI function in Javascript but it won’t encode/decode the url. Note that the the word used in Javascript is URI not URL. But in PHP both are URL.... [READ MORE]

Check whether request is made from Ajax – PHP

To check whether a request has been made is from Ajax or not you can use $_SERVER[‘HTTP_X_REQUESTED_WITH’]. See the following example: There you go. You now know how to check whether request made to file is from an Ajax Call or not in PHP.... [READ MORE]

Add GET or POST parameters on include files in PHP

If you want to add GET parameters or POST parameters to files loading using include function in PHP then you should know the following: It’s not possible. But it is in a different way. If you are adding GET parameters to file name like the following, then it won’t work: The above code won’t load the file, because PHP Include function only looks for files, it won’t send any parameters.... [READ MORE]

How to execute a PHP PDO prepared statement

PDO – a method used to execute SQL statements risk free. Fast, secure and easy when compared to mysqli and mysql functions in PHP. A lot of newbies including me heard about PDO mostly in the 2010 – 2013 years when a lot of sites got hacked of Mysql Injection. PDO is the easiest and safest way to execute an SQL code, complete risk free. In this post I’m gonna tell you how to execute a prepared statement in PDO and the common mistakes made by programmers which results an error while executing SQL code.... [READ MORE]

How to redirect users to a page in PHP

If you want to redirect users to a specific page or url like when user is not logged in or something in PHP then you can accomplish this with header function or by Javascript printed by echo function. The following example will redirect user to http://subins.hp.af.cm Or you can use the normal Javascript : What’s the difference ? header function is called in server itself not when the page reaches the browser.... [READ MORE]

Facebook Hacker Cup 2013:Beautiful Strings solution in PHP

Here is the solution for FHC 2013 Beautiful Strings problem in PHP: $ip = fopen(‘input.txt‘, "r"); $test_cases = trim(fgets($ip));     $c=1;     while($c!= $test_cases+1){         $case=preg_replace(‘/[^a-z]+/’, ", strtolower(trim(fgets($ip))));         $vals=array_count_values(str_split($case));         arsort($vals);         $beauty=26;         $max_b=0;         foreach($vals as $v){             $max_b +=$v*$beauty;             $beauty–;... [READ MORE]

Check whether mysqli connection is made or not in php

This function helps to check whether connection the mysql server has been made or not. Here is the code: if ($mysqli->ping()) { echo ("Our connection is ok!n"); } else {       printf ("Error: %sn", $mysqli->error); } The $mysqli variable is a connection made via mysqli function. Know more about mysqli ping function here. ... [READ MORE]

Hide File Extensions In Browsers Using .htaccess

Many of us programmers want to hide the file extension of server files such as .php, .jsp, .py etc…. You can easily hide these extensions with the help of a .htaccess file. This feature is only available to Apache servers. Create a file named .htaccess if your root directory of site doesn’t have one. Add these lines to the .htaccess file : <span style="background-color: white; font-family: inherit;"><span class="kw1" style="border: 0px; color: #2060a0; line-height: 18.... [READ MORE]

Create Facebook Like System With jQuery, MySQL, PDO In PHP

Facebook have it’s own like system which pretty good. This post will tell you how to create a "Like system" like that of Facebook. All you have to need is jQuery, MySQL Database and PDO PHP extension. This technic is partially used in my social network, Open. See the demo there in the social network. But you have to signup. DEMO You should create a user table with users data including user id, username, password, email etc… <div> <span style="color: red; font-family: inherit;">The table should be like this:</span> </div> Let’s start by creating a likes table where we store the like actions by the user.... [READ MORE]

Friendshood Update new feature – Post to Facebook

I updated Friendshood. The new feature is that the user can post status update and photos to Facebook along with posting in Friendshood. I implemented this function using Facebook PHP SDK. You can download the SDK here. It was not quite easy. It was hard to make Picture uploading function along with the normal status update. Next I’m gonna implement twitter posting from Friendshood. I’m gonna tell you how to post a status update in the following posts.... [READ MORE]

Follow/Subscribe

Telegram 

Mastodon  Twitter

GitHub GitLab

Subdomains

Demos  Lab

Past

This blog was once on WordPress. Now a static site. See source code on

GitLab