Javascript
Encoding
encodeURIComponent(url);
Decoding
decodeURIComponent(url);
PHP
Encoding
urlencode(url);
Decoding
... [READ MORE]Check whether request is made from Ajax – PHP
if(strtolower($_SERVER[‘HTTP_X_REQUESTED_WITH’])==’xmlhttprequest’){
echo "The request is from an Ajax Call";
}else{
echo "The request is not from an Ajax Call";
}
?>
There you go. You now know how to check whether request made to file is from an Ajax Call or not in PHP.
Add GET or POST parameters on include files in PHP
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. It will search for file.php?user=subin in the directory for the case above. You can make it work in a different way.
... [READ MORE]How to execute a PHP PDO prepared statement
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
The following example will redirect user to http://subins.hp.af.cm
Or you can use the normal Javascript :
window.location=’http://subins.hp.af.cm’;"; ?>
What’s the difference ?
header function is called in server itself not when the page reaches the browser. So no content will load, instead the client’s page will be redirected to the specified url.
Facebook Hacker Cup 2013:Beautiful Strings solution in PHP
$ip = fopen(‘input.txt‘, "r");
... [READ MORE]
$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–;
}
print("Case #".$c.": ".$max_b);
if($c < $test_cases){
print("
");
}
$c++;
}
Check whether mysqli connection is made or not in php
if ($mysqli->ping()) {
echo ("Our connection is ok!n");
} else {
printf ("Error: %sn", $mysqli->error);
}
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….
<span style="background-color: white; font-family: inherit;"><span class="kw1" style="border: 0px; color: #2060a0; line-height: 18.200000762939453px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap;">RewriteEngine</span><span style="line-height: 18.200000762939453px; white-space: nowrap;"> </span><span class="kw2" style="border: 0px; color: #2060a0; line-height: 18.200000762939453px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap;">on</span></span>
<span style="background-color: white; font-family: inherit;"><span class="kw1" style="border: 0px; color: #2060a0; line-height: 18.200000762939453px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap;">RewriteCond</span><span style="line-height: 18.200000762939453px; white-space: nowrap;"> %{REQUEST_FILENAME} !-d</span></span>
<span style="background-color: white; font-family: inherit;"><span class="kw1" style="border: 0px; color: #2060a0; line-height: 18.200000762939453px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap;">RewriteCond</span><span style="line-height: 18.200000762939453px; white-space: nowrap;"> %{REQUEST_FILENAME}.php -f</span></span>
<span style="background-color: white; font-family: inherit;"><span class="kw1" style="border: 0px; color: #2060a0; line-height: 18.200000762939453px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap;">RewriteRule</span><span style="line-height: 18.200000762939453px; white-space: nowrap;"> .* $0.php</span></span>
<span class="kw1" style="border: 0px; color: #2060a0; line-height: 18.200000762939453px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap;">RewriteCond</span><span style="line-height: 18.200000762939453px; white-space: nowrap;"> %{REQUEST_FILENAME}.php -f</span>
HTML
<span class="kw1" style="border: 0px; color: #2060a0; line-height: 18.200000762939453px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap;">RewriteCond</span><span style="line-height: 18.200000762939453px; white-space: nowrap;"> %{REQUEST_FILENAME}.html -f</span>
JSP
<span class="kw1" style="border: 0px; color: #2060a0; line-height: 18.200000762939453px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap;">RewriteCond</span><span style="line-height: 18.200000762939453px; white-space: nowrap;"> %{REQUEST_FILENAME}.jsp -f</span>
ASP
<span class="kw1" style="border: 0px; color: #2060a0; line-height: 18.200000762939453px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap;">RewriteCond</span><span style="line-height: 18.200000762939453px; white-space: nowrap;"> %{REQUEST_FILENAME}.asp -f</span>
PY
<span class="kw1" style="border: 0px; color: #2060a0; line-height: 18.200000762939453px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap;">RewriteCond</span><span style="line-height: 18.200000762939453px; white-space: nowrap;"> %{REQUEST_FILENAME}.py -f</span>
JS
<span class="kw1" style="border: 0px; color: #2060a0; line-height: 18.200000762939453px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap;">RewriteCond</span><span style="line-height: 18.200000762939453px; white-space: nowrap;"> %{REQUEST_FILENAME}.js -f</span>
<span style="color: #2060a0;">RewriteRule </span>(.*).<span style="color: red;">html</span> $1 [R=301,NC]
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.
<div>
<span style="color: red; font-family: inherit;">The table should be like this:</span>
</div>
Friendshood Update new feature – Post to Facebook
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. Wait for it.
... [READ MORE]