Posts marked with "PHP" in categories

The best method to find client’s IP Address in PHP.

This simple function will help you to find the client’s IP. You could use $_SERVER[‘REMOTE_ADDR’] , but this method will not returns the actual IP address.

To get the real IP address use this method.

function getUserIpAddr(){
    if (!empty($_SERVER[‘HTTP_CLIENT_IP’])){
        return $_SERVER[‘HTTP_CLIENT_IP’];
    }else if (!empty($_SERVER[‘HTTP_X_FORWARDED_FOR’])){
        $ite=explode(‘,’,$_SERVER[‘HTTP_X_FORWARDED_FOR’]); return str_replace(" ",",$ite[0]);
    }else{
        return $_SERVER[‘REMOTE_ADDR’];
    }
} $cip=getUserIpAddr();

... [READ MORE]

Finding Client’s IP address, Country, State, City using NetIP.de api in PHP

If you want to get client’s IP address you will use $_SERVER[‘REMOTE_ADDR’] function in PHP.
But you will not get the real IP address of the client. To get the real IP address You can use the method I used.
Also With this method you can also find the City, State, Country client’s in.
The code is pretty simple. With the help of NetIP.de it was pretty easy.

$response=@file_get_contents(‘http://www.netip.de’);if (empty($response)){throw new InvalidArgumentException("Error contacting Geo-IP-Server");}$patterns=array();$patterns["state"] = ‘#State/Region: (.*?);$patterns["IP"] = ‘#IP: (.*?) #i’;$patterns["country"] = ‘#Country: (.*?) #i’;$patterns["city"] = ‘#City: (.*?) $pattern){$ipInfo[$key] = preg_match($pattern,$response,$value) && !empty($value[1]) ? $value[1] : ‘not found’;} $uct=$ipInfo["state"];$uip=$ipInfo["IP"];$uci=$ipInfo["city"];$ipInfo=explode(‘-‘,$ipInfo["country"]);$ucs=$ipInfo[0];$uco=$ipInfo[1];

... [READ MORE]

Subins Project Online – Thanks to App Fog

You might have know the project I have been working on. The Subins Project. I have spent a year on this project. My wish was to host this on a site. But I couldn’t afford the hosting charges cause I’m 12 and my dad won’t lend me money.

I took a leave because of fever. On that day I was browsing the internet and out of nowhere I saw a post about a site named AppFog. The post said that AppFog gives free hosting on their servers under their domain name. So quickly I went to AppFog and signed up. It was pretty easy. I created my site in the domain subins.hp.af.cm.

... [READ MORE]

SQL Query in another SQL Query = SQL Subquery

You might have wanted to do a SQL query inside an another SQL query. You can do this using SQL Subquery. It’s simple as ABC. Here’s an example :

SELECT * FROM `fdposts` WHERE user IN (SELECT friend FROM `fdfriends` WHERE user=’subins2000′)

The above code will select rows in table fdposts where user is the value of friend row in the table fdfriends.
As you can see it’s very simple. Here’s another example :

SELECT * FROM `posts` WHERE user IN (SELECT name FROM `members` WHERE user=’subins2000′)

... [READ MORE]

phpMyAdmin – A software to manage MySql Database

If you want to manage your MySql table you can use a software called phpMyAdmin. You can install phpMyAdmin in any Operating Systems. This tutorial will help you to install phpMyAdmin in Linux.

<h2 id="require" style="font-family: sans-serif; max-width: 70em;">
  Requirements
</h2>

<ul style="font-family: sans-serif; margin: 1em; max-width: 70em;">
  <li style="margin-top: 0.5em;">
    <b>PHP</b> <ul style="margin: 1em 1em 0px; max-width: 70em;">
      <li style="margin-top: 0.5em;">
        You need PHP 5.2.0 or newer, with&nbsp;<tt>session</tt>&nbsp;support&nbsp;and the Standard PHP Library (SPL) extension.
      </li>
      <li style="margin-top: 0.5em;">
        To support uploading of ZIP files, you need the PHP&nbsp;<tt>zip</tt>&nbsp;extension.
      </li>
      <li style="margin-top: 0.5em;">
        For proper support of multibyte strings (eg. UTF-8, which is currently default), you should install mbstring and ctype extensions.
      </li>
      <li style="margin-top: 0.5em;">
        You need GD2 support in PHP to display inline thumbnails of JPEGs ("image/jpeg: inline") with their original aspect ratio
      </li>
      <li style="margin-top: 0.5em;">
        When using the "cookie"&nbsp;authentication method, the&nbsp;<tt>mcrypt</tt>&nbsp;extension is strongly suggested for most users and is&nbsp;<b>required</b>&nbsp;for 64–bit machines. Not using mcrypt will cause phpMyAdmin to load pages significantly slower.
      </li>
      <li style="margin-top: 0.5em;">
        To support upload progress bars.
      </li>
    </ul>
  </li>
  
  <li style="margin-top: 0.5em;">
    <b>MySQL</b>&nbsp;5.0 or newer (details);
  </li>
  <li style="margin-top: 0.5em;">
    <b>Web browser</b>&nbsp;with cookies enabled.
  </li>
</ul>
Press ALT + CTRL + T.
You will get the Terminal window.
Type the command shown below.

sudo apt-get install phpmyadmin

... [READ MORE]

Get extension of a file using PHP

This function will allow you to get a file’s extension in PHP.
function getExtension($fileName){
   $i = strrpos($fileName, ".");
   if (!$i) {
      return "";
   }
   $length = strlen($str) - $i;
   $extens = substr($str, $i+1, $length);
   return $extens;
}

For example you need to get a extension of the file photo.jpg. To get the extension type this code in your PHP file.

<span style="color: #660000;"><?php</span> <span style="color: #660000;">echo</span> getExtension<span style="color: #660000;">(</span>'<b><span style="color: #e06666;">photo.jpg</span></b>'<span style="color: #660000;">);</span> <span style="color: #660000;">?></span>

The above code will print out "jpg".

... [READ MORE]

Upload more than 1 MB file in PHP.

Some may have problem with uploading file more than 1 MB or 2 MB. You can fix this by editing the configuration file of PHP. To fix this follow the steps.

Open Root Terminal (Applications -> System Tools -> Root Terminal).
Type 

sudo gedit /etc/php5/apache2/php.ini 

and press enter key.
You will get gedit application with the php.in file.

Search for the words post_max_size upload_max_filesize.
If you found the words you will see a = after the word post_max_size upload_max_filesize.

Change the number as you want (Default will be 1M or 2M).
After editing save the file and restart Apache Web Server by opening Root Terminal and pasting this code

... [READ MORE]

Insert XML Data to MySQL Table Using PHP

This tutorial will help you to insert XML file’s contents to a MySQL Database table using php. Note- If you can’t open PHP files in browser in Ubuntu Linux See the Tutorial : http://subinsb.com/how-to-open-php-files-in-ubuntu-instead-of-downloading

This is the XML data we are going to insert in to our MySQL Table.

<pre class="prettyprint"><code>&lt;span style="font-family: inherit;">&lt;items&gt;&lt;/span>

<span style=“font-family: inherit;"> <item></span> <span style=“font-family: inherit;">  <title>Google</title></span> <span style=“font-family: inherit;">  <url>google.com</url></span> <span style=“font-family: inherit;"> </item></span> <span style=“font-family: inherit;"> <item></span> <span style=“font-family: inherit;">  <title>Google Accounts</title></span> <span style=“font-family: inherit;">  <url>accounts.google.com</url></span> <span style=“font-family: inherit;"> </item></span> <span style=“font-family: inherit;"></items> </span>

... [READ MORE]

Hide or show a div using data sent to a php file

This tutorial will help you to send data to a php file to hide a div ie sending a string to a php file to hide a div.Follow these steps.

1 : Open the php file which contains the div to hide. 
     Paste this code above the  tag

<blockquote class="tr_bq">
  <p>
    <b><style type="text/css"></b><b><span style="font-family: Times, 'Times New Roman', serif;">#<?php echo $_GET[&#8216;div&#8217;]; ?>{</span></b><b><span style="font-family: Times, 'Times New Roman', serif;"><span style="color: red;">display:none;</span></span></b><b><span style="font-family: Times, 'Times New Roman', serif;">}</span></b><b><span style="font-family: Times, 'Times New Roman', serif;"></style></span></b>
  </p>
</blockquote>

If you want to show a div change the line "display:none;" to "display:block;"

... [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