Monthly Archives: May 2017

How to convert string to array in JavaScript

Hi all,
Today we discuss related to important topic related to string to array convertion using javascript. When I’m doing my project I face this problem, get the values from api url using ajax, the success data is string then I can’t display the values in dropdown list. Based on this problem I found the solution: first convert the success data (string) to array values.

First we move two important topics related to this article.
The JSON.stringify and JSON.parse are very important in string to array conversion.




JSON.stringify in JavaScript

We use the Json.stringify in JavaScript to convert JavaScript object into a string.
When sending data to a web server, the data has to be a string.

Stringify a JavaScript Array

Suppose we have an variable in javascript. The variable values are array but we want to convert this array into string.

 var a = ["Kerala","Haryana","Delhi","Chandigarh","West Bengal","Uthar Pradesh"];




Use the JavaScript function JSON.stringify() to convert it into a string.

 var b=JSON.stringify(a);

The output is like:

[“Kerala”,”Haryana”,”Delhi”,”Chandigarh”,”West Bengal”,”Uthar Pradesh”]

Stringify a JavaScript Object

Suppose we have an object in javascript.




 var a = {"State":"Kerala", "District":"Ernakulam", "Pincode":674091};

Use the JavaScript function JSON.stringify() to convert it into a string.

var b = JSON.stringify(a);

The output is like:

{“State”:”Kerala”, “District”:”Ernakulam”, “Pincode”:674091}

JSON.parse()

When we receive the data from server, the data is always string.
We use JSON.parse() in javascript the string data convert to as array.




var a = JSON.parse('{ "name":"Priya", "age":13, "city":"Ernakulam"}');
document.getElementById("demo").innerHTML = a.name + ", " + a.age;

The output like:

Priya,13

String to Array in Javascript

Next we move to how to convert the array value to string and then it convert to array and finally the data is displayed in dropdown list. Are you confused?. Everybody think as normal why we convert array to string then to array, easily we can convert string array value into dropdown list. That’s cool. We can consider first array to string value or direct string values here I consider array value and convert this array values to string and then convert to array and display it into dropdownlist. This process is mainly used in ajax success result. If the value is string then we use this operation.

Full Code









Windows or Linux Hosting – Which one is better

Hi all,
This is very common questions when we plan to develop personal blog or web site hosting to our needs. In web hosting company, they provides connectivity and space to your content. Your file includes script like JavaScript, jQuery, style etc and media files like image, videos, PDF or word file etc they are resides in the hosting server and your audience are about to fetch these from this server only. While selecting a Hosting provider and OS keep in mind few things like which Scripting languages you are about to consider and what volume of data is coming , how much is the expected traffic and how often interactions and content publishing is going to happen

In web hosting there are two major types are available. They are:

  1. Windows hosting
  2. Linux hosting




Linux Hosting

From UNIX, the linux operating system is derived. The main advantages of UNIX or Linux operating system is: its open source and free to use and also most scripting languages are supported by Linux. Linux got better permission Management and Directory Security. It also support popular content management systems like WordPress, Drupal. Joomla , Vanilla are well working with Linux over Windows. And database support for Linux Includes MySQL and Postgres SQL. Linux is on the other hand Case Sensitive. Linux hosting provides cpanel, we can configure our site in cpanel.

Standard Features of Linux Hosting

  • cPanel/WHM Web Control Panel Integration.
  • Supports large variety of Linux OS such as Ubuntu, Debian, CentOS, Fedora, FreeBSD etc.
  • Full Root Access.
  • Supports Apache Web Server, Litespeed, MySQL, PHP, Perl, Python, Ruby on Rails, FFMpeg.
  • Server Protection with IP Tables Firewall.

Windows Hosting

In web hosting they are many advantages and disadvantages over Linux. Windows is the property OS of Microsoft.




The main scripting language supported by Windows are ASP and ASP.net , both are good for applications but lacks wide community support and patches like PHP , again CMS es like WordPress are not well available for ASP variants.

Windows Hosting Advantage:

  • Tons of Useful Features: Depending on the server plan, Windows hosting packages are rich in great features.
  • Regular Software Updates:Microsoft updates its operating systems and other software programs on a regular basis.
  • Highly Compatible: It is also compatible with a variety of open-source technologies, including Apache, PHP, and MySQL, which are typically found on Linux and other Unix-based servers




What is the difference between Linux and Windows hosting?

The windows and Linux are two different types of operating systems. Basically, we can say that the Linux hosting is more secure and more efficent than windows. One other difference is that Linux files are case-sensitive and Windows files are not. Both Linux and Windows offer the FTP access, but only Linux offer Telnet and SSH (secure Shell) access. The Telnet and SSH are used for manipulating files in the server. Windows support ASP, ASP.net ,C# , PHP,MSSQL ,MySQL etc. And Linux supports PHP, MySQL, Pearl, Ruby etc.

Development Tool Linux Hosting Windows hosting
Dreamweaver or other WYSIWYG apps
WordPress® or other Web apps
ASP, ASP.NET, MS SQL
PHP, MySQL, CGI, Python, or Perl
ASP, ASP.NET and PHP, MySQL

Based on security, both hosting platforms are secure. And windows is found to be good in performance when comparing to Linux , but on feature wise Linux is leading

The main difference is the operating system which is responsible for executing scripts and databases. In other words: Linux and Windows are using different script and database languages. So think in advance if you need special Windows script languages. When there’s no need for ASP. VBScript or MSSQL, Linux is the OS of choice. By the way, it doesn’t matter if your computer runs on Windows, because all computers are able to communicate with Linux or Windows servers.




Anyways It’s impossible to make a general recommendation because your choice depends on the requirements of your hosting or website project. But Linux has the advantage of working on 70% of web servers worldwide, so that might be a minor advantage.

Linux also has more of the features web designers expect, so unless you have websites which need specific Windows applications, Linux is the preferred choice.

If anyone has doubts on this topic then please do let me know by leaving comments or send me an email.

Create A Facebook Login For Your Website Using PHP

Hi all,
A web application the registration form and logins forms are implemented. But nowadays the users are not like to fill the big registration form and they not like to remember and they forget their login details like username and password in each login system. Short registration process helps to get more subscribers for your website. Based on this situation I try to develop the facebook login page integrated into our system using PHP. Everybody has the facebook account, using your existing facebook login details we can connect or login into our application with the help of facebook API system. Login with Facebook is a powerful and quick way to integrate registration and login system into the website. Facebook is the social network and everybody has the facebook account. Facebook Login allow users to sign into your website using their Facebook account credentials without sign up on your website.

In this article, I will explain how to implement user login and registration system with Facebook using PHP and store the user profile data into the MySQL database. For this purpose first, we include Facebook SDK file into our folder.




Facebook Apps Creation

To access the facebook API into our system first we create App ID & App Secret.
Follow the step-by-step guide to creating and configure a Facebook App from the App Dashboard.

    • Go to the Facebook App Dashboard and log in with your Facebook account.
    • Create a new Facebook apps with your desired name (like prittytimes-Test1)
    • If you want to test Facebook login at the localhost server, then your App Domains should be localhost. Also, localhost domain will only work, once you add platform. For add, a platform clicks on Settings links from the left side menu panel » Click on the Add Platform button » Choose Website category » Enter site URL (http://localhost/my_post/facebook_comment/facebook_login_with_php/).
    • Once you completed the above steps, your apps settings page would something like the below.






  • Now click on Status & Review link from the left side menu panel and make your apps live.
  • Congratulation! your apps creation has completed.

Database Table Creation

If you want to store the facebook user information to our MySQL database, first create users table in PHPMyAdmin with the field. And also we create the database in PHPMyAdmin, under this database we create users table. It’s very important because then only we can insert the data the specified table in MySQL database.

CREATE TABLE `users` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `oauth_provider` enum('','facebook','google','twitter') COLLATE utf8_unicode_ci NOT NULL,
 `oauth_uid` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
 `first_name` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
 `last_name` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
 `email` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
 `gender` varchar(5) COLLATE utf8_unicode_ci NOT NULL,
 `locale` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
 `picture` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
 `link` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
 `created` datetime NOT NULL,
 `modified` datetime NOT NULL,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

Facebook SDK for PHP

To include or create facebook application into our PHP code: first, we include facebook SDK into our directory.
The facebook-php-sdk/ directory contains the latest version of Facebook SDK for PHP

User Class (User.php)

The User class helps to insert or update user data into the database using PHP and MySQL. In User.php file, you only need to specify your MySQL database credentials ($dbHost, $dbUsername, $dbPassword, and $dbName) and table name ($userTbl) where you want to store the user’s Facebook profile information.


Facebook API Configuration (fbConfig.php)

In fbConfig.php page, define Facebook App ID ($appId), App Secret ($appSecret), Callback URL ($redirectURL), and Permissions ($fbPermissions) to connect with Facebook API and working with SDK.


Login & Profile Information (index.php)

When we call index.php file, if the user already logged in his the Facebook account, the profile details would be displayed, otherwise, Facebook login button will appear.

Facebook ID : ' . $userData['oauth_uid'];
        $output .= '
Name : ' . $userData['first_name'].' '.$userData['last_name'];
        $output .= '
Email : ' . $userData['email'];
        $output .= '
Gender : ' . $userData['gender'];
        $output .= '
Locale : ' . $userData['locale'];
        $output .= '
Logged in with : Facebook';
		$output .= '
Click to Visit Facebook Page';
        $output .= '
Logout from Facebook'; 
	}else{
		$output = '

Some problem occurred, please try again.

‘; } }else{ $loginURL = $helper->getLoginUrl($redirectURL, $fbPermissions); $output = ‘‘; } ?>Login with Facebook using PHP by CodexWorld

 

Login with facebook

 

Logout (logout.php)

When the user wishes to log out from their account, the logout.php file will be loaded after log out from Facebook account.


If anyone has doubts on this topic then please do let me know by leaving comments or send me an email.