Connecting remote server using SSH
Warning (2): key() expects parameter 1 to be array, null given [APP/Plugin/Feedback/View/Helper/RatingsHelper.php, line 73]Code Contextif (empty($model) && empty($modelClass))
{
$modelClass = key($this->models);
$data = array( 'Post' => array( 'id' => '11', 'postcategory_id' => '8', 'user_id' => '1', 'title' => 'Connecting remote server using SSH', 'body' => '<p>SSH stands for secured shall - a secured network service over an unsecured network. It is a network protocol. It provides an encrypted data communication between two computers. SSH can be used interactively to enable terminal sessions. SSH is also used in scripts to remotely and securely access data and other resources. In order to connect to remote server with SSH, you need:</p> <p>1) Server IP or domain name</p> <p>2) Username</p> <p>3) Password</p> <p>4) SSH client - I recommend PuTTY (you can easily download from internet) for windows operating system while Linux and MAC users can use OpenSSH which is mostly installed in their OS.</p> <p><strong>Useful SSH commands frequently used by developers:</strong></p> <p><em>>_ ssh <remote_host></em></p> <p><remote_host> is an IP address or domain name that you are trying to connect to. This command assumes that your username on the remote system is the same as your username on your local system.</p> <p> <em>>_ ssh remote_username@<remote_host></em></p> <p>If your username is different on the remote system. You can specify by using this syntax.</p> <p>Once you are connected to the server, you will be asked to provide a password. SSH works by connecting a client program to an SSH server. In above commands, SSH is the client program. The SSH server is at the <em>remote_host</em> that is specified.</p> <p><strong>How to configure SSH</strong></p> <p>When you change the configuration of SSH, you are changing the settings of the sshd server. In Ubuntu, the main sshd configuration file is located at <em>/etc/ssh/sshd_config</em>.</p> <p>While it is helpful to be able to log in to a remote system using passwords, it is much better idea to set up Key-based authentication.</p> <p>Key based authentication works by creating a pair of keys: <strong>a private key</strong> and <strong>a public key.</strong></p> <p>The private key is located on the client machine. The public key is placed on any server you wish to access. Please check how to generate public and private keys with PuTTY for windows and with ssh-keygen for linux and mac OS. The folder in which the private key is placed default in the windows is c:\users\<username>\.ssh while in unix based system it is under /home/<username>/.ssh</p> <p>The public key is added to a special file within the user account you will be logging into called ~/.ssh/authorized_keys</p> <p>When you attempt to connect using a key pair, the server will use the public key to create a message for the client computer that can only be read with private key.</p> <p>The client computer then sends the appropriate response back to the server and the server will know that the client is legitimate. This entire process is done in the background after keys are correctly setup.</p> <p>SSH operates on TCP port 22 by default. The server listens on port 22 though this can be changed through custom port number in <em>sshd_config</em> file.</p> <p><em>>_ ssh -p</em> <em>7322 remote_username@<remote_host></em></p> <p>If you are not connecting <em>remote host</em> at the default port 22, then you need to specify the custom port number in the command. The above command shows remote host is being connected at the port number 7322.</p> ', 'comment_count' => '0', 'postview_count' => '1161', 'active' => '1', 'created' => '2019-11-29 13:06:49', 'modified' => '2019-11-29 13:06:49', 'tags' => 'SSH, Network, Secure' ), 'User' => array( 'id' => '1', 'firstname' => 'Chirayu' ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/ssh-connect-16148-small.jpg', 'namemedium' => '/files/uploads/postimages/ssh-connect-16148-medium.jpg' ), 'Rating' => array( (int) 0 => array( 'id' => '11', 'foreign_model' => 'Post', 'foreign_id' => '11', 'author_ip' => '49.34.166.201', 'rating' => '3.5', 'created' => '2019-11-29 13:10:29' ) ), 'Tag' => array( (int) 0 => array( 'id' => '24', 'name' => 'SSH', 'keyname' => 'ssh', 'Tagged' => array( [maximum depth reached] ) ), (int) 1 => array( 'id' => '25', 'name' => 'Network', 'keyname' => 'network', 'Tagged' => array( [maximum depth reached] ) ), (int) 2 => array( 'id' => '26', 'name' => 'Secure', 'keyname' => 'secure', 'Tagged' => array( [maximum depth reached] ) ) ), 'RatingSummary' => array( 'total_votes' => (int) 1, 'total_rating' => (float) 3.5 ) ) $options = array() $model = null $modelClass = nullkey - [internal], line ?? RatingsHelper::prepareParams() - APP/Plugin/Feedback/View/Helper/RatingsHelper.php, line 73 RatingsHelper::display_for() - APP/Plugin/Feedback/View/Helper/RatingsHelper.php, line 48 include - APP/View/Posts/filter.ctp, line 30 View::_evaluate() - CORE/Cake/View/View.php, line 971 View::_render() - CORE/Cake/View/View.php, line 933 View::render() - CORE/Cake/View/View.php, line 473 Controller::render() - CORE/Cake/Controller/Controller.php, line 963 Dispatcher::_invoke() - CORE/Cake/Routing/Dispatcher.php, line 200 Dispatcher::dispatch() - CORE/Cake/Routing/Dispatcher.php, line 167 [main] - APP/webroot/index.php, line 109
Warning (2): current() expects parameter 1 to be array, null given [APP/Plugin/Feedback/View/Helper/RatingsHelper.php, line 74]Code Context{
$modelClass = key($this->models);
$model = current($this->models);
$data = array( 'Post' => array( 'id' => '11', 'postcategory_id' => '8', 'user_id' => '1', 'title' => 'Connecting remote server using SSH', 'body' => '<p>SSH stands for secured shall - a secured network service over an unsecured network. It is a network protocol. It provides an encrypted data communication between two computers. SSH can be used interactively to enable terminal sessions. SSH is also used in scripts to remotely and securely access data and other resources. In order to connect to remote server with SSH, you need:</p> <p>1) Server IP or domain name</p> <p>2) Username</p> <p>3) Password</p> <p>4) SSH client - I recommend PuTTY (you can easily download from internet) for windows operating system while Linux and MAC users can use OpenSSH which is mostly installed in their OS.</p> <p><strong>Useful SSH commands frequently used by developers:</strong></p> <p><em>>_ ssh <remote_host></em></p> <p><remote_host> is an IP address or domain name that you are trying to connect to. This command assumes that your username on the remote system is the same as your username on your local system.</p> <p> <em>>_ ssh remote_username@<remote_host></em></p> <p>If your username is different on the remote system. You can specify by using this syntax.</p> <p>Once you are connected to the server, you will be asked to provide a password. SSH works by connecting a client program to an SSH server. In above commands, SSH is the client program. The SSH server is at the <em>remote_host</em> that is specified.</p> <p><strong>How to configure SSH</strong></p> <p>When you change the configuration of SSH, you are changing the settings of the sshd server. In Ubuntu, the main sshd configuration file is located at <em>/etc/ssh/sshd_config</em>.</p> <p>While it is helpful to be able to log in to a remote system using passwords, it is much better idea to set up Key-based authentication.</p> <p>Key based authentication works by creating a pair of keys: <strong>a private key</strong> and <strong>a public key.</strong></p> <p>The private key is located on the client machine. The public key is placed on any server you wish to access. Please check how to generate public and private keys with PuTTY for windows and with ssh-keygen for linux and mac OS. The folder in which the private key is placed default in the windows is c:\users\<username>\.ssh while in unix based system it is under /home/<username>/.ssh</p> <p>The public key is added to a special file within the user account you will be logging into called ~/.ssh/authorized_keys</p> <p>When you attempt to connect using a key pair, the server will use the public key to create a message for the client computer that can only be read with private key.</p> <p>The client computer then sends the appropriate response back to the server and the server will know that the client is legitimate. This entire process is done in the background after keys are correctly setup.</p> <p>SSH operates on TCP port 22 by default. The server listens on port 22 though this can be changed through custom port number in <em>sshd_config</em> file.</p> <p><em>>_ ssh -p</em> <em>7322 remote_username@<remote_host></em></p> <p>If you are not connecting <em>remote host</em> at the default port 22, then you need to specify the custom port number in the command. The above command shows remote host is being connected at the port number 7322.</p> ', 'comment_count' => '0', 'postview_count' => '1161', 'active' => '1', 'created' => '2019-11-29 13:06:49', 'modified' => '2019-11-29 13:06:49', 'tags' => 'SSH, Network, Secure' ), 'User' => array( 'id' => '1', 'firstname' => 'Chirayu' ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/ssh-connect-16148-small.jpg', 'namemedium' => '/files/uploads/postimages/ssh-connect-16148-medium.jpg' ), 'Rating' => array( (int) 0 => array( 'id' => '11', 'foreign_model' => 'Post', 'foreign_id' => '11', 'author_ip' => '49.34.166.201', 'rating' => '3.5', 'created' => '2019-11-29 13:10:29' ) ), 'Tag' => array( (int) 0 => array( 'id' => '24', 'name' => 'SSH', 'keyname' => 'ssh', 'Tagged' => array( [maximum depth reached] ) ), (int) 1 => array( 'id' => '25', 'name' => 'Network', 'keyname' => 'network', 'Tagged' => array( [maximum depth reached] ) ), (int) 2 => array( 'id' => '26', 'name' => 'Secure', 'keyname' => 'secure', 'Tagged' => array( [maximum depth reached] ) ) ), 'RatingSummary' => array( 'total_votes' => (int) 1, 'total_rating' => (float) 3.5 ) ) $options = array() $model = null $modelClass = nullcurrent - [internal], line ?? RatingsHelper::prepareParams() - APP/Plugin/Feedback/View/Helper/RatingsHelper.php, line 74 RatingsHelper::display_for() - APP/Plugin/Feedback/View/Helper/RatingsHelper.php, line 48 include - APP/View/Posts/filter.ctp, line 30 View::_evaluate() - CORE/Cake/View/View.php, line 971 View::_render() - CORE/Cake/View/View.php, line 933 View::render() - CORE/Cake/View/View.php, line 473 Controller::render() - CORE/Cake/Controller/Controller.php, line 963 Dispatcher::_invoke() - CORE/Cake/Routing/Dispatcher.php, line 200 Dispatcher::dispatch() - CORE/Cake/Routing/Dispatcher.php, line 167 [main] - APP/webroot/index.php, line 109
Notice (8): Undefined index: [APP/Plugin/Feedback/View/Helper/RatingsHelper.php, line 81]Code Context$message_id = 'message-'.$random_id;
$values_id = 'values-'.$random_id;
$id = $data[$modelClass]['id'];
$data = array( 'Post' => array( 'id' => '11', 'postcategory_id' => '8', 'user_id' => '1', 'title' => 'Connecting remote server using SSH', 'body' => '<p>SSH stands for secured shall - a secured network service over an unsecured network. It is a network protocol. It provides an encrypted data communication between two computers. SSH can be used interactively to enable terminal sessions. SSH is also used in scripts to remotely and securely access data and other resources. In order to connect to remote server with SSH, you need:</p> <p>1) Server IP or domain name</p> <p>2) Username</p> <p>3) Password</p> <p>4) SSH client - I recommend PuTTY (you can easily download from internet) for windows operating system while Linux and MAC users can use OpenSSH which is mostly installed in their OS.</p> <p><strong>Useful SSH commands frequently used by developers:</strong></p> <p><em>>_ ssh <remote_host></em></p> <p><remote_host> is an IP address or domain name that you are trying to connect to. This command assumes that your username on the remote system is the same as your username on your local system.</p> <p> <em>>_ ssh remote_username@<remote_host></em></p> <p>If your username is different on the remote system. You can specify by using this syntax.</p> <p>Once you are connected to the server, you will be asked to provide a password. SSH works by connecting a client program to an SSH server. In above commands, SSH is the client program. The SSH server is at the <em>remote_host</em> that is specified.</p> <p><strong>How to configure SSH</strong></p> <p>When you change the configuration of SSH, you are changing the settings of the sshd server. In Ubuntu, the main sshd configuration file is located at <em>/etc/ssh/sshd_config</em>.</p> <p>While it is helpful to be able to log in to a remote system using passwords, it is much better idea to set up Key-based authentication.</p> <p>Key based authentication works by creating a pair of keys: <strong>a private key</strong> and <strong>a public key.</strong></p> <p>The private key is located on the client machine. The public key is placed on any server you wish to access. Please check how to generate public and private keys with PuTTY for windows and with ssh-keygen for linux and mac OS. The folder in which the private key is placed default in the windows is c:\users\<username>\.ssh while in unix based system it is under /home/<username>/.ssh</p> <p>The public key is added to a special file within the user account you will be logging into called ~/.ssh/authorized_keys</p> <p>When you attempt to connect using a key pair, the server will use the public key to create a message for the client computer that can only be read with private key.</p> <p>The client computer then sends the appropriate response back to the server and the server will know that the client is legitimate. This entire process is done in the background after keys are correctly setup.</p> <p>SSH operates on TCP port 22 by default. The server listens on port 22 though this can be changed through custom port number in <em>sshd_config</em> file.</p> <p><em>>_ ssh -p</em> <em>7322 remote_username@<remote_host></em></p> <p>If you are not connecting <em>remote host</em> at the default port 22, then you need to specify the custom port number in the command. The above command shows remote host is being connected at the port number 7322.</p> ', 'comment_count' => '0', 'postview_count' => '1161', 'active' => '1', 'created' => '2019-11-29 13:06:49', 'modified' => '2019-11-29 13:06:49', 'tags' => 'SSH, Network, Secure' ), 'User' => array( 'id' => '1', 'firstname' => 'Chirayu' ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/ssh-connect-16148-small.jpg', 'namemedium' => '/files/uploads/postimages/ssh-connect-16148-medium.jpg' ), 'Rating' => array( (int) 0 => array( 'id' => '11', 'foreign_model' => 'Post', 'foreign_id' => '11', 'author_ip' => '49.34.166.201', 'rating' => '3.5', 'created' => '2019-11-29 13:10:29' ) ), 'Tag' => array( (int) 0 => array( 'id' => '24', 'name' => 'SSH', 'keyname' => 'ssh', 'Tagged' => array( [maximum depth reached] ) ), (int) 1 => array( 'id' => '25', 'name' => 'Network', 'keyname' => 'network', 'Tagged' => array( [maximum depth reached] ) ), (int) 2 => array( 'id' => '26', 'name' => 'Secure', 'keyname' => 'secure', 'Tagged' => array( [maximum depth reached] ) ) ), 'RatingSummary' => array( 'total_votes' => (int) 1, 'total_rating' => (float) 3.5 ) ) $options = array() $model = null $modelClass = null $random_id = (int) 1452208407 $element_id = 'rating-1452208407' $message_id = 'message-1452208407' $values_id = 'values-1452208407'RatingsHelper::prepareParams() - APP/Plugin/Feedback/View/Helper/RatingsHelper.php, line 81 RatingsHelper::display_for() - APP/Plugin/Feedback/View/Helper/RatingsHelper.php, line 48 include - APP/View/Posts/filter.ctp, line 30 View::_evaluate() - CORE/Cake/View/View.php, line 971 View::_render() - CORE/Cake/View/View.php, line 933 View::render() - CORE/Cake/View/View.php, line 473 Controller::render() - CORE/Cake/Controller/Controller.php, line 963 Dispatcher::_invoke() - CORE/Cake/Routing/Dispatcher.php, line 200 Dispatcher::dispatch() - CORE/Cake/Routing/Dispatcher.php, line 167 [main] - APP/webroot/index.php, line 109
Notice (8): Undefined index: [APP/Plugin/Feedback/View/Elements/rating.ctp, line 59]Code ContextRating: {
foreign_model: '{$modelClass}',
foreign_id: '{$data[$modelClass]['id']}',
$viewFile = '/var/www/html/chirayuim/app/Plugin/Feedback/View/Elements/rating.ctp' $dataForView = array( 'tags' => array( (int) 0 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 1 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 2 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 3 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 4 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 5 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 6 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 7 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 8 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 9 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 10 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 11 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 12 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 13 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 14 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 15 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 16 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 17 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 18 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 19 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ) ), 'postcategories' => array( (int) 0 => array( 'Postcategory' => array( [maximum depth reached] ), 'ParentPostcategory' => array( [maximum depth reached] ), 'ChildPostcategory' => array([maximum depth reached]), 'Post' => array( [maximum depth reached] ), 'children' => array([maximum depth reached]) ), (int) 1 => array( 'Postcategory' => array( [maximum depth reached] ), 'ParentPostcategory' => array( [maximum depth reached] ), 'ChildPostcategory' => array([maximum depth reached]), 'Post' => array( [maximum depth reached] ), 'children' => array([maximum depth reached]) ), (int) 2 => array( 'Postcategory' => array( [maximum depth reached] ), 'ParentPostcategory' => array( [maximum depth reached] ), 'ChildPostcategory' => array( [maximum depth reached] ), 'Post' => array( [maximum depth reached] ), 'children' => array( [maximum depth reached] ) ), (int) 3 => array( 'Postcategory' => array( [maximum depth reached] ), 'ParentPostcategory' => array( [maximum depth reached] ), 'ChildPostcategory' => array([maximum depth reached]), 'Post' => array( [maximum depth reached] ), 'children' => array([maximum depth reached]) ) ), 'posts' => array( (int) 0 => array( 'Post' => array( [maximum depth reached] ), 'User' => array( [maximum depth reached] ), 'Postcoverimage' => array( [maximum depth reached] ), 'Rating' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), 'RatingSummary' => array( [maximum depth reached] ) ), (int) 1 => array( 'Post' => array( [maximum depth reached] ), 'User' => array( [maximum depth reached] ), 'Postcoverimage' => array( [maximum depth reached] ), 'Rating' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), 'RatingSummary' => array( [maximum depth reached] ) ), (int) 2 => array( 'Post' => array( [maximum depth reached] ), 'User' => array( [maximum depth reached] ), 'Postcoverimage' => array( [maximum depth reached] ), 'Rating' => array([maximum depth reached]), 'Tag' => array( [maximum depth reached] ) ), (int) 3 => array( 'Post' => array( [maximum depth reached] ), 'User' => array( [maximum depth reached] ), 'Postcoverimage' => array( [maximum depth reached] ), 'Rating' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), 'RatingSummary' => array( [maximum depth reached] ) ), (int) 4 => array( 'Post' => array( [maximum depth reached] ), 'User' => array( [maximum depth reached] ), 'Postcoverimage' => array( [maximum depth reached] ), 'Rating' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), 'RatingSummary' => array( [maximum depth reached] ) ) ), 'masterclass' => '', 'appposts' => array( (int) 0 => array( 'Post' => array( [maximum depth reached] ), 'Postcoverimage' => array( [maximum depth reached] ), 'Tofriend' => array([maximum depth reached]) ), (int) 1 => array( 'Post' => array( [maximum depth reached] ), 'Postcoverimage' => array( [maximum depth reached] ), 'Tofriend' => array( [maximum depth reached] ) ), (int) 2 => array( 'Post' => array( [maximum depth reached] ), 'Postcoverimage' => array( [maximum depth reached] ), 'Tofriend' => array( [maximum depth reached] ) ), (int) 3 => array( 'Post' => array( [maximum depth reached] ), 'Postcoverimage' => array( [maximum depth reached] ), 'Tofriend' => array([maximum depth reached]) ), (int) 4 => array( 'Post' => array( [maximum depth reached] ), 'Postcoverimage' => array( [maximum depth reached] ), 'Tofriend' => array([maximum depth reached]) ) ), 'regions' => array(), 'appcountries' => array( (int) 1 => 'Andorra', (int) 2 => 'United Arab Emirates', (int) 3 => 'Afghanistan', (int) 4 => 'Antigua and Barbuda', (int) 5 => 'Anguilla', (int) 6 => 'Albania', (int) 7 => 'Armenia', (int) 8 => 'Netherlands Antilles', (int) 9 => 'Angola', (int) 12 => 'Argentina', (int) 13 => 'American Samoa', (int) 14 => 'Austria', (int) 15 => 'Australia', (int) 16 => 'Aruba', (int) 17 => 'Azerbaijan', (int) 18 => 'Bosnia and Herzegovina', (int) 19 => 'Barbados', (int) 20 => 'Bangladesh', (int) 21 => 'Belgium', (int) 22 => 'Burkina Faso', (int) 23 => 'Bulgaria', (int) 24 => 'Bahrain', (int) 25 => 'Burundi', (int) 26 => 'Benin', (int) 27 => 'Bermuda', (int) 28 => 'Brunei Darussalam', (int) 29 => 'Bolivia', (int) 30 => 'Brazil', (int) 31 => 'Bahamas', (int) 32 => 'Bhutan', (int) 34 => 'Botswana', (int) 35 => 'Belarus', (int) 36 => 'Belize', (int) 37 => 'Canada', (int) 38 => 'Cocos (Keeling) Islands', (int) 40 => 'Central African Republic', (int) 41 => 'Congo', (int) 42 => 'Switzerland', (int) 43 => 'Cote D'Ivoire', (int) 44 => 'Cook Islands', (int) 45 => 'Chile', (int) 46 => 'Cameroon', (int) 47 => 'China', (int) 48 => 'Colombia', (int) 49 => 'Costa Rica', (int) 51 => 'Cuba', (int) 52 => 'Cape Verde', (int) 53 => 'Christmas Island', (int) 54 => 'Cyprus', (int) 55 => 'Czech Republic', (int) 56 => 'Germany', (int) 57 => 'Djibouti', (int) 58 => 'Denmark', (int) 59 => 'Dominica', (int) 60 => 'Dominican Republic', (int) 61 => 'Algeria', (int) 62 => 'Ecuador', (int) 63 => 'Estonia', (int) 64 => 'Egypt', (int) 65 => 'Western Sahara', (int) 66 => 'Eritrea', (int) 67 => 'Spain', (int) 68 => 'Ethiopia', (int) 70 => 'Finland', (int) 71 => 'Fiji', (int) 72 => 'Falkland Islands (Malvinas)', (int) 73 => 'Micronesia, Federated States of', (int) 74 => 'Faroe Islands', (int) 75 => 'France', (int) 77 => 'Gabon', (int) 78 => 'United Kingdom', (int) 79 => 'Grenada', (int) 80 => 'Georgia', (int) 81 => 'French Guiana', (int) 82 => 'Ghana', (int) 83 => 'Gibraltar', (int) 84 => 'Greenland', (int) 85 => 'Gambia', (int) 86 => 'Guinea', (int) 87 => 'Guadeloupe', (int) 88 => 'Equatorial Guinea', (int) 89 => 'Greece', (int) 90 => 'South Georgia and Sandwich Island', (int) 91 => 'Guatemala', (int) 93 => 'Guinea-Bissau', (int) 94 => 'Guyana', (int) 95 => 'Hong Kong', (int) 97 => 'Honduras', (int) 98 => 'Croatia', (int) 99 => 'Haiti', (int) 100 => 'Hungary', (int) 101 => 'Indonesia', (int) 102 => 'Ireland', (int) 103 => 'Israel', (int) 104 => 'India', (int) 106 => 'Iraq', (int) 107 => 'Iran, Islamic Republic of', (int) 108 => 'Iceland', (int) 109 => 'Italy', (int) 110 => 'Jamaica', (int) 111 => 'Jordan', (int) 112 => 'Japan', (int) 113 => 'Kenya', (int) 114 => 'Kyrgyzstan', (int) 115 => 'Cambodia', (int) 116 => 'Kiribati', (int) 117 => 'Comoros', (int) 118 => 'Saint Kitts and Nevis', (int) 119 => 'Korea, Democratic', (int) 120 => 'Korea, Republic of', (int) 121 => 'Kuwait', (int) 122 => 'Cayman Islands', (int) 123 => 'Kazakhstan', (int) 124 => 'Laos', (int) 125 => 'Lebanon', (int) 126 => 'Saint Lucia', (int) 127 => 'Liechtenstein', (int) 128 => 'Sri Lanka', (int) 129 => 'Liberia', (int) 130 => 'Lesotho', (int) 131 => 'Lithuania', (int) 132 => 'Luxembourg', (int) 133 => 'Latvia', (int) 134 => 'Libya', (int) 135 => 'Morocco', (int) 136 => 'Monaco', (int) 137 => 'Moldova', (int) 138 => 'Madagascar', (int) 139 => 'Marshall Islands', (int) 140 => 'Macedonia', (int) 141 => 'Mali', (int) 142 => 'Myanmar', (int) 143 => 'Mongolia', (int) 144 => 'Macau', (int) 145 => 'Northern Mariana Islands', (int) 146 => 'Martinique', (int) 147 => 'Mauritania', (int) 148 => 'Montserrat', (int) 149 => 'Malta', (int) 150 => 'Mauritius', (int) 151 => 'Maldives', (int) 152 => 'Malawi', (int) 153 => 'Mexico', (int) 154 => 'Malaysia', (int) 155 => 'Mozambique', (int) 156 => 'Namibia', (int) 157 => 'New Caledonia', (int) 158 => 'Niger', (int) 159 => 'Norfolk Island', (int) 160 => 'Nigeria', (int) 161 => 'Nicaragua', (int) 162 => 'Netherlands', (int) 163 => 'Norway', (int) 164 => 'Nepal', (int) 165 => 'Nauru', (int) 166 => 'Niue', (int) 167 => 'New Zealand', (int) 168 => 'Oman', (int) 169 => 'Panama', (int) 170 => 'Peru', (int) 171 => 'French Polynesia', (int) 172 => 'Papua New Guinea', (int) 173 => 'Philippines', (int) 174 => 'Pakistan', (int) 175 => 'Poland', (int) 176 => 'Saint Pierre and Miquelon', (int) 177 => 'Pitcairn', (int) 180 => 'Portugal', (int) 181 => 'Palau', (int) 182 => 'Paraguay', (int) 183 => 'Qatar', (int) 184 => 'Reunion', (int) 185 => 'Romania', (int) 186 => 'Russian Federation', (int) 187 => 'Rwanda', (int) 188 => 'Saudi Arabia', (int) 189 => 'Solomon Islands', (int) 190 => 'Seychelles', (int) 191 => 'Sudan', (int) 192 => 'Sweden', (int) 193 => 'Singapore', (int) 194 => 'Saint Helena', (int) 195 => 'Slovenia', (int) 196 => 'Svalbard and Jan Mayen', (int) 197 => 'Slovakia', (int) 198 => 'Sierra Leone', (int) 199 => 'San Marino', (int) 200 => 'Senegal', (int) 201 => 'Somalia', (int) 202 => 'Suriname', (int) 203 => 'Sao Tome and Principe', (int) 204 => 'El Salvador', (int) 205 => 'Syrian Arab Republic', (int) 206 => 'Swaziland', (int) 207 => 'Turks and Caicos Islands', (int) 208 => 'Chad', (int) 209 => 'French Southern Territories', (int) 210 => 'Togo', (int) 211 => 'Thailand', (int) 212 => 'Tajikistan', (int) 213 => 'Tokelau', (int) 215 => 'Turkmenistan', (int) 216 => 'Tunisia', (int) 217 => 'Tonga', (int) 218 => 'Turkey', (int) 219 => 'Trinidad and Tobago', (int) 220 => 'Tuvalu', (int) 221 => 'Taiwan', (int) 222 => 'Tanzania, United Republic', (int) 223 => 'Ukraine', (int) 224 => 'Uganda', (int) 226 => 'United States', (int) 227 => 'Uruguay', (int) 228 => 'Uzbekistan', (int) 230 => 'Saint Vincent and the Grenadines', (int) 231 => 'Venezuela', (int) 232 => 'Virgin Islands, British', (int) 233 => 'Virgin Islands, U.S.', (int) 234 => 'Vietnam', (int) 235 => 'Vanuatu', (int) 236 => 'Wallis and Futuna', (int) 237 => 'Samoa', (int) 238 => 'Yemen', (int) 239 => 'Mayotte', (int) 240 => 'South Africa', (int) 241 => 'Zambia', (int) 242 => 'Zaire', (int) 243 => 'Zimbabwe' ), 'data' => array( 'Post' => array( 'id' => '11', 'postcategory_id' => '8', 'user_id' => '1', 'title' => 'Connecting remote server using SSH', 'body' => '<p>SSH stands for secured shall - a secured network service over an unsecured network. It is a network protocol. It provides an encrypted data communication between two computers. SSH can be used interactively to enable terminal sessions. SSH is also used in scripts to remotely and securely access data and other resources. In order to connect to remote server with SSH, you need:</p> <p>1) Server IP or domain name</p> <p>2) Username</p> <p>3) Password</p> <p>4) SSH client - I recommend PuTTY (you can easily download from internet) for windows operating system while Linux and MAC users can use OpenSSH which is mostly installed in their OS.</p> <p><strong>Useful SSH commands frequently used by developers:</strong></p> <p><em>>_ ssh <remote_host></em></p> <p><remote_host> is an IP address or domain name that you are trying to connect to. This command assumes that your username on the remote system is the same as your username on your local system.</p> <p> <em>>_ ssh remote_username@<remote_host></em></p> <p>If your username is different on the remote system. You can specify by using this syntax.</p> <p>Once you are connected to the server, you will be asked to provide a password. SSH works by connecting a client program to an SSH server. In above commands, SSH is the client program. The SSH server is at the <em>remote_host</em> that is specified.</p> <p><strong>How to configure SSH</strong></p> <p>When you change the configuration of SSH, you are changing the settings of the sshd server. In Ubuntu, the main sshd configuration file is located at <em>/etc/ssh/sshd_config</em>.</p> <p>While it is helpful to be able to log in to a remote system using passwords, it is much better idea to set up Key-based authentication.</p> <p>Key based authentication works by creating a pair of keys: <strong>a private key</strong> and <strong>a public key.</strong></p> <p>The private key is located on the client machine. The public key is placed on any server you wish to access. Please check how to generate public and private keys with PuTTY for windows and with ssh-keygen for linux and mac OS. The folder in which the private key is placed default in the windows is c:\users\<username>\.ssh while in unix based system it is under /home/<username>/.ssh</p> <p>The public key is added to a special file within the user account you will be logging into called ~/.ssh/authorized_keys</p> <p>When you attempt to connect using a key pair, the server will use the public key to create a message for the client computer that can only be read with private key.</p> <p>The client computer then sends the appropriate response back to the server and the server will know that the client is legitimate. This entire process is done in the background after keys are correctly setup.</p> <p>SSH operates on TCP port 22 by default. The server listens on port 22 though this can be changed through custom port number in <em>sshd_config</em> file.</p> <p><em>>_ ssh -p</em> <em>7322 remote_username@<remote_host></em></p> <p>If you are not connecting <em>remote host</em> at the default port 22, then you need to specify the custom port number in the command. The above command shows remote host is being connected at the port number 7322.</p> ', 'comment_count' => '0', 'postview_count' => '1161', 'active' => '1', 'created' => '2019-11-29 13:06:49', 'modified' => '2019-11-29 13:06:49', 'tags' => 'SSH, Network, Secure' ), 'User' => array( 'id' => '1', 'firstname' => 'Chirayu' ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/ssh-connect-16148-small.jpg', 'namemedium' => '/files/uploads/postimages/ssh-connect-16148-medium.jpg' ), 'Rating' => array( (int) 0 => array( [maximum depth reached] ) ), 'Tag' => array( (int) 0 => array( [maximum depth reached] ), (int) 1 => array( [maximum depth reached] ), (int) 2 => array( [maximum depth reached] ) ), 'RatingSummary' => array( 'total_votes' => (int) 1, 'total_rating' => (float) 3.5 ) ), 'model' => null, 'modelClass' => null, 'submit_url' => '/feedback/ratings/add', 'element_id' => 'rating-1452208407', 'message_id' => 'message-1452208407', 'values_id' => 'values-1452208407', 'readonly' => 'false', 'value' => (float) 3.5, 'votes' => (float) 1, 'user_vote' => (int) 0 ) $tags = array( (int) 0 => array( 'Tagged' => array( 'tag_id' => '1' ), 'Tag' => array( 'id' => '1', 'identifier' => null, 'name' => 'Configuration', 'keyname' => 'configuration', 'weight' => (float) 12, 'occurrence' => '2' ), (int) 0 => array( 'occurrence' => '2' ) ), (int) 1 => array( 'Tagged' => array( 'tag_id' => '2' ), 'Tag' => array( 'id' => '2', 'identifier' => null, 'name' => 'PHP5', 'keyname' => 'php5', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 2 => array( 'Tagged' => array( 'tag_id' => '3' ), 'Tag' => array( 'id' => '3', 'identifier' => null, 'name' => 'Apache2', 'keyname' => 'apache2', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 3 => array( 'Tagged' => array( 'tag_id' => '4' ), 'Tag' => array( 'id' => '4', 'identifier' => null, 'name' => 'PHP', 'keyname' => 'php', 'weight' => (float) 20, 'occurrence' => '6' ), (int) 0 => array( 'occurrence' => '6' ) ), (int) 4 => array( 'Tagged' => array( 'tag_id' => '5' ), 'Tag' => array( 'id' => '5', 'identifier' => null, 'name' => 'Sourcecode', 'keyname' => 'sourcecode', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 5 => array( 'Tagged' => array( 'tag_id' => '6' ), 'Tag' => array( 'id' => '6', 'identifier' => null, 'name' => 'Warnings', 'keyname' => 'warnings', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 6 => array( 'Tagged' => array( 'tag_id' => '7' ), 'Tag' => array( 'id' => '7', 'identifier' => null, 'name' => 'Timezone', 'keyname' => 'timezone', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 7 => array( 'Tagged' => array( 'tag_id' => '8' ), 'Tag' => array( 'id' => '8', 'identifier' => null, 'name' => 'Linux', 'keyname' => 'linux', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 8 => array( 'Tagged' => array( 'tag_id' => '9' ), 'Tag' => array( 'id' => '9', 'identifier' => null, 'name' => 'Apache', 'keyname' => 'apache', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 9 => array( 'Tagged' => array( 'tag_id' => '10' ), 'Tag' => array( 'id' => '10', 'identifier' => null, 'name' => 'Installation', 'keyname' => 'installation', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 10 => array( 'Tagged' => array( 'tag_id' => '11' ), 'Tag' => array( 'id' => '11', 'identifier' => null, 'name' => 'Open Authentication', 'keyname' => 'openauthentication', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 11 => array( 'Tagged' => array( 'tag_id' => '12' ), 'Tag' => array( 'id' => '12', 'identifier' => null, 'name' => 'Social Network Login', 'keyname' => 'socialnetworklogin', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 12 => array( 'Tagged' => array( 'tag_id' => '13' ), 'Tag' => array( 'id' => '13', 'identifier' => null, 'name' => 'oAuth', 'keyname' => 'oauth', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 13 => array( 'Tagged' => array( 'tag_id' => '14' ), 'Tag' => array( 'id' => '14', 'identifier' => null, 'name' => 'Web Developement', 'keyname' => 'webdevelopement', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 14 => array( 'Tagged' => array( 'tag_id' => '15' ), 'Tag' => array( 'id' => '15', 'identifier' => null, 'name' => 'Security', 'keyname' => 'security', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 15 => array( 'Tagged' => array( 'tag_id' => '16' ), 'Tag' => array( 'id' => '16', 'identifier' => null, 'name' => 'Code', 'keyname' => 'code', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 16 => array( 'Tagged' => array( 'tag_id' => '17' ), 'Tag' => array( 'id' => '17', 'identifier' => null, 'name' => 'Tips', 'keyname' => 'tips', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 17 => array( 'Tagged' => array( 'tag_id' => '18' ), 'Tag' => array( 'id' => '18', 'identifier' => null, 'name' => 'CSV files', 'keyname' => 'csvfiles', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 18 => array( 'Tagged' => array( 'tag_id' => '19' ), 'Tag' => array( 'id' => '19', 'identifier' => null, 'name' => 'File content', 'keyname' => 'filecontent', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 19 => array( 'Tagged' => array( 'tag_id' => '20' ), 'Tag' => array( 'id' => '20', 'identifier' => null, 'name' => 'Software Design', 'keyname' => 'softwaredesign', 'weight' => (float) 12, 'occurrence' => '2' ), (int) 0 => array( 'occurrence' => '2' ) ) ) $postcategories = array( (int) 0 => array( 'Postcategory' => array( 'id' => '5', 'parent_id' => null, 'name' => 'PHP Configuration', 'active' => '1', 'lft' => '1', 'rght' => '2', 'created' => '2015-05-06 13:24:33', 'modified' => '2015-05-06 13:24:33' ), 'ParentPostcategory' => array( 'id' => null, 'parent_id' => null, 'name' => null, 'active' => null, 'lft' => null, 'rght' => null, 'created' => null, 'modified' => null ), 'ChildPostcategory' => array(), 'Post' => array( (int) 0 => array( [maximum depth reached] ), (int) 1 => array( [maximum depth reached] ), (int) 2 => array( [maximum depth reached] ) ), 'children' => array() ), (int) 1 => array( 'Postcategory' => array( 'id' => '6', 'parent_id' => null, 'name' => 'PHP installation', 'active' => '1', 'lft' => '3', 'rght' => '4', 'created' => '2015-05-06 13:36:53', 'modified' => '2015-05-06 13:36:53' ), 'ParentPostcategory' => array( 'id' => null, 'parent_id' => null, 'name' => null, 'active' => null, 'lft' => null, 'rght' => null, 'created' => null, 'modified' => null ), 'ChildPostcategory' => array(), 'Post' => array( (int) 0 => array( [maximum depth reached] ) ), 'children' => array() ), (int) 2 => array( 'Postcategory' => array( 'id' => '7', 'parent_id' => null, 'name' => 'Web development', 'active' => '1', 'lft' => '5', 'rght' => '8', 'created' => '2015-06-06 05:44:15', 'modified' => '2015-06-06 05:44:15' ), 'ParentPostcategory' => array( 'id' => null, 'parent_id' => null, 'name' => null, 'active' => null, 'lft' => null, 'rght' => null, 'created' => null, 'modified' => null ), 'ChildPostcategory' => array( (int) 0 => array( [maximum depth reached] ) ), 'Post' => array( (int) 0 => array( [maximum depth reached] ), (int) 1 => array( [maximum depth reached] ), (int) 2 => array( [maximum depth reached] ) ), 'children' => array( (int) 0 => array( [maximum depth reached] ) ) ), (int) 3 => array( 'Postcategory' => array( 'id' => '9', 'parent_id' => null, 'name' => 'Software Design', 'active' => '1', 'lft' => '9', 'rght' => '10', 'created' => '2017-07-12 16:27:21', 'modified' => '2017-07-12 16:27:21' ), 'ParentPostcategory' => array( 'id' => null, 'parent_id' => null, 'name' => null, 'active' => null, 'lft' => null, 'rght' => null, 'created' => null, 'modified' => null ), 'ChildPostcategory' => array(), 'Post' => array( (int) 0 => array( [maximum depth reached] ), (int) 1 => array( [maximum depth reached] ) ), 'children' => array() ) ) $posts = array( (int) 0 => array( 'Post' => array( 'id' => '11', 'postcategory_id' => '8', 'user_id' => '1', 'title' => 'Connecting remote server using SSH', 'body' => '<p>SSH stands for secured shall - a secured network service over an unsecured network. It is a network protocol. It provides an encrypted data communication between two computers. SSH can be used interactively to enable terminal sessions. SSH is also used in scripts to remotely and securely access data and other resources. In order to connect to remote server with SSH, you need:</p> <p>1) Server IP or domain name</p> <p>2) Username</p> <p>3) Password</p> <p>4) SSH client - I recommend PuTTY (you can easily download from internet) for windows operating system while Linux and MAC users can use OpenSSH which is mostly installed in their OS.</p> <p><strong>Useful SSH commands frequently used by developers:</strong></p> <p><em>>_ ssh <remote_host></em></p> <p><remote_host> is an IP address or domain name that you are trying to connect to. This command assumes that your username on the remote system is the same as your username on your local system.</p> <p> <em>>_ ssh remote_username@<remote_host></em></p> <p>If your username is different on the remote system. You can specify by using this syntax.</p> <p>Once you are connected to the server, you will be asked to provide a password. SSH works by connecting a client program to an SSH server. In above commands, SSH is the client program. The SSH server is at the <em>remote_host</em> that is specified.</p> <p><strong>How to configure SSH</strong></p> <p>When you change the configuration of SSH, you are changing the settings of the sshd server. In Ubuntu, the main sshd configuration file is located at <em>/etc/ssh/sshd_config</em>.</p> <p>While it is helpful to be able to log in to a remote system using passwords, it is much better idea to set up Key-based authentication.</p> <p>Key based authentication works by creating a pair of keys: <strong>a private key</strong> and <strong>a public key.</strong></p> <p>The private key is located on the client machine. The public key is placed on any server you wish to access. Please check how to generate public and private keys with PuTTY for windows and with ssh-keygen for linux and mac OS. The folder in which the private key is placed default in the windows is c:\users\<username>\.ssh while in unix based system it is under /home/<username>/.ssh</p> <p>The public key is added to a special file within the user account you will be logging into called ~/.ssh/authorized_keys</p> <p>When you attempt to connect using a key pair, the server will use the public key to create a message for the client computer that can only be read with private key.</p> <p>The client computer then sends the appropriate response back to the server and the server will know that the client is legitimate. This entire process is done in the background after keys are correctly setup.</p> <p>SSH operates on TCP port 22 by default. The server listens on port 22 though this can be changed through custom port number in <em>sshd_config</em> file.</p> <p><em>>_ ssh -p</em> <em>7322 remote_username@<remote_host></em></p> <p>If you are not connecting <em>remote host</em> at the default port 22, then you need to specify the custom port number in the command. The above command shows remote host is being connected at the port number 7322.</p> ', 'comment_count' => '0', 'postview_count' => '1161', 'active' => '1', 'created' => '2019-11-29 13:06:49', 'modified' => '2019-11-29 13:06:49', 'tags' => 'SSH, Network, Secure' ), 'User' => array( 'id' => '1', 'firstname' => 'Chirayu' ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/ssh-connect-16148-small.jpg', 'namemedium' => '/files/uploads/postimages/ssh-connect-16148-medium.jpg' ), 'Rating' => array( (int) 0 => array( [maximum depth reached] ) ), 'Tag' => array( (int) 0 => array( [maximum depth reached] ), (int) 1 => array( [maximum depth reached] ), (int) 2 => array( [maximum depth reached] ) ), 'RatingSummary' => array( 'total_votes' => (int) 1, 'total_rating' => (float) 3.5 ) ), (int) 1 => array( 'Post' => array( 'id' => '8', 'postcategory_id' => '7', 'user_id' => '0', 'title' => 'CSV files data into php array to store in MySql', 'body' => '<p><strong><em>What are CSV files?</em></strong></p> <p>A CSV (Comma Separated Values) files are text files, allows data to be saved in a structured format. CSV files can be used with Microsoft Excel, Google Spreadsheets or Open Office Calc kind of tools. These CSV files are saved with .csv extension. In CSV files data fields are usually separated by comma as delimiter, but can also use a tab or pipe symbol instead of comma. CSV files are used to import and export data from application to application. Mostly, the first record is a header containing a list of field names. Any programming language has technique to import and export data from and to database like MS-SQL, MySql, PostGres, etc..</p> <p>PHP is one of the best programming languages for import and export of the data with the database to and from flat files like CSV files.</p> <p><strong><em>Fetching the data from the CSV file</em></strong></p> <p>Open the file in the read mode and store the content into variable. We assume that the CSV file contains the information about the contacts having fields firstname, lastname, email, and phone exported and the file name is contacts.csv.</p> <p>$csvfilehandle = fopen("contacts.csv","r");</p> <p>Here $csvfilehandle is file pointer to a file "contacts.csv" successfully opened</p> <p>while (($line = fgetcsv($csvfilehandle,1000,',','"'))!==false){</p> <p> $data[] = $line;</p> <p>}</p> <p>Close the opened file handle with </p> <p>fclose($csvfilehandle);</p> <p>The first argument $csvfilehandle is the mandatory arguments and remaining are optional.</p> <p>1000 is a length of characters per line to be set. This should be greater than the longest line in the file. If you are not sure about the length then don`t specify it.</p> <p>',' comma is a delimiter you can set or according to the data in the file the delimiter is used.</p> <p>'"' is the enclosure in the file used for the field value</p> <p>Now you have all the data of the CSV file into the array $data. If you print this with print_r($data); you get values into array.</p> <p><strong><em>Importing data into MySQL table</em></strong></p> <p>Now to import the data into the MySQL table named contacts, we need to modify the above wile loop. Let`s do that now.</p> <p>while (($line = fgetcsv($csvfilehandle,1000,',','"'))!==false){ </p> <p> mysql_query("insert into contacts(</p> <p> firstname, lastname, email, telephone</p> <p> )VALUES(</p> <p> '".mysql_real_escape_string($line[0])."',</p> <p> '".mysql_real_escape_string($line[1])."',</p> <p> '".mysql_real_escape_string($line[2])."',</p> <p> '".mysql_real_escape_string($line[3])."'</p> <p> )")</p> <p>or die(mysql_error());</p> <p>}</p> <p>fclose($csvfilehandle);</p> <p>Write me back if you are working for such functionality and not getting through the code.</p> ', 'comment_count' => '1', 'postview_count' => '1540', 'active' => '1', 'created' => '2016-11-03 07:17:48', 'modified' => '2019-11-21 06:00:03', 'tags' => 'PHP, CSV files, File content' ), 'User' => array( 'id' => null, 'firstname' => null ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/csv-files-data-into-88773-small.png', 'namemedium' => '/files/uploads/postimages/csv-files-data-into-88773-medium.png' ), 'Rating' => array( (int) 0 => array( [maximum depth reached] ) ), 'Tag' => array( (int) 0 => array( [maximum depth reached] ), (int) 1 => array( [maximum depth reached] ), (int) 2 => array( [maximum depth reached] ) ), 'RatingSummary' => array( 'total_votes' => (int) 1, 'total_rating' => (float) 2.5 ) ), (int) 2 => array( 'Post' => array( 'id' => '7', 'postcategory_id' => '7', 'user_id' => '0', 'title' => 'How the PHP script may report what is the total size of any web page browsed', 'body' => '<p>These days excellent work is being done to attract web site users by creating attractive and well managed web pages. While browsing any internet site or a web page as developer or designer of the web pages we might came across the thought, “how much size of this web page is? or how much costly to render this on my browser?”. Well today lets build a script which reports information of above questions. As usual we will be using PHP for scripting the code. This script includes two things in consideration. <strong>First,</strong> how many http/https requests are being used to render the page and <strong>Second,</strong> what is the total size of the rendered web page. We will create a script in a manner that it can be used from command line interface as well as from the browser. For this the cURL module is used. If it is not installed in your PHP set up then go to my previous article of installation and configuration of PHP.</p> <p>Ok. So now what is the meaning of <strong>First</strong> part, “how many http/https requests are”. When any web page is rendered or loaded in your browser, it is a combination of one or multiple CSS files, one or multiple javascripts or .js files, code of Html, multiple images, etc… we call them web page resources as all together they make a web page. While web page is loaded all these multiple files are being called from one or different locations with specific web address. These files are called one by one as it cannot called all once at a time. The separate calls for each of these files are known as http/https requests.</p> <p>Now let’s come to the Second part of the task – “what is the total size of the rendered web page” and that consist of file size of each of these resource we saw above. When http/https requests are responded uninterrupted then that response contains response header (developers and designers knows that). One of the headers is called “Content-Length” and that gives the size of that particular resource. We need to use built in API of PHP ie. get_headers and the argument would be the URL where the http/https request is sent. Bellow is the hint and good start of the code in PHP.</p> <p><strong><em>function file_size_rendered($url) { </em></strong></p> <p><strong><em>//where $url in the argument is the location where request is being sent.</em></strong></p> <p><strong><em> $headers = get_headers($url, 1);</em></strong> </p> <p><strong><em> if (isset($headers['Content-Length'])) </em></strong></p> <p><strong><em> return $headers['Content-Length'];</em></strong> </p> <p><strong><em>//Also check whether lower case of "L" is used in Content-length</em></strong></p> <p><strong><em> if (isset($headers['Content-length'])) </em></strong></p> <p><strong><em> return $headers['Content-length'];</em></strong></p> <p><strong><em>//if the content header is not found then use the curl request</em></strong></p> <p><strong><em> $c = curl_init();</em></strong></p> <p><strong><em> curl_setopt_array($c, array(</em></strong></p> <p><strong><em> CURLOPT_URL => $url,</em></strong></p> <p><strong><em> CURLOPT_RETURNTRANSFER => true,</em></strong></p> <p><strong><em> CURLOPT_HTTPHEADER => array('User-Agent: Mozilla/5.0 </em></strong></p> <p><strong><em> (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.3) </em></strong></p> <p><strong><em> Gecko/20090824 Firefox/3.5.3'),</em></strong></p> <p><strong><em> ));</em></strong></p> <p><strong><em> curl_exec($c);</em></strong> </p> <p><strong><em> $size = curl_getinfo($c, CURLINFO_SIZE_DOWNLOAD);</em></strong> </p> <p><strong><em> return $size;</em></strong> </p> <p><strong><em> curl_close($c);</em></strong></p> <p><strong><em>}</em></strong></p> <p>This article is just a good start to inspire for deeper understanding or the technique of coding. One can browse more or post questions to get answer on more specific tasks.</p> ', 'comment_count' => '0', 'postview_count' => '1768', 'active' => '1', 'created' => '2015-12-28 10:52:20', 'modified' => '2019-11-21 06:00:37', 'tags' => 'PHP, Code, Tips' ), 'User' => array( 'id' => null, 'firstname' => null ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/how-the-php-script-may-62903-small.jpg', 'namemedium' => '/files/uploads/postimages/how-the-php-script-may-62903-medium.jpg' ), 'Rating' => array(), 'Tag' => array( (int) 0 => array( [maximum depth reached] ), (int) 1 => array( [maximum depth reached] ), (int) 2 => array( [maximum depth reached] ) ) ), (int) 3 => array( 'Post' => array( 'id' => '6', 'postcategory_id' => '8', 'user_id' => '1', 'title' => 'Developing secured web application with PHP', 'body' => '<p>Your PHP web application is deployed on the secured platform is great but it is not just enough to consider your application is secured. It is equally or more important that your source code is also developed in the same intensity of security and passed through security testing. I would like to propose certain check list to consider before you go live with your site. PHP is considered one of the easiest languages for developing web applications and this gives chance to startup developers to leave common PHP security pitfalls in development.</p> <p>Listed out bellow are few points which can be used as a check list before you publish your web application.</p> <ul> <li><strong><em>Character encoding:</em></strong> The thumb rule is always create a valid output and use UTF-8 for the encoding like in Html, Database, Html, JS, URLs, Emails and wherever it is possible.</li> <li><strong><em>User Input Data Validation:</em></strong> Validate the user input data according to which purpose it is collected from them. It is always a good idea to validate the user input data at the PHP logic even if your JavaScript validate it at the browser itself. Type-casting is also helpful in most of the cases.</li> <li><strong><em>CSRF or XSRF – Cross Site Request Forgeries: </em></strong>a request from the different site which misuses users authenticated stat data to hack or perform unwanted operations. While user is logged in, his session data is shared across all tabs in the same browser. Code the PHP script that way it uses minimum time of GET requests or probably only to access the information rather than transactions. Avoid using $_REQUEST as much possible instead use $_GET or $_POST accordingly wherever you retrieve variables.</li> </ul> <p>Another way is to generate a random value known as token while user successfully log in at the application. Store this token value in the session and check in application logic whenever user requests or post any information.</p> <ul> <li><strong><em>XSS – Cross site scripting: </em></strong>always validate HTML inputs from user’s submitted data in case like accepting comments on the posts, or collecting reviews and display them on the site. It may use to steal session an cookie data and run kind of JS script on the browser. Use strip_tags() and /or htmlspecialchars() functions which encode and prevent users data to create an HTML tags.</li> <li><strong><em>Non-disclose of file system</em></strong>: If your website allows to download any file to its users, always use some functions which takes file path as an internal system input and use respective header() arguments to download the file. Do not create a like for the file which displays whole folder structure in the link itself to download the file.</li> <li><strong><em>Restrict the file uploads</em></strong>: a user could upload a .php extension file or any other executable file through your file upload feature on site. Check the MIME type of the uploaded file with the function like finfo_file() or any similar to validate the type of file. Create an array of allowable file extensions and keep checking with the uploaded file extension is present in the allowable array or not.</li> <li><strong><em>SQL injection</em></strong>: any input which is concatenated into a string as an SQL query is called the SQL injection. Characters like semicolon, single quote, double quote, hyphens, etc which are used in the SQL queries or statements, should be escaped. This compromise the database and it allowed to be accessed by unauthorized way. Developer can use the pair of prepare () and execute () statement to execute the query rather than simply write a row query to fire on database. Most of the new generation frameworks for PHP take care of this.</li> <li>Other security measures includes <ul style="list-style-type:circle"> <li>Use a proper error handling.</li> <li>Always use .php extensions to included files.</li> <li>Filter values of “From” header before you create that in the Email function.</li> <li>Use strong password hashing algorithm while storing the passwords.</li> <li>Encrypt the session data before you store.</li> <li>Strong cipher code to encrypt data is also a good measure.</li> </ul> </li> </ul> <p style="margin-left:.25in">Web application security measures are taken at the time of designing its architecture. Also it should not happen that steps taken from the security point of view decreases the scope of usability. Security must be implemented keeping in the mind of your website users and must be included in the development budget.</p> <p style="margin-left:.25in">This is a short tutorial for PHP developers and has just stretched the surface of the development techniques. It is up to the developer who understands the depth of vulnerabilities and possible attacks on applications over the web. Developers are required to drill more on each points which are listed and /or which are left from discussion here.</p> ', 'comment_count' => '0', 'postview_count' => '1740', 'active' => '1', 'created' => '2015-07-17 13:54:47', 'modified' => '2019-11-21 06:01:23', 'tags' => 'PHP, Web Developement, Security' ), 'User' => array( 'id' => '1', 'firstname' => 'Chirayu' ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/developing-secured-web-application-65142-small.jpg', 'namemedium' => '/files/uploads/postimages/developing-secured-web-application-65142-medium.jpg' ), 'Rating' => array( (int) 0 => array( [maximum depth reached] ), (int) 1 => array( [maximum depth reached] ) ), 'Tag' => array( (int) 0 => array( [maximum depth reached] ), (int) 1 => array( [maximum depth reached] ), (int) 2 => array( [maximum depth reached] ) ), 'RatingSummary' => array( 'total_votes' => (int) 2, 'total_rating' => (float) 4 ) ), (int) 4 => array( 'Post' => array( 'id' => '5', 'postcategory_id' => '7', 'user_id' => '1', 'title' => 'Social website login for your site is Open source standards for authorization', 'body' => '<p>You might have seen many of sites now showing links or buttons of Facebook, Twitter, Google + or other social network sites on their sign up and sign in page. This is to make users life bit easier for the login or sign up process on various websites. What happens when you click on any of that link? Have you tried anytime?</p> <p>Let’s see how you as a developer can develop this feature for your website. For this we consider a use case.</p> <p><em>User came to the sign in page of your site and he looked at the login with “facebook” or “twitter” or “google” (or any of the site) link. He has a separate account of any of these listed social network sites which you have integrated in your website. He clicks on any of the link and now he is redirected to the respective site for authentication. He provides correct credential for that social network site. He is now authenticated by that social network site and if it is for the first time he is using this authentication system, he has to agree to share his profile data with the other site from where he is coming for the authentication.</em></p> <p>When user agrees to share his profile data on successful login, that social network site redirect him to your site with user’s profile information. Of course password would not be sent to your site. This authenticating social network site will generate one token for this session and send along with the user’s profile data. This token is unique to user and your site. Now all communication and data exchange between your site and the authenticating social network site happens with this token generated by the authenticated site. Give essential profile data to your website login system and create a successful login session at your website and treat him as a logged in user.</p> <p> You can store this user information into your database and send an email to him with the new login credentials to login in your site directly in future. If he doesn’t want to login from your site directly, he still has an option to login again from the social network site which he chooses. Check every time while login weather he is the stored user with his unique field value like email address or username and if not found in your database store it and or otherwise directly give an authentication to the logged in section of your site.</p> <p>All of these redirections and authentications are made through APIs provided by these authenticating sites. Most of these sites do provide a sign in APIs but do not have the APIs for sign off from the authenticated site (There are few exceptions in this). Once user is logged in to your website through open authentication system via a different web site, he has to actually login into that website. Now when he clicks on the logout link of your site, he logs out from your site not from the site from where he was authenticated. This is risk if any user is accessing your site from the public computer and forgets to log off from the authenticated site. His account would be compromised.</p> <p>You as a developer of your site must provide information about the risk factors to your users before they use separate authentication system for your site. Developers need to create an account on these sites and get secret API key to use their APIs and use this secret key into data transactions with the site.</p> <p>Here are few providers of open authentication services are also called resource owners to authorize other web service or web site to their resources without sharing their users’ credentials.</p> <p>Amazon, Dropbox, Facebook, Flickr, GitHub, Instagram, LinkedIn, Twitter, Tumblrand …..And many of others.</p> ', 'comment_count' => '0', 'postview_count' => '2059', 'active' => '1', 'created' => '2015-06-15 08:15:29', 'modified' => '2019-11-21 06:01:51', 'tags' => 'Open Authentication, Social Network Login, oAuth' ), 'User' => array( 'id' => '1', 'firstname' => 'Chirayu' ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/social-website-login-for-65938-small.jpg', 'namemedium' => '/files/uploads/postimages/social-website-login-for-65938-medium.jpg' ), 'Rating' => array( (int) 0 => array( [maximum depth reached] ) ), 'Tag' => array( (int) 0 => array( [maximum depth reached] ), (int) 1 => array( [maximum depth reached] ), (int) 2 => array( [maximum depth reached] ) ), 'RatingSummary' => array( 'total_votes' => (int) 1, 'total_rating' => (float) 5 ) ) ) $masterclass = '' $appposts = array( (int) 0 => array( 'Post' => array( 'id' => '11', 'user_id' => '1', 'title' => 'Connecting remote server using SSH', 'body' => '<p>SSH stands for secured shall - a secured network service over an unsecured network. It is a network protocol. It provides an encrypted data communication between two computers. SSH can be used interactively to enable terminal sessions. SSH is also used in scripts to remotely and securely access data and other resources. In order to connect to remote server with SSH, you need:</p> <p>1) Server IP or domain name</p> <p>2) Username</p> <p>3) Password</p> <p>4) SSH client - I recommend PuTTY (you can easily download from internet) for windows operating system while Linux and MAC users can use OpenSSH which is mostly installed in their OS.</p> <p><strong>Useful SSH commands frequently used by developers:</strong></p> <p><em>>_ ssh <remote_host></em></p> <p><remote_host> is an IP address or domain name that you are trying to connect to. This command assumes that your username on the remote system is the same as your username on your local system.</p> <p> <em>>_ ssh remote_username@<remote_host></em></p> <p>If your username is different on the remote system. You can specify by using this syntax.</p> <p>Once you are connected to the server, you will be asked to provide a password. SSH works by connecting a client program to an SSH server. In above commands, SSH is the client program. The SSH server is at the <em>remote_host</em> that is specified.</p> <p><strong>How to configure SSH</strong></p> <p>When you change the configuration of SSH, you are changing the settings of the sshd server. In Ubuntu, the main sshd configuration file is located at <em>/etc/ssh/sshd_config</em>.</p> <p>While it is helpful to be able to log in to a remote system using passwords, it is much better idea to set up Key-based authentication.</p> <p>Key based authentication works by creating a pair of keys: <strong>a private key</strong> and <strong>a public key.</strong></p> <p>The private key is located on the client machine. The public key is placed on any server you wish to access. Please check how to generate public and private keys with PuTTY for windows and with ssh-keygen for linux and mac OS. The folder in which the private key is placed default in the windows is c:\users\<username>\.ssh while in unix based system it is under /home/<username>/.ssh</p> <p>The public key is added to a special file within the user account you will be logging into called ~/.ssh/authorized_keys</p> <p>When you attempt to connect using a key pair, the server will use the public key to create a message for the client computer that can only be read with private key.</p> <p>The client computer then sends the appropriate response back to the server and the server will know that the client is legitimate. This entire process is done in the background after keys are correctly setup.</p> <p>SSH operates on TCP port 22 by default. The server listens on port 22 though this can be changed through custom port number in <em>sshd_config</em> file.</p> <p><em>>_ ssh -p</em> <em>7322 remote_username@<remote_host></em></p> <p>If you are not connecting <em>remote host</em> at the default port 22, then you need to specify the custom port number in the command. The above command shows remote host is being connected at the port number 7322.</p> ', 'created' => '2019-11-29 13:06:49', 'tags' => '' ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/ssh-connect-16148-small.jpg', 'namemedium' => '/files/uploads/postimages/ssh-connect-16148-medium.jpg' ), 'Tofriend' => array() ), (int) 1 => array( 'Post' => array( 'id' => '10', 'user_id' => '0', 'title' => 'SOLID Part-2 : Principle of Open and Closed', 'body' => '<p>Any project has a scope of changes in terms of features, functionalities and workflows. Practically, to design application prefactly from begining is almost impossible even in the agile development. Classes and interfaces are pillers of application designs.</p> <p>SOLID is one of the proven set of design principles that are meant to guide developers to design and build robust, easily maintainable and scalable software.<br /> This article is focused ont he second principle of SOLID : The principle of Open / Closed.<br /> It satates that : Software entities (ie. classes, interfaces, functions etc) should be Open to extended but closed for modifications.<br /> Lets Check first what does it mean by this principle.</p> <p>A class is closed since it may be compiled, stored in the library, baselined and used by client classes. But it is also open, since any new class may use it as parent and adding new features.</p> <p>Fortunately we have a concept of Inheritance to achieve this goal. But, inheritance introduces tight coupling if the subclasses depend on implementation details of their parent class.</p> <p>my recomandation is to start designe inheritance with interfaces instead of superclasses. The interfaces are closed for modifications, you can provide new implementations to extend the functionality of your software.</p> <p>Let’s see an example that uses the Open/Closed Principle.</p> <p>We will need a Employee interface, the Company class, which uses the Employees, and some implementation of the Employee interface.<br /> The Company class should know just one thing about the Employees — what methods to call. This is what all the Employees have in common, so we will have a Employee interface with just the common methods(ie. someWork).</p> <p>public interface Employee{<br /> public void someWork();<br /> }</p> <p>And a Company class that encapsulates an Employye implementation and executes it.<br /> public class Company() {<br /> private Employee emp;<br /> // we set the strategy in the constructor<br /> public Company(Employee emp) {<br /> this.emp = emp;<br /> }</p> <p> public void completeTheWork() {<br /> this.emp.someWork();<br /> }<br /> }</p> <p>And let’s create two implementations for the Employee interface.</p> <p>public class Employee1 implements Employee {<br /> public void someWork() {<br /> System.out.println(“Work of Emoloyee 1”);<br /> }<br /> }</p> <p>public class Employee2 implements Employee {<br /> public void someWork() {<br /> System.out.println(“Work of Emoloyee 2”);<br /> }<br /> }</p> <p>Now lets use some dependency Injection to see how it works. We need to create one Perform class.</p> <p>public class Perform() {<br /> public static void main(String[] args) {<br /> Context context = new Company(new Employee1()); // we inject the Employee1<br /> context.completeTheWorky(); // it will print “Execute employee 1”;</p> <p> context = new Company(new Employee2()); // we inject the Employee2<br /> context.completeTheWork(); // it will print “Execute employee 2”<br /> }<br /> }</p> <p>So the Company is decoupled from a specific Employee class. You could implement many Employees it needed and no matter how they work and what you want them to do, you don’t need to modify the Company class. The Company class knows just that it must call someWork method and it is enough.</p> <p>After taking a closer look at the Single Responsibility Principle, we now discussed the Open/Closed Principle.<br /> It uses Interfaces to enable you the functionality of your application without changing the existing code.</p> ', 'created' => '2019-05-24 11:59:08', 'tags' => '' ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/Solid-part-2-28564-small.jpg', 'namemedium' => '/files/uploads/postimages/Solid-part-2-28564-medium.jpg' ), 'Tofriend' => array( (int) 0 => array( [maximum depth reached] ) ) ), (int) 2 => array( 'Post' => array( 'id' => '9', 'user_id' => '0', 'title' => 'SOLID Part-1 : Single Responsibility Principle - Software design', 'body' => '<p>S O L I D</p> <p>'S' represents Single Responsibility Principle</p> <p>Every class should have responsibility over a single part of the functionality provided by the software and that responsibility should be entirely encapsulated by the class. In other words there should never be more than one trigger or reason for a class to change. When a (functional) responsibility is divided over more than one class, all classes’ part of that responsibility has to change.</p> <p>The code must be maintainable. When we need to make a change in a class having more responsibilities the change might affect the other functionality related to the other responsibility of the class. The code, which cannot adapt to change requirements with ease, is not a well defined.</p> <p>When we design our classes, we should take care that one class at the most is responsible for doing only one task or single responsibility. Not only should the class, even operations or methods in the class defined in a way that it has only one responsibility to handle. To understand this let us take an example of Employee class. Class Employee is made with few of its attributes and operations.</p> <p>Class Employee{</p> <p> private String employeeId;</p> <p> private String name;</p> <p> private string address;</p> <p> private Date dateOfJoining;</p> <p> private Int DesignationId;</p> <p> </p> <p> public amtIncrement(){</p> <p> //increment logic implementation</p> <p> }</p> <p> public calDOR(){</p> <p> //Date of retirement logic implementation</p> <p> } </p> <p> public setDateOfJoining(){</p> <p> }</p> <p> public setEmployeeId(){</p> <p> }</p> <p> public getDateOfJoining(){</p> <p> }</p> <p> public getDesignationId(){ </p> <p> } </p> <p>}</p> <p>The above class is correctly structured and it has employee attributes declared. Also it has operations related to employee.</p> <p>Here Employee class should have only responsibility to maintain and manage the data of employee in formations. But this class is violating the principle of Single Responsibility. How?</p> <p><strong>First,</strong> the logic of calculating the Date of Retirement is not the employee's responsibility. This might be defined under the HR class and calculate by taking employee's Date of Joining in the organization which is an attribute of Employee class. So if any change happens in the HR policies, the Employee Class does not get updated. Just because HR policies updated this has nothing to do with the Employee entity.</p> <p><strong>Second,</strong> the logic of calculating the amount of increment is a responsibility of Finance class and it calculated by taking the level or designation of the employee in the organization. So if any change happens to the financial status, the Employee class doesn’t get affected with that.</p> <p>If the class has only one reason to change then it stays less fragile. More responsibilities lead to more dependencies and higher coupling. A test class for a ‘one responsibility class’ will have less test cases (branches). If a class has one purpose it will usually have less dependencies, thus less mocking and test preparing.</p> <p>The Single Responsibility Principle represents a good way of identifying classes during the design phase of an application and it reminds you to think of all the ways a class can evolve. Class and module design is highly affected by SRP and it leads to a low coupled design with less and lighter dependencies.</p> <p>Points to consider when you design the class.</p> <ul> <li>Define clearly what this class is going to do.</li> <li>Reduce the long procedures of the logic. Divide into multiple chunks.</li> <li>Write the code in the way that very small steps can be tested independently.</li> </ul> ', 'created' => '2017-07-12 16:42:05', 'tags' => '' ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/Solid-part-1-50472-small.jpg', 'namemedium' => '/files/uploads/postimages/Solid-part-1-50472-medium.jpg' ), 'Tofriend' => array( (int) 0 => array( [maximum depth reached] ), (int) 1 => array( [maximum depth reached] ), (int) 2 => array( [maximum depth reached] ) ) ), (int) 3 => array( 'Post' => array( 'id' => '8', 'user_id' => '0', 'title' => 'CSV files data into php array to store in MySql', 'body' => '<p><strong><em>What are CSV files?</em></strong></p> <p>A CSV (Comma Separated Values) files are text files, allows data to be saved in a structured format. CSV files can be used with Microsoft Excel, Google Spreadsheets or Open Office Calc kind of tools. These CSV files are saved with .csv extension. In CSV files data fields are usually separated by comma as delimiter, but can also use a tab or pipe symbol instead of comma. CSV files are used to import and export data from application to application. Mostly, the first record is a header containing a list of field names. Any programming language has technique to import and export data from and to database like MS-SQL, MySql, PostGres, etc..</p> <p>PHP is one of the best programming languages for import and export of the data with the database to and from flat files like CSV files.</p> <p><strong><em>Fetching the data from the CSV file</em></strong></p> <p>Open the file in the read mode and store the content into variable. We assume that the CSV file contains the information about the contacts having fields firstname, lastname, email, and phone exported and the file name is contacts.csv.</p> <p>$csvfilehandle = fopen("contacts.csv","r");</p> <p>Here $csvfilehandle is file pointer to a file "contacts.csv" successfully opened</p> <p>while (($line = fgetcsv($csvfilehandle,1000,',','"'))!==false){</p> <p> $data[] = $line;</p> <p>}</p> <p>Close the opened file handle with </p> <p>fclose($csvfilehandle);</p> <p>The first argument $csvfilehandle is the mandatory arguments and remaining are optional.</p> <p>1000 is a length of characters per line to be set. This should be greater than the longest line in the file. If you are not sure about the length then don`t specify it.</p> <p>',' comma is a delimiter you can set or according to the data in the file the delimiter is used.</p> <p>'"' is the enclosure in the file used for the field value</p> <p>Now you have all the data of the CSV file into the array $data. If you print this with print_r($data); you get values into array.</p> <p><strong><em>Importing data into MySQL table</em></strong></p> <p>Now to import the data into the MySQL table named contacts, we need to modify the above wile loop. Let`s do that now.</p> <p>while (($line = fgetcsv($csvfilehandle,1000,',','"'))!==false){ </p> <p> mysql_query("insert into contacts(</p> <p> firstname, lastname, email, telephone</p> <p> )VALUES(</p> <p> '".mysql_real_escape_string($line[0])."',</p> <p> '".mysql_real_escape_string($line[1])."',</p> <p> '".mysql_real_escape_string($line[2])."',</p> <p> '".mysql_real_escape_string($line[3])."'</p> <p> )")</p> <p>or die(mysql_error());</p> <p>}</p> <p>fclose($csvfilehandle);</p> <p>Write me back if you are working for such functionality and not getting through the code.</p> ', 'created' => '2016-11-03 07:17:48', 'tags' => '' ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/csv-files-data-into-88773-small.png', 'namemedium' => '/files/uploads/postimages/csv-files-data-into-88773-medium.png' ), 'Tofriend' => array() ), (int) 4 => array( 'Post' => array( 'id' => '7', 'user_id' => '0', 'title' => 'How the PHP script may report what is the total size of any web page browsed', 'body' => '<p>These days excellent work is being done to attract web site users by creating attractive and well managed web pages. While browsing any internet site or a web page as developer or designer of the web pages we might came across the thought, “how much size of this web page is? or how much costly to render this on my browser?”. Well today lets build a script which reports information of above questions. As usual we will be using PHP for scripting the code. This script includes two things in consideration. <strong>First,</strong> how many http/https requests are being used to render the page and <strong>Second,</strong> what is the total size of the rendered web page. We will create a script in a manner that it can be used from command line interface as well as from the browser. For this the cURL module is used. If it is not installed in your PHP set up then go to my previous article of installation and configuration of PHP.</p> <p>Ok. So now what is the meaning of <strong>First</strong> part, “how many http/https requests are”. When any web page is rendered or loaded in your browser, it is a combination of one or multiple CSS files, one or multiple javascripts or .js files, code of Html, multiple images, etc… we call them web page resources as all together they make a web page. While web page is loaded all these multiple files are being called from one or different locations with specific web address. These files are called one by one as it cannot called all once at a time. The separate calls for each of these files are known as http/https requests.</p> <p>Now let’s come to the Second part of the task – “what is the total size of the rendered web page” and that consist of file size of each of these resource we saw above. When http/https requests are responded uninterrupted then that response contains response header (developers and designers knows that). One of the headers is called “Content-Length” and that gives the size of that particular resource. We need to use built in API of PHP ie. get_headers and the argument would be the URL where the http/https request is sent. Bellow is the hint and good start of the code in PHP.</p> <p><strong><em>function file_size_rendered($url) { </em></strong></p> <p><strong><em>//where $url in the argument is the location where request is being sent.</em></strong></p> <p><strong><em> $headers = get_headers($url, 1);</em></strong> </p> <p><strong><em> if (isset($headers['Content-Length'])) </em></strong></p> <p><strong><em> return $headers['Content-Length'];</em></strong> </p> <p><strong><em>//Also check whether lower case of "L" is used in Content-length</em></strong></p> <p><strong><em> if (isset($headers['Content-length'])) </em></strong></p> <p><strong><em> return $headers['Content-length'];</em></strong></p> <p><strong><em>//if the content header is not found then use the curl request</em></strong></p> <p><strong><em> $c = curl_init();</em></strong></p> <p><strong><em> curl_setopt_array($c, array(</em></strong></p> <p><strong><em> CURLOPT_URL => $url,</em></strong></p> <p><strong><em> CURLOPT_RETURNTRANSFER => true,</em></strong></p> <p><strong><em> CURLOPT_HTTPHEADER => array('User-Agent: Mozilla/5.0 </em></strong></p> <p><strong><em> (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.3) </em></strong></p> <p><strong><em> Gecko/20090824 Firefox/3.5.3'),</em></strong></p> <p><strong><em> ));</em></strong></p> <p><strong><em> curl_exec($c);</em></strong> </p> <p><strong><em> $size = curl_getinfo($c, CURLINFO_SIZE_DOWNLOAD);</em></strong> </p> <p><strong><em> return $size;</em></strong> </p> <p><strong><em> curl_close($c);</em></strong></p> <p><strong><em>}</em></strong></p> <p>This article is just a good start to inspire for deeper understanding or the technique of coding. One can browse more or post questions to get answer on more specific tasks.</p> ', 'created' => '2015-12-28 10:52:20', 'tags' => '' ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/how-the-php-script-may-62903-small.jpg', 'namemedium' => '/files/uploads/postimages/how-the-php-script-may-62903-medium.jpg' ), 'Tofriend' => array() ) ) $regions = array() $appcountries = array( (int) 1 => 'Andorra', (int) 2 => 'United Arab Emirates', (int) 3 => 'Afghanistan', (int) 4 => 'Antigua and Barbuda', (int) 5 => 'Anguilla', (int) 6 => 'Albania', (int) 7 => 'Armenia', (int) 8 => 'Netherlands Antilles', (int) 9 => 'Angola', (int) 12 => 'Argentina', (int) 13 => 'American Samoa', (int) 14 => 'Austria', (int) 15 => 'Australia', (int) 16 => 'Aruba', (int) 17 => 'Azerbaijan', (int) 18 => 'Bosnia and Herzegovina', (int) 19 => 'Barbados', (int) 20 => 'Bangladesh', (int) 21 => 'Belgium', (int) 22 => 'Burkina Faso', (int) 23 => 'Bulgaria', (int) 24 => 'Bahrain', (int) 25 => 'Burundi', (int) 26 => 'Benin', (int) 27 => 'Bermuda', (int) 28 => 'Brunei Darussalam', (int) 29 => 'Bolivia', (int) 30 => 'Brazil', (int) 31 => 'Bahamas', (int) 32 => 'Bhutan', (int) 34 => 'Botswana', (int) 35 => 'Belarus', (int) 36 => 'Belize', (int) 37 => 'Canada', (int) 38 => 'Cocos (Keeling) Islands', (int) 40 => 'Central African Republic', (int) 41 => 'Congo', (int) 42 => 'Switzerland', (int) 43 => 'Cote D'Ivoire', (int) 44 => 'Cook Islands', (int) 45 => 'Chile', (int) 46 => 'Cameroon', (int) 47 => 'China', (int) 48 => 'Colombia', (int) 49 => 'Costa Rica', (int) 51 => 'Cuba', (int) 52 => 'Cape Verde', (int) 53 => 'Christmas Island', (int) 54 => 'Cyprus', (int) 55 => 'Czech Republic', (int) 56 => 'Germany', (int) 57 => 'Djibouti', (int) 58 => 'Denmark', (int) 59 => 'Dominica', (int) 60 => 'Dominican Republic', (int) 61 => 'Algeria', (int) 62 => 'Ecuador', (int) 63 => 'Estonia', (int) 64 => 'Egypt', (int) 65 => 'Western Sahara', (int) 66 => 'Eritrea', (int) 67 => 'Spain', (int) 68 => 'Ethiopia', (int) 70 => 'Finland', (int) 71 => 'Fiji', (int) 72 => 'Falkland Islands (Malvinas)', (int) 73 => 'Micronesia, Federated States of', (int) 74 => 'Faroe Islands', (int) 75 => 'France', (int) 77 => 'Gabon', (int) 78 => 'United Kingdom', (int) 79 => 'Grenada', (int) 80 => 'Georgia', (int) 81 => 'French Guiana', (int) 82 => 'Ghana', (int) 83 => 'Gibraltar', (int) 84 => 'Greenland', (int) 85 => 'Gambia', (int) 86 => 'Guinea', (int) 87 => 'Guadeloupe', (int) 88 => 'Equatorial Guinea', (int) 89 => 'Greece', (int) 90 => 'South Georgia and Sandwich Island', (int) 91 => 'Guatemala', (int) 93 => 'Guinea-Bissau', (int) 94 => 'Guyana', (int) 95 => 'Hong Kong', (int) 97 => 'Honduras', (int) 98 => 'Croatia', (int) 99 => 'Haiti', (int) 100 => 'Hungary', (int) 101 => 'Indonesia', (int) 102 => 'Ireland', (int) 103 => 'Israel', (int) 104 => 'India', (int) 106 => 'Iraq', (int) 107 => 'Iran, Islamic Republic of', (int) 108 => 'Iceland', (int) 109 => 'Italy', (int) 110 => 'Jamaica', (int) 111 => 'Jordan', (int) 112 => 'Japan', (int) 113 => 'Kenya', (int) 114 => 'Kyrgyzstan', (int) 115 => 'Cambodia', (int) 116 => 'Kiribati', (int) 117 => 'Comoros', (int) 118 => 'Saint Kitts and Nevis', (int) 119 => 'Korea, Democratic', (int) 120 => 'Korea, Republic of', (int) 121 => 'Kuwait', (int) 122 => 'Cayman Islands', (int) 123 => 'Kazakhstan', (int) 124 => 'Laos', (int) 125 => 'Lebanon', (int) 126 => 'Saint Lucia', (int) 127 => 'Liechtenstein', (int) 128 => 'Sri Lanka', (int) 129 => 'Liberia', (int) 130 => 'Lesotho', (int) 131 => 'Lithuania', (int) 132 => 'Luxembourg', (int) 133 => 'Latvia', (int) 134 => 'Libya', (int) 135 => 'Morocco', (int) 136 => 'Monaco', (int) 137 => 'Moldova', (int) 138 => 'Madagascar', (int) 139 => 'Marshall Islands', (int) 140 => 'Macedonia', (int) 141 => 'Mali', (int) 142 => 'Myanmar', (int) 143 => 'Mongolia', (int) 144 => 'Macau', (int) 145 => 'Northern Mariana Islands', (int) 146 => 'Martinique', (int) 147 => 'Mauritania', (int) 148 => 'Montserrat', (int) 149 => 'Malta', (int) 150 => 'Mauritius', (int) 151 => 'Maldives', (int) 152 => 'Malawi', (int) 153 => 'Mexico', (int) 154 => 'Malaysia', (int) 155 => 'Mozambique', (int) 156 => 'Namibia', (int) 157 => 'New Caledonia', (int) 158 => 'Niger', (int) 159 => 'Norfolk Island', (int) 160 => 'Nigeria', (int) 161 => 'Nicaragua', (int) 162 => 'Netherlands', (int) 163 => 'Norway', (int) 164 => 'Nepal', (int) 165 => 'Nauru', (int) 166 => 'Niue', (int) 167 => 'New Zealand', (int) 168 => 'Oman', (int) 169 => 'Panama', (int) 170 => 'Peru', (int) 171 => 'French Polynesia', (int) 172 => 'Papua New Guinea', (int) 173 => 'Philippines', (int) 174 => 'Pakistan', (int) 175 => 'Poland', (int) 176 => 'Saint Pierre and Miquelon', (int) 177 => 'Pitcairn', (int) 180 => 'Portugal', (int) 181 => 'Palau', (int) 182 => 'Paraguay', (int) 183 => 'Qatar', (int) 184 => 'Reunion', (int) 185 => 'Romania', (int) 186 => 'Russian Federation', (int) 187 => 'Rwanda', (int) 188 => 'Saudi Arabia', (int) 189 => 'Solomon Islands', (int) 190 => 'Seychelles', (int) 191 => 'Sudan', (int) 192 => 'Sweden', (int) 193 => 'Singapore', (int) 194 => 'Saint Helena', (int) 195 => 'Slovenia', (int) 196 => 'Svalbard and Jan Mayen', (int) 197 => 'Slovakia', (int) 198 => 'Sierra Leone', (int) 199 => 'San Marino', (int) 200 => 'Senegal', (int) 201 => 'Somalia', (int) 202 => 'Suriname', (int) 203 => 'Sao Tome and Principe', (int) 204 => 'El Salvador', (int) 205 => 'Syrian Arab Republic', (int) 206 => 'Swaziland', (int) 207 => 'Turks and Caicos Islands', (int) 208 => 'Chad', (int) 209 => 'French Southern Territories', (int) 210 => 'Togo', (int) 211 => 'Thailand', (int) 212 => 'Tajikistan', (int) 213 => 'Tokelau', (int) 215 => 'Turkmenistan', (int) 216 => 'Tunisia', (int) 217 => 'Tonga', (int) 218 => 'Turkey', (int) 219 => 'Trinidad and Tobago', (int) 220 => 'Tuvalu', (int) 221 => 'Taiwan', (int) 222 => 'Tanzania, United Republic', (int) 223 => 'Ukraine', (int) 224 => 'Uganda', (int) 226 => 'United States', (int) 227 => 'Uruguay', (int) 228 => 'Uzbekistan', (int) 230 => 'Saint Vincent and the Grenadines', (int) 231 => 'Venezuela', (int) 232 => 'Virgin Islands, British', (int) 233 => 'Virgin Islands, U.S.', (int) 234 => 'Vietnam', (int) 235 => 'Vanuatu', (int) 236 => 'Wallis and Futuna', (int) 237 => 'Samoa', (int) 238 => 'Yemen', (int) 239 => 'Mayotte', (int) 240 => 'South Africa', (int) 241 => 'Zambia', (int) 242 => 'Zaire', (int) 243 => 'Zimbabwe' ) $data = array( 'Post' => array( 'id' => '11', 'postcategory_id' => '8', 'user_id' => '1', 'title' => 'Connecting remote server using SSH', 'body' => '<p>SSH stands for secured shall - a secured network service over an unsecured network. It is a network protocol. It provides an encrypted data communication between two computers. SSH can be used interactively to enable terminal sessions. SSH is also used in scripts to remotely and securely access data and other resources. In order to connect to remote server with SSH, you need:</p> <p>1) Server IP or domain name</p> <p>2) Username</p> <p>3) Password</p> <p>4) SSH client - I recommend PuTTY (you can easily download from internet) for windows operating system while Linux and MAC users can use OpenSSH which is mostly installed in their OS.</p> <p><strong>Useful SSH commands frequently used by developers:</strong></p> <p><em>>_ ssh <remote_host></em></p> <p><remote_host> is an IP address or domain name that you are trying to connect to. This command assumes that your username on the remote system is the same as your username on your local system.</p> <p> <em>>_ ssh remote_username@<remote_host></em></p> <p>If your username is different on the remote system. You can specify by using this syntax.</p> <p>Once you are connected to the server, you will be asked to provide a password. SSH works by connecting a client program to an SSH server. In above commands, SSH is the client program. The SSH server is at the <em>remote_host</em> that is specified.</p> <p><strong>How to configure SSH</strong></p> <p>When you change the configuration of SSH, you are changing the settings of the sshd server. In Ubuntu, the main sshd configuration file is located at <em>/etc/ssh/sshd_config</em>.</p> <p>While it is helpful to be able to log in to a remote system using passwords, it is much better idea to set up Key-based authentication.</p> <p>Key based authentication works by creating a pair of keys: <strong>a private key</strong> and <strong>a public key.</strong></p> <p>The private key is located on the client machine. The public key is placed on any server you wish to access. Please check how to generate public and private keys with PuTTY for windows and with ssh-keygen for linux and mac OS. The folder in which the private key is placed default in the windows is c:\users\<username>\.ssh while in unix based system it is under /home/<username>/.ssh</p> <p>The public key is added to a special file within the user account you will be logging into called ~/.ssh/authorized_keys</p> <p>When you attempt to connect using a key pair, the server will use the public key to create a message for the client computer that can only be read with private key.</p> <p>The client computer then sends the appropriate response back to the server and the server will know that the client is legitimate. This entire process is done in the background after keys are correctly setup.</p> <p>SSH operates on TCP port 22 by default. The server listens on port 22 though this can be changed through custom port number in <em>sshd_config</em> file.</p> <p><em>>_ ssh -p</em> <em>7322 remote_username@<remote_host></em></p> <p>If you are not connecting <em>remote host</em> at the default port 22, then you need to specify the custom port number in the command. The above command shows remote host is being connected at the port number 7322.</p> ', 'comment_count' => '0', 'postview_count' => '1161', 'active' => '1', 'created' => '2019-11-29 13:06:49', 'modified' => '2019-11-29 13:06:49', 'tags' => 'SSH, Network, Secure' ), 'User' => array( 'id' => '1', 'firstname' => 'Chirayu' ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/ssh-connect-16148-small.jpg', 'namemedium' => '/files/uploads/postimages/ssh-connect-16148-medium.jpg' ), 'Rating' => array( (int) 0 => array( 'id' => '11', 'foreign_model' => 'Post', 'foreign_id' => '11', 'author_ip' => '49.34.166.201', 'rating' => '3.5', 'created' => '2019-11-29 13:10:29' ) ), 'Tag' => array( (int) 0 => array( 'id' => '24', 'name' => 'SSH', 'keyname' => 'ssh', 'Tagged' => array( [maximum depth reached] ) ), (int) 1 => array( 'id' => '25', 'name' => 'Network', 'keyname' => 'network', 'Tagged' => array( [maximum depth reached] ) ), (int) 2 => array( 'id' => '26', 'name' => 'Secure', 'keyname' => 'secure', 'Tagged' => array( [maximum depth reached] ) ) ), 'RatingSummary' => array( 'total_votes' => (int) 1, 'total_rating' => (float) 3.5 ) ) $model = null $modelClass = null $submit_url = '/feedback/ratings/add' $element_id = 'rating-1452208407' $message_id = 'message-1452208407' $values_id = 'values-1452208407' $readonly = 'false' $value = (float) 3.5 $votes = (float) 1 $user_vote = (int) 0 $user_vote_message = 'Your vote: 0.0' $submitting_message = 'Sending vote...' $error_message = 'There was an error while saving your vote'include - APP/Plugin/Feedback/View/Elements/rating.ctp, line 59 View::_evaluate() - CORE/Cake/View/View.php, line 971 View::_render() - CORE/Cake/View/View.php, line 933 View::_renderElement() - CORE/Cake/View/View.php, line 1224 View::element() - CORE/Cake/View/View.php, line 418 RatingsHelper::display_for() - APP/Plugin/Feedback/View/Helper/RatingsHelper.php, line 53 include - APP/View/Posts/filter.ctp, line 30 View::_evaluate() - CORE/Cake/View/View.php, line 971 View::_render() - CORE/Cake/View/View.php, line 933 View::render() - CORE/Cake/View/View.php, line 473 Controller::render() - CORE/Cake/Controller/Controller.php, line 963 Dispatcher::_invoke() - CORE/Cake/Routing/Dispatcher.php, line 200 Dispatcher::dispatch() - CORE/Cake/Routing/Dispatcher.php, line 167 [main] - APP/webroot/index.php, line 109
CSV files data into php array to store in MySql
Warning (2): key() expects parameter 1 to be array, null given [APP/Plugin/Feedback/View/Helper/RatingsHelper.php, line 73]Code Contextif (empty($model) && empty($modelClass))
{
$modelClass = key($this->models);
$data = array( 'Post' => array( 'id' => '8', 'postcategory_id' => '7', 'user_id' => '0', 'title' => 'CSV files data into php array to store in MySql', 'body' => '<p><strong><em>What are CSV files?</em></strong></p> <p>A CSV (Comma Separated Values) files are text files, allows data to be saved in a structured format. CSV files can be used with Microsoft Excel, Google Spreadsheets or Open Office Calc kind of tools. These CSV files are saved with .csv extension. In CSV files data fields are usually separated by comma as delimiter, but can also use a tab or pipe symbol instead of comma. CSV files are used to import and export data from application to application. Mostly, the first record is a header containing a list of field names. Any programming language has technique to import and export data from and to database like MS-SQL, MySql, PostGres, etc..</p> <p>PHP is one of the best programming languages for import and export of the data with the database to and from flat files like CSV files.</p> <p><strong><em>Fetching the data from the CSV file</em></strong></p> <p>Open the file in the read mode and store the content into variable. We assume that the CSV file contains the information about the contacts having fields firstname, lastname, email, and phone exported and the file name is contacts.csv.</p> <p>$csvfilehandle = fopen("contacts.csv","r");</p> <p>Here $csvfilehandle is file pointer to a file "contacts.csv" successfully opened</p> <p>while (($line = fgetcsv($csvfilehandle,1000,',','"'))!==false){</p> <p> $data[] = $line;</p> <p>}</p> <p>Close the opened file handle with </p> <p>fclose($csvfilehandle);</p> <p>The first argument $csvfilehandle is the mandatory arguments and remaining are optional.</p> <p>1000 is a length of characters per line to be set. This should be greater than the longest line in the file. If you are not sure about the length then don`t specify it.</p> <p>',' comma is a delimiter you can set or according to the data in the file the delimiter is used.</p> <p>'"' is the enclosure in the file used for the field value</p> <p>Now you have all the data of the CSV file into the array $data. If you print this with print_r($data); you get values into array.</p> <p><strong><em>Importing data into MySQL table</em></strong></p> <p>Now to import the data into the MySQL table named contacts, we need to modify the above wile loop. Let`s do that now.</p> <p>while (($line = fgetcsv($csvfilehandle,1000,',','"'))!==false){ </p> <p> mysql_query("insert into contacts(</p> <p> firstname, lastname, email, telephone</p> <p> )VALUES(</p> <p> '".mysql_real_escape_string($line[0])."',</p> <p> '".mysql_real_escape_string($line[1])."',</p> <p> '".mysql_real_escape_string($line[2])."',</p> <p> '".mysql_real_escape_string($line[3])."'</p> <p> )")</p> <p>or die(mysql_error());</p> <p>}</p> <p>fclose($csvfilehandle);</p> <p>Write me back if you are working for such functionality and not getting through the code.</p> ', 'comment_count' => '1', 'postview_count' => '1540', 'active' => '1', 'created' => '2016-11-03 07:17:48', 'modified' => '2019-11-21 06:00:03', 'tags' => 'PHP, CSV files, File content' ), 'User' => array( 'id' => null, 'firstname' => null ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/csv-files-data-into-88773-small.png', 'namemedium' => '/files/uploads/postimages/csv-files-data-into-88773-medium.png' ), 'Rating' => array( (int) 0 => array( 'id' => '7', 'foreign_model' => 'Post', 'foreign_id' => '8', 'author_ip' => '49.34.160.19', 'rating' => '2.5', 'created' => '2016-11-03 07:18:34' ) ), 'Tag' => array( (int) 0 => array( 'id' => '4', 'name' => 'PHP', 'keyname' => 'php', 'Tagged' => array( [maximum depth reached] ) ), (int) 1 => array( 'id' => '18', 'name' => 'CSV files', 'keyname' => 'csvfiles', 'Tagged' => array( [maximum depth reached] ) ), (int) 2 => array( 'id' => '19', 'name' => 'File content', 'keyname' => 'filecontent', 'Tagged' => array( [maximum depth reached] ) ) ), 'RatingSummary' => array( 'total_votes' => (int) 1, 'total_rating' => (float) 2.5 ) ) $options = array() $model = null $modelClass = nullkey - [internal], line ?? RatingsHelper::prepareParams() - APP/Plugin/Feedback/View/Helper/RatingsHelper.php, line 73 RatingsHelper::display_for() - APP/Plugin/Feedback/View/Helper/RatingsHelper.php, line 48 include - APP/View/Posts/filter.ctp, line 30 View::_evaluate() - CORE/Cake/View/View.php, line 971 View::_render() - CORE/Cake/View/View.php, line 933 View::render() - CORE/Cake/View/View.php, line 473 Controller::render() - CORE/Cake/Controller/Controller.php, line 963 Dispatcher::_invoke() - CORE/Cake/Routing/Dispatcher.php, line 200 Dispatcher::dispatch() - CORE/Cake/Routing/Dispatcher.php, line 167 [main] - APP/webroot/index.php, line 109
Warning (2): current() expects parameter 1 to be array, null given [APP/Plugin/Feedback/View/Helper/RatingsHelper.php, line 74]Code Context{
$modelClass = key($this->models);
$model = current($this->models);
$data = array( 'Post' => array( 'id' => '8', 'postcategory_id' => '7', 'user_id' => '0', 'title' => 'CSV files data into php array to store in MySql', 'body' => '<p><strong><em>What are CSV files?</em></strong></p> <p>A CSV (Comma Separated Values) files are text files, allows data to be saved in a structured format. CSV files can be used with Microsoft Excel, Google Spreadsheets or Open Office Calc kind of tools. These CSV files are saved with .csv extension. In CSV files data fields are usually separated by comma as delimiter, but can also use a tab or pipe symbol instead of comma. CSV files are used to import and export data from application to application. Mostly, the first record is a header containing a list of field names. Any programming language has technique to import and export data from and to database like MS-SQL, MySql, PostGres, etc..</p> <p>PHP is one of the best programming languages for import and export of the data with the database to and from flat files like CSV files.</p> <p><strong><em>Fetching the data from the CSV file</em></strong></p> <p>Open the file in the read mode and store the content into variable. We assume that the CSV file contains the information about the contacts having fields firstname, lastname, email, and phone exported and the file name is contacts.csv.</p> <p>$csvfilehandle = fopen("contacts.csv","r");</p> <p>Here $csvfilehandle is file pointer to a file "contacts.csv" successfully opened</p> <p>while (($line = fgetcsv($csvfilehandle,1000,',','"'))!==false){</p> <p> $data[] = $line;</p> <p>}</p> <p>Close the opened file handle with </p> <p>fclose($csvfilehandle);</p> <p>The first argument $csvfilehandle is the mandatory arguments and remaining are optional.</p> <p>1000 is a length of characters per line to be set. This should be greater than the longest line in the file. If you are not sure about the length then don`t specify it.</p> <p>',' comma is a delimiter you can set or according to the data in the file the delimiter is used.</p> <p>'"' is the enclosure in the file used for the field value</p> <p>Now you have all the data of the CSV file into the array $data. If you print this with print_r($data); you get values into array.</p> <p><strong><em>Importing data into MySQL table</em></strong></p> <p>Now to import the data into the MySQL table named contacts, we need to modify the above wile loop. Let`s do that now.</p> <p>while (($line = fgetcsv($csvfilehandle,1000,',','"'))!==false){ </p> <p> mysql_query("insert into contacts(</p> <p> firstname, lastname, email, telephone</p> <p> )VALUES(</p> <p> '".mysql_real_escape_string($line[0])."',</p> <p> '".mysql_real_escape_string($line[1])."',</p> <p> '".mysql_real_escape_string($line[2])."',</p> <p> '".mysql_real_escape_string($line[3])."'</p> <p> )")</p> <p>or die(mysql_error());</p> <p>}</p> <p>fclose($csvfilehandle);</p> <p>Write me back if you are working for such functionality and not getting through the code.</p> ', 'comment_count' => '1', 'postview_count' => '1540', 'active' => '1', 'created' => '2016-11-03 07:17:48', 'modified' => '2019-11-21 06:00:03', 'tags' => 'PHP, CSV files, File content' ), 'User' => array( 'id' => null, 'firstname' => null ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/csv-files-data-into-88773-small.png', 'namemedium' => '/files/uploads/postimages/csv-files-data-into-88773-medium.png' ), 'Rating' => array( (int) 0 => array( 'id' => '7', 'foreign_model' => 'Post', 'foreign_id' => '8', 'author_ip' => '49.34.160.19', 'rating' => '2.5', 'created' => '2016-11-03 07:18:34' ) ), 'Tag' => array( (int) 0 => array( 'id' => '4', 'name' => 'PHP', 'keyname' => 'php', 'Tagged' => array( [maximum depth reached] ) ), (int) 1 => array( 'id' => '18', 'name' => 'CSV files', 'keyname' => 'csvfiles', 'Tagged' => array( [maximum depth reached] ) ), (int) 2 => array( 'id' => '19', 'name' => 'File content', 'keyname' => 'filecontent', 'Tagged' => array( [maximum depth reached] ) ) ), 'RatingSummary' => array( 'total_votes' => (int) 1, 'total_rating' => (float) 2.5 ) ) $options = array() $model = null $modelClass = nullcurrent - [internal], line ?? RatingsHelper::prepareParams() - APP/Plugin/Feedback/View/Helper/RatingsHelper.php, line 74 RatingsHelper::display_for() - APP/Plugin/Feedback/View/Helper/RatingsHelper.php, line 48 include - APP/View/Posts/filter.ctp, line 30 View::_evaluate() - CORE/Cake/View/View.php, line 971 View::_render() - CORE/Cake/View/View.php, line 933 View::render() - CORE/Cake/View/View.php, line 473 Controller::render() - CORE/Cake/Controller/Controller.php, line 963 Dispatcher::_invoke() - CORE/Cake/Routing/Dispatcher.php, line 200 Dispatcher::dispatch() - CORE/Cake/Routing/Dispatcher.php, line 167 [main] - APP/webroot/index.php, line 109
Notice (8): Undefined index: [APP/Plugin/Feedback/View/Helper/RatingsHelper.php, line 81]Code Context$message_id = 'message-'.$random_id;
$values_id = 'values-'.$random_id;
$id = $data[$modelClass]['id'];
$data = array( 'Post' => array( 'id' => '8', 'postcategory_id' => '7', 'user_id' => '0', 'title' => 'CSV files data into php array to store in MySql', 'body' => '<p><strong><em>What are CSV files?</em></strong></p> <p>A CSV (Comma Separated Values) files are text files, allows data to be saved in a structured format. CSV files can be used with Microsoft Excel, Google Spreadsheets or Open Office Calc kind of tools. These CSV files are saved with .csv extension. In CSV files data fields are usually separated by comma as delimiter, but can also use a tab or pipe symbol instead of comma. CSV files are used to import and export data from application to application. Mostly, the first record is a header containing a list of field names. Any programming language has technique to import and export data from and to database like MS-SQL, MySql, PostGres, etc..</p> <p>PHP is one of the best programming languages for import and export of the data with the database to and from flat files like CSV files.</p> <p><strong><em>Fetching the data from the CSV file</em></strong></p> <p>Open the file in the read mode and store the content into variable. We assume that the CSV file contains the information about the contacts having fields firstname, lastname, email, and phone exported and the file name is contacts.csv.</p> <p>$csvfilehandle = fopen("contacts.csv","r");</p> <p>Here $csvfilehandle is file pointer to a file "contacts.csv" successfully opened</p> <p>while (($line = fgetcsv($csvfilehandle,1000,',','"'))!==false){</p> <p> $data[] = $line;</p> <p>}</p> <p>Close the opened file handle with </p> <p>fclose($csvfilehandle);</p> <p>The first argument $csvfilehandle is the mandatory arguments and remaining are optional.</p> <p>1000 is a length of characters per line to be set. This should be greater than the longest line in the file. If you are not sure about the length then don`t specify it.</p> <p>',' comma is a delimiter you can set or according to the data in the file the delimiter is used.</p> <p>'"' is the enclosure in the file used for the field value</p> <p>Now you have all the data of the CSV file into the array $data. If you print this with print_r($data); you get values into array.</p> <p><strong><em>Importing data into MySQL table</em></strong></p> <p>Now to import the data into the MySQL table named contacts, we need to modify the above wile loop. Let`s do that now.</p> <p>while (($line = fgetcsv($csvfilehandle,1000,',','"'))!==false){ </p> <p> mysql_query("insert into contacts(</p> <p> firstname, lastname, email, telephone</p> <p> )VALUES(</p> <p> '".mysql_real_escape_string($line[0])."',</p> <p> '".mysql_real_escape_string($line[1])."',</p> <p> '".mysql_real_escape_string($line[2])."',</p> <p> '".mysql_real_escape_string($line[3])."'</p> <p> )")</p> <p>or die(mysql_error());</p> <p>}</p> <p>fclose($csvfilehandle);</p> <p>Write me back if you are working for such functionality and not getting through the code.</p> ', 'comment_count' => '1', 'postview_count' => '1540', 'active' => '1', 'created' => '2016-11-03 07:17:48', 'modified' => '2019-11-21 06:00:03', 'tags' => 'PHP, CSV files, File content' ), 'User' => array( 'id' => null, 'firstname' => null ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/csv-files-data-into-88773-small.png', 'namemedium' => '/files/uploads/postimages/csv-files-data-into-88773-medium.png' ), 'Rating' => array( (int) 0 => array( 'id' => '7', 'foreign_model' => 'Post', 'foreign_id' => '8', 'author_ip' => '49.34.160.19', 'rating' => '2.5', 'created' => '2016-11-03 07:18:34' ) ), 'Tag' => array( (int) 0 => array( 'id' => '4', 'name' => 'PHP', 'keyname' => 'php', 'Tagged' => array( [maximum depth reached] ) ), (int) 1 => array( 'id' => '18', 'name' => 'CSV files', 'keyname' => 'csvfiles', 'Tagged' => array( [maximum depth reached] ) ), (int) 2 => array( 'id' => '19', 'name' => 'File content', 'keyname' => 'filecontent', 'Tagged' => array( [maximum depth reached] ) ) ), 'RatingSummary' => array( 'total_votes' => (int) 1, 'total_rating' => (float) 2.5 ) ) $options = array() $model = null $modelClass = null $random_id = (int) 2065393822 $element_id = 'rating-2065393822' $message_id = 'message-2065393822' $values_id = 'values-2065393822'RatingsHelper::prepareParams() - APP/Plugin/Feedback/View/Helper/RatingsHelper.php, line 81 RatingsHelper::display_for() - APP/Plugin/Feedback/View/Helper/RatingsHelper.php, line 48 include - APP/View/Posts/filter.ctp, line 30 View::_evaluate() - CORE/Cake/View/View.php, line 971 View::_render() - CORE/Cake/View/View.php, line 933 View::render() - CORE/Cake/View/View.php, line 473 Controller::render() - CORE/Cake/Controller/Controller.php, line 963 Dispatcher::_invoke() - CORE/Cake/Routing/Dispatcher.php, line 200 Dispatcher::dispatch() - CORE/Cake/Routing/Dispatcher.php, line 167 [main] - APP/webroot/index.php, line 109
Notice (8): Undefined index: [APP/Plugin/Feedback/View/Elements/rating.ctp, line 59]Code ContextRating: {
foreign_model: '{$modelClass}',
foreign_id: '{$data[$modelClass]['id']}',
$viewFile = '/var/www/html/chirayuim/app/Plugin/Feedback/View/Elements/rating.ctp' $dataForView = array( 'tags' => array( (int) 0 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 1 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 2 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 3 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 4 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 5 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 6 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 7 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 8 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 9 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 10 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 11 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 12 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 13 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 14 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 15 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 16 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 17 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 18 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 19 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ) ), 'postcategories' => array( (int) 0 => array( 'Postcategory' => array( [maximum depth reached] ), 'ParentPostcategory' => array( [maximum depth reached] ), 'ChildPostcategory' => array([maximum depth reached]), 'Post' => array( [maximum depth reached] ), 'children' => array([maximum depth reached]) ), (int) 1 => array( 'Postcategory' => array( [maximum depth reached] ), 'ParentPostcategory' => array( [maximum depth reached] ), 'ChildPostcategory' => array([maximum depth reached]), 'Post' => array( [maximum depth reached] ), 'children' => array([maximum depth reached]) ), (int) 2 => array( 'Postcategory' => array( [maximum depth reached] ), 'ParentPostcategory' => array( [maximum depth reached] ), 'ChildPostcategory' => array( [maximum depth reached] ), 'Post' => array( [maximum depth reached] ), 'children' => array( [maximum depth reached] ) ), (int) 3 => array( 'Postcategory' => array( [maximum depth reached] ), 'ParentPostcategory' => array( [maximum depth reached] ), 'ChildPostcategory' => array([maximum depth reached]), 'Post' => array( [maximum depth reached] ), 'children' => array([maximum depth reached]) ) ), 'posts' => array( (int) 0 => array( 'Post' => array( [maximum depth reached] ), 'User' => array( [maximum depth reached] ), 'Postcoverimage' => array( [maximum depth reached] ), 'Rating' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), 'RatingSummary' => array( [maximum depth reached] ) ), (int) 1 => array( 'Post' => array( [maximum depth reached] ), 'User' => array( [maximum depth reached] ), 'Postcoverimage' => array( [maximum depth reached] ), 'Rating' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), 'RatingSummary' => array( [maximum depth reached] ) ), (int) 2 => array( 'Post' => array( [maximum depth reached] ), 'User' => array( [maximum depth reached] ), 'Postcoverimage' => array( [maximum depth reached] ), 'Rating' => array([maximum depth reached]), 'Tag' => array( [maximum depth reached] ) ), (int) 3 => array( 'Post' => array( [maximum depth reached] ), 'User' => array( [maximum depth reached] ), 'Postcoverimage' => array( [maximum depth reached] ), 'Rating' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), 'RatingSummary' => array( [maximum depth reached] ) ), (int) 4 => array( 'Post' => array( [maximum depth reached] ), 'User' => array( [maximum depth reached] ), 'Postcoverimage' => array( [maximum depth reached] ), 'Rating' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), 'RatingSummary' => array( [maximum depth reached] ) ) ), 'masterclass' => '', 'appposts' => array( (int) 0 => array( 'Post' => array( [maximum depth reached] ), 'Postcoverimage' => array( [maximum depth reached] ), 'Tofriend' => array([maximum depth reached]) ), (int) 1 => array( 'Post' => array( [maximum depth reached] ), 'Postcoverimage' => array( [maximum depth reached] ), 'Tofriend' => array( [maximum depth reached] ) ), (int) 2 => array( 'Post' => array( [maximum depth reached] ), 'Postcoverimage' => array( [maximum depth reached] ), 'Tofriend' => array( [maximum depth reached] ) ), (int) 3 => array( 'Post' => array( [maximum depth reached] ), 'Postcoverimage' => array( [maximum depth reached] ), 'Tofriend' => array([maximum depth reached]) ), (int) 4 => array( 'Post' => array( [maximum depth reached] ), 'Postcoverimage' => array( [maximum depth reached] ), 'Tofriend' => array([maximum depth reached]) ) ), 'regions' => array(), 'appcountries' => array( (int) 1 => 'Andorra', (int) 2 => 'United Arab Emirates', (int) 3 => 'Afghanistan', (int) 4 => 'Antigua and Barbuda', (int) 5 => 'Anguilla', (int) 6 => 'Albania', (int) 7 => 'Armenia', (int) 8 => 'Netherlands Antilles', (int) 9 => 'Angola', (int) 12 => 'Argentina', (int) 13 => 'American Samoa', (int) 14 => 'Austria', (int) 15 => 'Australia', (int) 16 => 'Aruba', (int) 17 => 'Azerbaijan', (int) 18 => 'Bosnia and Herzegovina', (int) 19 => 'Barbados', (int) 20 => 'Bangladesh', (int) 21 => 'Belgium', (int) 22 => 'Burkina Faso', (int) 23 => 'Bulgaria', (int) 24 => 'Bahrain', (int) 25 => 'Burundi', (int) 26 => 'Benin', (int) 27 => 'Bermuda', (int) 28 => 'Brunei Darussalam', (int) 29 => 'Bolivia', (int) 30 => 'Brazil', (int) 31 => 'Bahamas', (int) 32 => 'Bhutan', (int) 34 => 'Botswana', (int) 35 => 'Belarus', (int) 36 => 'Belize', (int) 37 => 'Canada', (int) 38 => 'Cocos (Keeling) Islands', (int) 40 => 'Central African Republic', (int) 41 => 'Congo', (int) 42 => 'Switzerland', (int) 43 => 'Cote D'Ivoire', (int) 44 => 'Cook Islands', (int) 45 => 'Chile', (int) 46 => 'Cameroon', (int) 47 => 'China', (int) 48 => 'Colombia', (int) 49 => 'Costa Rica', (int) 51 => 'Cuba', (int) 52 => 'Cape Verde', (int) 53 => 'Christmas Island', (int) 54 => 'Cyprus', (int) 55 => 'Czech Republic', (int) 56 => 'Germany', (int) 57 => 'Djibouti', (int) 58 => 'Denmark', (int) 59 => 'Dominica', (int) 60 => 'Dominican Republic', (int) 61 => 'Algeria', (int) 62 => 'Ecuador', (int) 63 => 'Estonia', (int) 64 => 'Egypt', (int) 65 => 'Western Sahara', (int) 66 => 'Eritrea', (int) 67 => 'Spain', (int) 68 => 'Ethiopia', (int) 70 => 'Finland', (int) 71 => 'Fiji', (int) 72 => 'Falkland Islands (Malvinas)', (int) 73 => 'Micronesia, Federated States of', (int) 74 => 'Faroe Islands', (int) 75 => 'France', (int) 77 => 'Gabon', (int) 78 => 'United Kingdom', (int) 79 => 'Grenada', (int) 80 => 'Georgia', (int) 81 => 'French Guiana', (int) 82 => 'Ghana', (int) 83 => 'Gibraltar', (int) 84 => 'Greenland', (int) 85 => 'Gambia', (int) 86 => 'Guinea', (int) 87 => 'Guadeloupe', (int) 88 => 'Equatorial Guinea', (int) 89 => 'Greece', (int) 90 => 'South Georgia and Sandwich Island', (int) 91 => 'Guatemala', (int) 93 => 'Guinea-Bissau', (int) 94 => 'Guyana', (int) 95 => 'Hong Kong', (int) 97 => 'Honduras', (int) 98 => 'Croatia', (int) 99 => 'Haiti', (int) 100 => 'Hungary', (int) 101 => 'Indonesia', (int) 102 => 'Ireland', (int) 103 => 'Israel', (int) 104 => 'India', (int) 106 => 'Iraq', (int) 107 => 'Iran, Islamic Republic of', (int) 108 => 'Iceland', (int) 109 => 'Italy', (int) 110 => 'Jamaica', (int) 111 => 'Jordan', (int) 112 => 'Japan', (int) 113 => 'Kenya', (int) 114 => 'Kyrgyzstan', (int) 115 => 'Cambodia', (int) 116 => 'Kiribati', (int) 117 => 'Comoros', (int) 118 => 'Saint Kitts and Nevis', (int) 119 => 'Korea, Democratic', (int) 120 => 'Korea, Republic of', (int) 121 => 'Kuwait', (int) 122 => 'Cayman Islands', (int) 123 => 'Kazakhstan', (int) 124 => 'Laos', (int) 125 => 'Lebanon', (int) 126 => 'Saint Lucia', (int) 127 => 'Liechtenstein', (int) 128 => 'Sri Lanka', (int) 129 => 'Liberia', (int) 130 => 'Lesotho', (int) 131 => 'Lithuania', (int) 132 => 'Luxembourg', (int) 133 => 'Latvia', (int) 134 => 'Libya', (int) 135 => 'Morocco', (int) 136 => 'Monaco', (int) 137 => 'Moldova', (int) 138 => 'Madagascar', (int) 139 => 'Marshall Islands', (int) 140 => 'Macedonia', (int) 141 => 'Mali', (int) 142 => 'Myanmar', (int) 143 => 'Mongolia', (int) 144 => 'Macau', (int) 145 => 'Northern Mariana Islands', (int) 146 => 'Martinique', (int) 147 => 'Mauritania', (int) 148 => 'Montserrat', (int) 149 => 'Malta', (int) 150 => 'Mauritius', (int) 151 => 'Maldives', (int) 152 => 'Malawi', (int) 153 => 'Mexico', (int) 154 => 'Malaysia', (int) 155 => 'Mozambique', (int) 156 => 'Namibia', (int) 157 => 'New Caledonia', (int) 158 => 'Niger', (int) 159 => 'Norfolk Island', (int) 160 => 'Nigeria', (int) 161 => 'Nicaragua', (int) 162 => 'Netherlands', (int) 163 => 'Norway', (int) 164 => 'Nepal', (int) 165 => 'Nauru', (int) 166 => 'Niue', (int) 167 => 'New Zealand', (int) 168 => 'Oman', (int) 169 => 'Panama', (int) 170 => 'Peru', (int) 171 => 'French Polynesia', (int) 172 => 'Papua New Guinea', (int) 173 => 'Philippines', (int) 174 => 'Pakistan', (int) 175 => 'Poland', (int) 176 => 'Saint Pierre and Miquelon', (int) 177 => 'Pitcairn', (int) 180 => 'Portugal', (int) 181 => 'Palau', (int) 182 => 'Paraguay', (int) 183 => 'Qatar', (int) 184 => 'Reunion', (int) 185 => 'Romania', (int) 186 => 'Russian Federation', (int) 187 => 'Rwanda', (int) 188 => 'Saudi Arabia', (int) 189 => 'Solomon Islands', (int) 190 => 'Seychelles', (int) 191 => 'Sudan', (int) 192 => 'Sweden', (int) 193 => 'Singapore', (int) 194 => 'Saint Helena', (int) 195 => 'Slovenia', (int) 196 => 'Svalbard and Jan Mayen', (int) 197 => 'Slovakia', (int) 198 => 'Sierra Leone', (int) 199 => 'San Marino', (int) 200 => 'Senegal', (int) 201 => 'Somalia', (int) 202 => 'Suriname', (int) 203 => 'Sao Tome and Principe', (int) 204 => 'El Salvador', (int) 205 => 'Syrian Arab Republic', (int) 206 => 'Swaziland', (int) 207 => 'Turks and Caicos Islands', (int) 208 => 'Chad', (int) 209 => 'French Southern Territories', (int) 210 => 'Togo', (int) 211 => 'Thailand', (int) 212 => 'Tajikistan', (int) 213 => 'Tokelau', (int) 215 => 'Turkmenistan', (int) 216 => 'Tunisia', (int) 217 => 'Tonga', (int) 218 => 'Turkey', (int) 219 => 'Trinidad and Tobago', (int) 220 => 'Tuvalu', (int) 221 => 'Taiwan', (int) 222 => 'Tanzania, United Republic', (int) 223 => 'Ukraine', (int) 224 => 'Uganda', (int) 226 => 'United States', (int) 227 => 'Uruguay', (int) 228 => 'Uzbekistan', (int) 230 => 'Saint Vincent and the Grenadines', (int) 231 => 'Venezuela', (int) 232 => 'Virgin Islands, British', (int) 233 => 'Virgin Islands, U.S.', (int) 234 => 'Vietnam', (int) 235 => 'Vanuatu', (int) 236 => 'Wallis and Futuna', (int) 237 => 'Samoa', (int) 238 => 'Yemen', (int) 239 => 'Mayotte', (int) 240 => 'South Africa', (int) 241 => 'Zambia', (int) 242 => 'Zaire', (int) 243 => 'Zimbabwe' ), 'data' => array( 'Post' => array( 'id' => '8', 'postcategory_id' => '7', 'user_id' => '0', 'title' => 'CSV files data into php array to store in MySql', 'body' => '<p><strong><em>What are CSV files?</em></strong></p> <p>A CSV (Comma Separated Values) files are text files, allows data to be saved in a structured format. CSV files can be used with Microsoft Excel, Google Spreadsheets or Open Office Calc kind of tools. These CSV files are saved with .csv extension. In CSV files data fields are usually separated by comma as delimiter, but can also use a tab or pipe symbol instead of comma. CSV files are used to import and export data from application to application. Mostly, the first record is a header containing a list of field names. Any programming language has technique to import and export data from and to database like MS-SQL, MySql, PostGres, etc..</p> <p>PHP is one of the best programming languages for import and export of the data with the database to and from flat files like CSV files.</p> <p><strong><em>Fetching the data from the CSV file</em></strong></p> <p>Open the file in the read mode and store the content into variable. We assume that the CSV file contains the information about the contacts having fields firstname, lastname, email, and phone exported and the file name is contacts.csv.</p> <p>$csvfilehandle = fopen("contacts.csv","r");</p> <p>Here $csvfilehandle is file pointer to a file "contacts.csv" successfully opened</p> <p>while (($line = fgetcsv($csvfilehandle,1000,',','"'))!==false){</p> <p> $data[] = $line;</p> <p>}</p> <p>Close the opened file handle with </p> <p>fclose($csvfilehandle);</p> <p>The first argument $csvfilehandle is the mandatory arguments and remaining are optional.</p> <p>1000 is a length of characters per line to be set. This should be greater than the longest line in the file. If you are not sure about the length then don`t specify it.</p> <p>',' comma is a delimiter you can set or according to the data in the file the delimiter is used.</p> <p>'"' is the enclosure in the file used for the field value</p> <p>Now you have all the data of the CSV file into the array $data. If you print this with print_r($data); you get values into array.</p> <p><strong><em>Importing data into MySQL table</em></strong></p> <p>Now to import the data into the MySQL table named contacts, we need to modify the above wile loop. Let`s do that now.</p> <p>while (($line = fgetcsv($csvfilehandle,1000,',','"'))!==false){ </p> <p> mysql_query("insert into contacts(</p> <p> firstname, lastname, email, telephone</p> <p> )VALUES(</p> <p> '".mysql_real_escape_string($line[0])."',</p> <p> '".mysql_real_escape_string($line[1])."',</p> <p> '".mysql_real_escape_string($line[2])."',</p> <p> '".mysql_real_escape_string($line[3])."'</p> <p> )")</p> <p>or die(mysql_error());</p> <p>}</p> <p>fclose($csvfilehandle);</p> <p>Write me back if you are working for such functionality and not getting through the code.</p> ', 'comment_count' => '1', 'postview_count' => '1540', 'active' => '1', 'created' => '2016-11-03 07:17:48', 'modified' => '2019-11-21 06:00:03', 'tags' => 'PHP, CSV files, File content' ), 'User' => array( 'id' => null, 'firstname' => null ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/csv-files-data-into-88773-small.png', 'namemedium' => '/files/uploads/postimages/csv-files-data-into-88773-medium.png' ), 'Rating' => array( (int) 0 => array( [maximum depth reached] ) ), 'Tag' => array( (int) 0 => array( [maximum depth reached] ), (int) 1 => array( [maximum depth reached] ), (int) 2 => array( [maximum depth reached] ) ), 'RatingSummary' => array( 'total_votes' => (int) 1, 'total_rating' => (float) 2.5 ) ), 'model' => null, 'modelClass' => null, 'submit_url' => '/feedback/ratings/add', 'element_id' => 'rating-2065393822', 'message_id' => 'message-2065393822', 'values_id' => 'values-2065393822', 'readonly' => 'false', 'value' => (float) 2.5, 'votes' => (float) 1, 'user_vote' => (int) 0 ) $tags = array( (int) 0 => array( 'Tagged' => array( 'tag_id' => '1' ), 'Tag' => array( 'id' => '1', 'identifier' => null, 'name' => 'Configuration', 'keyname' => 'configuration', 'weight' => (float) 12, 'occurrence' => '2' ), (int) 0 => array( 'occurrence' => '2' ) ), (int) 1 => array( 'Tagged' => array( 'tag_id' => '2' ), 'Tag' => array( 'id' => '2', 'identifier' => null, 'name' => 'PHP5', 'keyname' => 'php5', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 2 => array( 'Tagged' => array( 'tag_id' => '3' ), 'Tag' => array( 'id' => '3', 'identifier' => null, 'name' => 'Apache2', 'keyname' => 'apache2', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 3 => array( 'Tagged' => array( 'tag_id' => '4' ), 'Tag' => array( 'id' => '4', 'identifier' => null, 'name' => 'PHP', 'keyname' => 'php', 'weight' => (float) 20, 'occurrence' => '6' ), (int) 0 => array( 'occurrence' => '6' ) ), (int) 4 => array( 'Tagged' => array( 'tag_id' => '5' ), 'Tag' => array( 'id' => '5', 'identifier' => null, 'name' => 'Sourcecode', 'keyname' => 'sourcecode', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 5 => array( 'Tagged' => array( 'tag_id' => '6' ), 'Tag' => array( 'id' => '6', 'identifier' => null, 'name' => 'Warnings', 'keyname' => 'warnings', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 6 => array( 'Tagged' => array( 'tag_id' => '7' ), 'Tag' => array( 'id' => '7', 'identifier' => null, 'name' => 'Timezone', 'keyname' => 'timezone', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 7 => array( 'Tagged' => array( 'tag_id' => '8' ), 'Tag' => array( 'id' => '8', 'identifier' => null, 'name' => 'Linux', 'keyname' => 'linux', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 8 => array( 'Tagged' => array( 'tag_id' => '9' ), 'Tag' => array( 'id' => '9', 'identifier' => null, 'name' => 'Apache', 'keyname' => 'apache', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 9 => array( 'Tagged' => array( 'tag_id' => '10' ), 'Tag' => array( 'id' => '10', 'identifier' => null, 'name' => 'Installation', 'keyname' => 'installation', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 10 => array( 'Tagged' => array( 'tag_id' => '11' ), 'Tag' => array( 'id' => '11', 'identifier' => null, 'name' => 'Open Authentication', 'keyname' => 'openauthentication', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 11 => array( 'Tagged' => array( 'tag_id' => '12' ), 'Tag' => array( 'id' => '12', 'identifier' => null, 'name' => 'Social Network Login', 'keyname' => 'socialnetworklogin', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 12 => array( 'Tagged' => array( 'tag_id' => '13' ), 'Tag' => array( 'id' => '13', 'identifier' => null, 'name' => 'oAuth', 'keyname' => 'oauth', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 13 => array( 'Tagged' => array( 'tag_id' => '14' ), 'Tag' => array( 'id' => '14', 'identifier' => null, 'name' => 'Web Developement', 'keyname' => 'webdevelopement', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 14 => array( 'Tagged' => array( 'tag_id' => '15' ), 'Tag' => array( 'id' => '15', 'identifier' => null, 'name' => 'Security', 'keyname' => 'security', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 15 => array( 'Tagged' => array( 'tag_id' => '16' ), 'Tag' => array( 'id' => '16', 'identifier' => null, 'name' => 'Code', 'keyname' => 'code', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 16 => array( 'Tagged' => array( 'tag_id' => '17' ), 'Tag' => array( 'id' => '17', 'identifier' => null, 'name' => 'Tips', 'keyname' => 'tips', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 17 => array( 'Tagged' => array( 'tag_id' => '18' ), 'Tag' => array( 'id' => '18', 'identifier' => null, 'name' => 'CSV files', 'keyname' => 'csvfiles', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 18 => array( 'Tagged' => array( 'tag_id' => '19' ), 'Tag' => array( 'id' => '19', 'identifier' => null, 'name' => 'File content', 'keyname' => 'filecontent', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 19 => array( 'Tagged' => array( 'tag_id' => '20' ), 'Tag' => array( 'id' => '20', 'identifier' => null, 'name' => 'Software Design', 'keyname' => 'softwaredesign', 'weight' => (float) 12, 'occurrence' => '2' ), (int) 0 => array( 'occurrence' => '2' ) ) ) $postcategories = array( (int) 0 => array( 'Postcategory' => array( 'id' => '5', 'parent_id' => null, 'name' => 'PHP Configuration', 'active' => '1', 'lft' => '1', 'rght' => '2', 'created' => '2015-05-06 13:24:33', 'modified' => '2015-05-06 13:24:33' ), 'ParentPostcategory' => array( 'id' => null, 'parent_id' => null, 'name' => null, 'active' => null, 'lft' => null, 'rght' => null, 'created' => null, 'modified' => null ), 'ChildPostcategory' => array(), 'Post' => array( (int) 0 => array( [maximum depth reached] ), (int) 1 => array( [maximum depth reached] ), (int) 2 => array( [maximum depth reached] ) ), 'children' => array() ), (int) 1 => array( 'Postcategory' => array( 'id' => '6', 'parent_id' => null, 'name' => 'PHP installation', 'active' => '1', 'lft' => '3', 'rght' => '4', 'created' => '2015-05-06 13:36:53', 'modified' => '2015-05-06 13:36:53' ), 'ParentPostcategory' => array( 'id' => null, 'parent_id' => null, 'name' => null, 'active' => null, 'lft' => null, 'rght' => null, 'created' => null, 'modified' => null ), 'ChildPostcategory' => array(), 'Post' => array( (int) 0 => array( [maximum depth reached] ) ), 'children' => array() ), (int) 2 => array( 'Postcategory' => array( 'id' => '7', 'parent_id' => null, 'name' => 'Web development', 'active' => '1', 'lft' => '5', 'rght' => '8', 'created' => '2015-06-06 05:44:15', 'modified' => '2015-06-06 05:44:15' ), 'ParentPostcategory' => array( 'id' => null, 'parent_id' => null, 'name' => null, 'active' => null, 'lft' => null, 'rght' => null, 'created' => null, 'modified' => null ), 'ChildPostcategory' => array( (int) 0 => array( [maximum depth reached] ) ), 'Post' => array( (int) 0 => array( [maximum depth reached] ), (int) 1 => array( [maximum depth reached] ), (int) 2 => array( [maximum depth reached] ) ), 'children' => array( (int) 0 => array( [maximum depth reached] ) ) ), (int) 3 => array( 'Postcategory' => array( 'id' => '9', 'parent_id' => null, 'name' => 'Software Design', 'active' => '1', 'lft' => '9', 'rght' => '10', 'created' => '2017-07-12 16:27:21', 'modified' => '2017-07-12 16:27:21' ), 'ParentPostcategory' => array( 'id' => null, 'parent_id' => null, 'name' => null, 'active' => null, 'lft' => null, 'rght' => null, 'created' => null, 'modified' => null ), 'ChildPostcategory' => array(), 'Post' => array( (int) 0 => array( [maximum depth reached] ), (int) 1 => array( [maximum depth reached] ) ), 'children' => array() ) ) $posts = array( (int) 0 => array( 'Post' => array( 'id' => '11', 'postcategory_id' => '8', 'user_id' => '1', 'title' => 'Connecting remote server using SSH', 'body' => '<p>SSH stands for secured shall - a secured network service over an unsecured network. It is a network protocol. It provides an encrypted data communication between two computers. SSH can be used interactively to enable terminal sessions. SSH is also used in scripts to remotely and securely access data and other resources. In order to connect to remote server with SSH, you need:</p> <p>1) Server IP or domain name</p> <p>2) Username</p> <p>3) Password</p> <p>4) SSH client - I recommend PuTTY (you can easily download from internet) for windows operating system while Linux and MAC users can use OpenSSH which is mostly installed in their OS.</p> <p><strong>Useful SSH commands frequently used by developers:</strong></p> <p><em>>_ ssh <remote_host></em></p> <p><remote_host> is an IP address or domain name that you are trying to connect to. This command assumes that your username on the remote system is the same as your username on your local system.</p> <p> <em>>_ ssh remote_username@<remote_host></em></p> <p>If your username is different on the remote system. You can specify by using this syntax.</p> <p>Once you are connected to the server, you will be asked to provide a password. SSH works by connecting a client program to an SSH server. In above commands, SSH is the client program. The SSH server is at the <em>remote_host</em> that is specified.</p> <p><strong>How to configure SSH</strong></p> <p>When you change the configuration of SSH, you are changing the settings of the sshd server. In Ubuntu, the main sshd configuration file is located at <em>/etc/ssh/sshd_config</em>.</p> <p>While it is helpful to be able to log in to a remote system using passwords, it is much better idea to set up Key-based authentication.</p> <p>Key based authentication works by creating a pair of keys: <strong>a private key</strong> and <strong>a public key.</strong></p> <p>The private key is located on the client machine. The public key is placed on any server you wish to access. Please check how to generate public and private keys with PuTTY for windows and with ssh-keygen for linux and mac OS. The folder in which the private key is placed default in the windows is c:\users\<username>\.ssh while in unix based system it is under /home/<username>/.ssh</p> <p>The public key is added to a special file within the user account you will be logging into called ~/.ssh/authorized_keys</p> <p>When you attempt to connect using a key pair, the server will use the public key to create a message for the client computer that can only be read with private key.</p> <p>The client computer then sends the appropriate response back to the server and the server will know that the client is legitimate. This entire process is done in the background after keys are correctly setup.</p> <p>SSH operates on TCP port 22 by default. The server listens on port 22 though this can be changed through custom port number in <em>sshd_config</em> file.</p> <p><em>>_ ssh -p</em> <em>7322 remote_username@<remote_host></em></p> <p>If you are not connecting <em>remote host</em> at the default port 22, then you need to specify the custom port number in the command. The above command shows remote host is being connected at the port number 7322.</p> ', 'comment_count' => '0', 'postview_count' => '1161', 'active' => '1', 'created' => '2019-11-29 13:06:49', 'modified' => '2019-11-29 13:06:49', 'tags' => 'SSH, Network, Secure' ), 'User' => array( 'id' => '1', 'firstname' => 'Chirayu' ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/ssh-connect-16148-small.jpg', 'namemedium' => '/files/uploads/postimages/ssh-connect-16148-medium.jpg' ), 'Rating' => array( (int) 0 => array( [maximum depth reached] ) ), 'Tag' => array( (int) 0 => array( [maximum depth reached] ), (int) 1 => array( [maximum depth reached] ), (int) 2 => array( [maximum depth reached] ) ), 'RatingSummary' => array( 'total_votes' => (int) 1, 'total_rating' => (float) 3.5 ) ), (int) 1 => array( 'Post' => array( 'id' => '8', 'postcategory_id' => '7', 'user_id' => '0', 'title' => 'CSV files data into php array to store in MySql', 'body' => '<p><strong><em>What are CSV files?</em></strong></p> <p>A CSV (Comma Separated Values) files are text files, allows data to be saved in a structured format. CSV files can be used with Microsoft Excel, Google Spreadsheets or Open Office Calc kind of tools. These CSV files are saved with .csv extension. In CSV files data fields are usually separated by comma as delimiter, but can also use a tab or pipe symbol instead of comma. CSV files are used to import and export data from application to application. Mostly, the first record is a header containing a list of field names. Any programming language has technique to import and export data from and to database like MS-SQL, MySql, PostGres, etc..</p> <p>PHP is one of the best programming languages for import and export of the data with the database to and from flat files like CSV files.</p> <p><strong><em>Fetching the data from the CSV file</em></strong></p> <p>Open the file in the read mode and store the content into variable. We assume that the CSV file contains the information about the contacts having fields firstname, lastname, email, and phone exported and the file name is contacts.csv.</p> <p>$csvfilehandle = fopen("contacts.csv","r");</p> <p>Here $csvfilehandle is file pointer to a file "contacts.csv" successfully opened</p> <p>while (($line = fgetcsv($csvfilehandle,1000,',','"'))!==false){</p> <p> $data[] = $line;</p> <p>}</p> <p>Close the opened file handle with </p> <p>fclose($csvfilehandle);</p> <p>The first argument $csvfilehandle is the mandatory arguments and remaining are optional.</p> <p>1000 is a length of characters per line to be set. This should be greater than the longest line in the file. If you are not sure about the length then don`t specify it.</p> <p>',' comma is a delimiter you can set or according to the data in the file the delimiter is used.</p> <p>'"' is the enclosure in the file used for the field value</p> <p>Now you have all the data of the CSV file into the array $data. If you print this with print_r($data); you get values into array.</p> <p><strong><em>Importing data into MySQL table</em></strong></p> <p>Now to import the data into the MySQL table named contacts, we need to modify the above wile loop. Let`s do that now.</p> <p>while (($line = fgetcsv($csvfilehandle,1000,',','"'))!==false){ </p> <p> mysql_query("insert into contacts(</p> <p> firstname, lastname, email, telephone</p> <p> )VALUES(</p> <p> '".mysql_real_escape_string($line[0])."',</p> <p> '".mysql_real_escape_string($line[1])."',</p> <p> '".mysql_real_escape_string($line[2])."',</p> <p> '".mysql_real_escape_string($line[3])."'</p> <p> )")</p> <p>or die(mysql_error());</p> <p>}</p> <p>fclose($csvfilehandle);</p> <p>Write me back if you are working for such functionality and not getting through the code.</p> ', 'comment_count' => '1', 'postview_count' => '1540', 'active' => '1', 'created' => '2016-11-03 07:17:48', 'modified' => '2019-11-21 06:00:03', 'tags' => 'PHP, CSV files, File content' ), 'User' => array( 'id' => null, 'firstname' => null ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/csv-files-data-into-88773-small.png', 'namemedium' => '/files/uploads/postimages/csv-files-data-into-88773-medium.png' ), 'Rating' => array( (int) 0 => array( [maximum depth reached] ) ), 'Tag' => array( (int) 0 => array( [maximum depth reached] ), (int) 1 => array( [maximum depth reached] ), (int) 2 => array( [maximum depth reached] ) ), 'RatingSummary' => array( 'total_votes' => (int) 1, 'total_rating' => (float) 2.5 ) ), (int) 2 => array( 'Post' => array( 'id' => '7', 'postcategory_id' => '7', 'user_id' => '0', 'title' => 'How the PHP script may report what is the total size of any web page browsed', 'body' => '<p>These days excellent work is being done to attract web site users by creating attractive and well managed web pages. While browsing any internet site or a web page as developer or designer of the web pages we might came across the thought, “how much size of this web page is? or how much costly to render this on my browser?”. Well today lets build a script which reports information of above questions. As usual we will be using PHP for scripting the code. This script includes two things in consideration. <strong>First,</strong> how many http/https requests are being used to render the page and <strong>Second,</strong> what is the total size of the rendered web page. We will create a script in a manner that it can be used from command line interface as well as from the browser. For this the cURL module is used. If it is not installed in your PHP set up then go to my previous article of installation and configuration of PHP.</p> <p>Ok. So now what is the meaning of <strong>First</strong> part, “how many http/https requests are”. When any web page is rendered or loaded in your browser, it is a combination of one or multiple CSS files, one or multiple javascripts or .js files, code of Html, multiple images, etc… we call them web page resources as all together they make a web page. While web page is loaded all these multiple files are being called from one or different locations with specific web address. These files are called one by one as it cannot called all once at a time. The separate calls for each of these files are known as http/https requests.</p> <p>Now let’s come to the Second part of the task – “what is the total size of the rendered web page” and that consist of file size of each of these resource we saw above. When http/https requests are responded uninterrupted then that response contains response header (developers and designers knows that). One of the headers is called “Content-Length” and that gives the size of that particular resource. We need to use built in API of PHP ie. get_headers and the argument would be the URL where the http/https request is sent. Bellow is the hint and good start of the code in PHP.</p> <p><strong><em>function file_size_rendered($url) { </em></strong></p> <p><strong><em>//where $url in the argument is the location where request is being sent.</em></strong></p> <p><strong><em> $headers = get_headers($url, 1);</em></strong> </p> <p><strong><em> if (isset($headers['Content-Length'])) </em></strong></p> <p><strong><em> return $headers['Content-Length'];</em></strong> </p> <p><strong><em>//Also check whether lower case of "L" is used in Content-length</em></strong></p> <p><strong><em> if (isset($headers['Content-length'])) </em></strong></p> <p><strong><em> return $headers['Content-length'];</em></strong></p> <p><strong><em>//if the content header is not found then use the curl request</em></strong></p> <p><strong><em> $c = curl_init();</em></strong></p> <p><strong><em> curl_setopt_array($c, array(</em></strong></p> <p><strong><em> CURLOPT_URL => $url,</em></strong></p> <p><strong><em> CURLOPT_RETURNTRANSFER => true,</em></strong></p> <p><strong><em> CURLOPT_HTTPHEADER => array('User-Agent: Mozilla/5.0 </em></strong></p> <p><strong><em> (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.3) </em></strong></p> <p><strong><em> Gecko/20090824 Firefox/3.5.3'),</em></strong></p> <p><strong><em> ));</em></strong></p> <p><strong><em> curl_exec($c);</em></strong> </p> <p><strong><em> $size = curl_getinfo($c, CURLINFO_SIZE_DOWNLOAD);</em></strong> </p> <p><strong><em> return $size;</em></strong> </p> <p><strong><em> curl_close($c);</em></strong></p> <p><strong><em>}</em></strong></p> <p>This article is just a good start to inspire for deeper understanding or the technique of coding. One can browse more or post questions to get answer on more specific tasks.</p> ', 'comment_count' => '0', 'postview_count' => '1768', 'active' => '1', 'created' => '2015-12-28 10:52:20', 'modified' => '2019-11-21 06:00:37', 'tags' => 'PHP, Code, Tips' ), 'User' => array( 'id' => null, 'firstname' => null ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/how-the-php-script-may-62903-small.jpg', 'namemedium' => '/files/uploads/postimages/how-the-php-script-may-62903-medium.jpg' ), 'Rating' => array(), 'Tag' => array( (int) 0 => array( [maximum depth reached] ), (int) 1 => array( [maximum depth reached] ), (int) 2 => array( [maximum depth reached] ) ) ), (int) 3 => array( 'Post' => array( 'id' => '6', 'postcategory_id' => '8', 'user_id' => '1', 'title' => 'Developing secured web application with PHP', 'body' => '<p>Your PHP web application is deployed on the secured platform is great but it is not just enough to consider your application is secured. It is equally or more important that your source code is also developed in the same intensity of security and passed through security testing. I would like to propose certain check list to consider before you go live with your site. PHP is considered one of the easiest languages for developing web applications and this gives chance to startup developers to leave common PHP security pitfalls in development.</p> <p>Listed out bellow are few points which can be used as a check list before you publish your web application.</p> <ul> <li><strong><em>Character encoding:</em></strong> The thumb rule is always create a valid output and use UTF-8 for the encoding like in Html, Database, Html, JS, URLs, Emails and wherever it is possible.</li> <li><strong><em>User Input Data Validation:</em></strong> Validate the user input data according to which purpose it is collected from them. It is always a good idea to validate the user input data at the PHP logic even if your JavaScript validate it at the browser itself. Type-casting is also helpful in most of the cases.</li> <li><strong><em>CSRF or XSRF – Cross Site Request Forgeries: </em></strong>a request from the different site which misuses users authenticated stat data to hack or perform unwanted operations. While user is logged in, his session data is shared across all tabs in the same browser. Code the PHP script that way it uses minimum time of GET requests or probably only to access the information rather than transactions. Avoid using $_REQUEST as much possible instead use $_GET or $_POST accordingly wherever you retrieve variables.</li> </ul> <p>Another way is to generate a random value known as token while user successfully log in at the application. Store this token value in the session and check in application logic whenever user requests or post any information.</p> <ul> <li><strong><em>XSS – Cross site scripting: </em></strong>always validate HTML inputs from user’s submitted data in case like accepting comments on the posts, or collecting reviews and display them on the site. It may use to steal session an cookie data and run kind of JS script on the browser. Use strip_tags() and /or htmlspecialchars() functions which encode and prevent users data to create an HTML tags.</li> <li><strong><em>Non-disclose of file system</em></strong>: If your website allows to download any file to its users, always use some functions which takes file path as an internal system input and use respective header() arguments to download the file. Do not create a like for the file which displays whole folder structure in the link itself to download the file.</li> <li><strong><em>Restrict the file uploads</em></strong>: a user could upload a .php extension file or any other executable file through your file upload feature on site. Check the MIME type of the uploaded file with the function like finfo_file() or any similar to validate the type of file. Create an array of allowable file extensions and keep checking with the uploaded file extension is present in the allowable array or not.</li> <li><strong><em>SQL injection</em></strong>: any input which is concatenated into a string as an SQL query is called the SQL injection. Characters like semicolon, single quote, double quote, hyphens, etc which are used in the SQL queries or statements, should be escaped. This compromise the database and it allowed to be accessed by unauthorized way. Developer can use the pair of prepare () and execute () statement to execute the query rather than simply write a row query to fire on database. Most of the new generation frameworks for PHP take care of this.</li> <li>Other security measures includes <ul style="list-style-type:circle"> <li>Use a proper error handling.</li> <li>Always use .php extensions to included files.</li> <li>Filter values of “From” header before you create that in the Email function.</li> <li>Use strong password hashing algorithm while storing the passwords.</li> <li>Encrypt the session data before you store.</li> <li>Strong cipher code to encrypt data is also a good measure.</li> </ul> </li> </ul> <p style="margin-left:.25in">Web application security measures are taken at the time of designing its architecture. Also it should not happen that steps taken from the security point of view decreases the scope of usability. Security must be implemented keeping in the mind of your website users and must be included in the development budget.</p> <p style="margin-left:.25in">This is a short tutorial for PHP developers and has just stretched the surface of the development techniques. It is up to the developer who understands the depth of vulnerabilities and possible attacks on applications over the web. Developers are required to drill more on each points which are listed and /or which are left from discussion here.</p> ', 'comment_count' => '0', 'postview_count' => '1740', 'active' => '1', 'created' => '2015-07-17 13:54:47', 'modified' => '2019-11-21 06:01:23', 'tags' => 'PHP, Web Developement, Security' ), 'User' => array( 'id' => '1', 'firstname' => 'Chirayu' ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/developing-secured-web-application-65142-small.jpg', 'namemedium' => '/files/uploads/postimages/developing-secured-web-application-65142-medium.jpg' ), 'Rating' => array( (int) 0 => array( [maximum depth reached] ), (int) 1 => array( [maximum depth reached] ) ), 'Tag' => array( (int) 0 => array( [maximum depth reached] ), (int) 1 => array( [maximum depth reached] ), (int) 2 => array( [maximum depth reached] ) ), 'RatingSummary' => array( 'total_votes' => (int) 2, 'total_rating' => (float) 4 ) ), (int) 4 => array( 'Post' => array( 'id' => '5', 'postcategory_id' => '7', 'user_id' => '1', 'title' => 'Social website login for your site is Open source standards for authorization', 'body' => '<p>You might have seen many of sites now showing links or buttons of Facebook, Twitter, Google + or other social network sites on their sign up and sign in page. This is to make users life bit easier for the login or sign up process on various websites. What happens when you click on any of that link? Have you tried anytime?</p> <p>Let’s see how you as a developer can develop this feature for your website. For this we consider a use case.</p> <p><em>User came to the sign in page of your site and he looked at the login with “facebook” or “twitter” or “google” (or any of the site) link. He has a separate account of any of these listed social network sites which you have integrated in your website. He clicks on any of the link and now he is redirected to the respective site for authentication. He provides correct credential for that social network site. He is now authenticated by that social network site and if it is for the first time he is using this authentication system, he has to agree to share his profile data with the other site from where he is coming for the authentication.</em></p> <p>When user agrees to share his profile data on successful login, that social network site redirect him to your site with user’s profile information. Of course password would not be sent to your site. This authenticating social network site will generate one token for this session and send along with the user’s profile data. This token is unique to user and your site. Now all communication and data exchange between your site and the authenticating social network site happens with this token generated by the authenticated site. Give essential profile data to your website login system and create a successful login session at your website and treat him as a logged in user.</p> <p> You can store this user information into your database and send an email to him with the new login credentials to login in your site directly in future. If he doesn’t want to login from your site directly, he still has an option to login again from the social network site which he chooses. Check every time while login weather he is the stored user with his unique field value like email address or username and if not found in your database store it and or otherwise directly give an authentication to the logged in section of your site.</p> <p>All of these redirections and authentications are made through APIs provided by these authenticating sites. Most of these sites do provide a sign in APIs but do not have the APIs for sign off from the authenticated site (There are few exceptions in this). Once user is logged in to your website through open authentication system via a different web site, he has to actually login into that website. Now when he clicks on the logout link of your site, he logs out from your site not from the site from where he was authenticated. This is risk if any user is accessing your site from the public computer and forgets to log off from the authenticated site. His account would be compromised.</p> <p>You as a developer of your site must provide information about the risk factors to your users before they use separate authentication system for your site. Developers need to create an account on these sites and get secret API key to use their APIs and use this secret key into data transactions with the site.</p> <p>Here are few providers of open authentication services are also called resource owners to authorize other web service or web site to their resources without sharing their users’ credentials.</p> <p>Amazon, Dropbox, Facebook, Flickr, GitHub, Instagram, LinkedIn, Twitter, Tumblrand …..And many of others.</p> ', 'comment_count' => '0', 'postview_count' => '2059', 'active' => '1', 'created' => '2015-06-15 08:15:29', 'modified' => '2019-11-21 06:01:51', 'tags' => 'Open Authentication, Social Network Login, oAuth' ), 'User' => array( 'id' => '1', 'firstname' => 'Chirayu' ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/social-website-login-for-65938-small.jpg', 'namemedium' => '/files/uploads/postimages/social-website-login-for-65938-medium.jpg' ), 'Rating' => array( (int) 0 => array( [maximum depth reached] ) ), 'Tag' => array( (int) 0 => array( [maximum depth reached] ), (int) 1 => array( [maximum depth reached] ), (int) 2 => array( [maximum depth reached] ) ), 'RatingSummary' => array( 'total_votes' => (int) 1, 'total_rating' => (float) 5 ) ) ) $masterclass = '' $appposts = array( (int) 0 => array( 'Post' => array( 'id' => '11', 'user_id' => '1', 'title' => 'Connecting remote server using SSH', 'body' => '<p>SSH stands for secured shall - a secured network service over an unsecured network. It is a network protocol. It provides an encrypted data communication between two computers. SSH can be used interactively to enable terminal sessions. SSH is also used in scripts to remotely and securely access data and other resources. In order to connect to remote server with SSH, you need:</p> <p>1) Server IP or domain name</p> <p>2) Username</p> <p>3) Password</p> <p>4) SSH client - I recommend PuTTY (you can easily download from internet) for windows operating system while Linux and MAC users can use OpenSSH which is mostly installed in their OS.</p> <p><strong>Useful SSH commands frequently used by developers:</strong></p> <p><em>>_ ssh <remote_host></em></p> <p><remote_host> is an IP address or domain name that you are trying to connect to. This command assumes that your username on the remote system is the same as your username on your local system.</p> <p> <em>>_ ssh remote_username@<remote_host></em></p> <p>If your username is different on the remote system. You can specify by using this syntax.</p> <p>Once you are connected to the server, you will be asked to provide a password. SSH works by connecting a client program to an SSH server. In above commands, SSH is the client program. The SSH server is at the <em>remote_host</em> that is specified.</p> <p><strong>How to configure SSH</strong></p> <p>When you change the configuration of SSH, you are changing the settings of the sshd server. In Ubuntu, the main sshd configuration file is located at <em>/etc/ssh/sshd_config</em>.</p> <p>While it is helpful to be able to log in to a remote system using passwords, it is much better idea to set up Key-based authentication.</p> <p>Key based authentication works by creating a pair of keys: <strong>a private key</strong> and <strong>a public key.</strong></p> <p>The private key is located on the client machine. The public key is placed on any server you wish to access. Please check how to generate public and private keys with PuTTY for windows and with ssh-keygen for linux and mac OS. The folder in which the private key is placed default in the windows is c:\users\<username>\.ssh while in unix based system it is under /home/<username>/.ssh</p> <p>The public key is added to a special file within the user account you will be logging into called ~/.ssh/authorized_keys</p> <p>When you attempt to connect using a key pair, the server will use the public key to create a message for the client computer that can only be read with private key.</p> <p>The client computer then sends the appropriate response back to the server and the server will know that the client is legitimate. This entire process is done in the background after keys are correctly setup.</p> <p>SSH operates on TCP port 22 by default. The server listens on port 22 though this can be changed through custom port number in <em>sshd_config</em> file.</p> <p><em>>_ ssh -p</em> <em>7322 remote_username@<remote_host></em></p> <p>If you are not connecting <em>remote host</em> at the default port 22, then you need to specify the custom port number in the command. The above command shows remote host is being connected at the port number 7322.</p> ', 'created' => '2019-11-29 13:06:49', 'tags' => '' ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/ssh-connect-16148-small.jpg', 'namemedium' => '/files/uploads/postimages/ssh-connect-16148-medium.jpg' ), 'Tofriend' => array() ), (int) 1 => array( 'Post' => array( 'id' => '10', 'user_id' => '0', 'title' => 'SOLID Part-2 : Principle of Open and Closed', 'body' => '<p>Any project has a scope of changes in terms of features, functionalities and workflows. Practically, to design application prefactly from begining is almost impossible even in the agile development. Classes and interfaces are pillers of application designs.</p> <p>SOLID is one of the proven set of design principles that are meant to guide developers to design and build robust, easily maintainable and scalable software.<br /> This article is focused ont he second principle of SOLID : The principle of Open / Closed.<br /> It satates that : Software entities (ie. classes, interfaces, functions etc) should be Open to extended but closed for modifications.<br /> Lets Check first what does it mean by this principle.</p> <p>A class is closed since it may be compiled, stored in the library, baselined and used by client classes. But it is also open, since any new class may use it as parent and adding new features.</p> <p>Fortunately we have a concept of Inheritance to achieve this goal. But, inheritance introduces tight coupling if the subclasses depend on implementation details of their parent class.</p> <p>my recomandation is to start designe inheritance with interfaces instead of superclasses. The interfaces are closed for modifications, you can provide new implementations to extend the functionality of your software.</p> <p>Let’s see an example that uses the Open/Closed Principle.</p> <p>We will need a Employee interface, the Company class, which uses the Employees, and some implementation of the Employee interface.<br /> The Company class should know just one thing about the Employees — what methods to call. This is what all the Employees have in common, so we will have a Employee interface with just the common methods(ie. someWork).</p> <p>public interface Employee{<br /> public void someWork();<br /> }</p> <p>And a Company class that encapsulates an Employye implementation and executes it.<br /> public class Company() {<br /> private Employee emp;<br /> // we set the strategy in the constructor<br /> public Company(Employee emp) {<br /> this.emp = emp;<br /> }</p> <p> public void completeTheWork() {<br /> this.emp.someWork();<br /> }<br /> }</p> <p>And let’s create two implementations for the Employee interface.</p> <p>public class Employee1 implements Employee {<br /> public void someWork() {<br /> System.out.println(“Work of Emoloyee 1”);<br /> }<br /> }</p> <p>public class Employee2 implements Employee {<br /> public void someWork() {<br /> System.out.println(“Work of Emoloyee 2”);<br /> }<br /> }</p> <p>Now lets use some dependency Injection to see how it works. We need to create one Perform class.</p> <p>public class Perform() {<br /> public static void main(String[] args) {<br /> Context context = new Company(new Employee1()); // we inject the Employee1<br /> context.completeTheWorky(); // it will print “Execute employee 1”;</p> <p> context = new Company(new Employee2()); // we inject the Employee2<br /> context.completeTheWork(); // it will print “Execute employee 2”<br /> }<br /> }</p> <p>So the Company is decoupled from a specific Employee class. You could implement many Employees it needed and no matter how they work and what you want them to do, you don’t need to modify the Company class. The Company class knows just that it must call someWork method and it is enough.</p> <p>After taking a closer look at the Single Responsibility Principle, we now discussed the Open/Closed Principle.<br /> It uses Interfaces to enable you the functionality of your application without changing the existing code.</p> ', 'created' => '2019-05-24 11:59:08', 'tags' => '' ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/Solid-part-2-28564-small.jpg', 'namemedium' => '/files/uploads/postimages/Solid-part-2-28564-medium.jpg' ), 'Tofriend' => array( (int) 0 => array( [maximum depth reached] ) ) ), (int) 2 => array( 'Post' => array( 'id' => '9', 'user_id' => '0', 'title' => 'SOLID Part-1 : Single Responsibility Principle - Software design', 'body' => '<p>S O L I D</p> <p>'S' represents Single Responsibility Principle</p> <p>Every class should have responsibility over a single part of the functionality provided by the software and that responsibility should be entirely encapsulated by the class. In other words there should never be more than one trigger or reason for a class to change. When a (functional) responsibility is divided over more than one class, all classes’ part of that responsibility has to change.</p> <p>The code must be maintainable. When we need to make a change in a class having more responsibilities the change might affect the other functionality related to the other responsibility of the class. The code, which cannot adapt to change requirements with ease, is not a well defined.</p> <p>When we design our classes, we should take care that one class at the most is responsible for doing only one task or single responsibility. Not only should the class, even operations or methods in the class defined in a way that it has only one responsibility to handle. To understand this let us take an example of Employee class. Class Employee is made with few of its attributes and operations.</p> <p>Class Employee{</p> <p> private String employeeId;</p> <p> private String name;</p> <p> private string address;</p> <p> private Date dateOfJoining;</p> <p> private Int DesignationId;</p> <p> </p> <p> public amtIncrement(){</p> <p> //increment logic implementation</p> <p> }</p> <p> public calDOR(){</p> <p> //Date of retirement logic implementation</p> <p> } </p> <p> public setDateOfJoining(){</p> <p> }</p> <p> public setEmployeeId(){</p> <p> }</p> <p> public getDateOfJoining(){</p> <p> }</p> <p> public getDesignationId(){ </p> <p> } </p> <p>}</p> <p>The above class is correctly structured and it has employee attributes declared. Also it has operations related to employee.</p> <p>Here Employee class should have only responsibility to maintain and manage the data of employee in formations. But this class is violating the principle of Single Responsibility. How?</p> <p><strong>First,</strong> the logic of calculating the Date of Retirement is not the employee's responsibility. This might be defined under the HR class and calculate by taking employee's Date of Joining in the organization which is an attribute of Employee class. So if any change happens in the HR policies, the Employee Class does not get updated. Just because HR policies updated this has nothing to do with the Employee entity.</p> <p><strong>Second,</strong> the logic of calculating the amount of increment is a responsibility of Finance class and it calculated by taking the level or designation of the employee in the organization. So if any change happens to the financial status, the Employee class doesn’t get affected with that.</p> <p>If the class has only one reason to change then it stays less fragile. More responsibilities lead to more dependencies and higher coupling. A test class for a ‘one responsibility class’ will have less test cases (branches). If a class has one purpose it will usually have less dependencies, thus less mocking and test preparing.</p> <p>The Single Responsibility Principle represents a good way of identifying classes during the design phase of an application and it reminds you to think of all the ways a class can evolve. Class and module design is highly affected by SRP and it leads to a low coupled design with less and lighter dependencies.</p> <p>Points to consider when you design the class.</p> <ul> <li>Define clearly what this class is going to do.</li> <li>Reduce the long procedures of the logic. Divide into multiple chunks.</li> <li>Write the code in the way that very small steps can be tested independently.</li> </ul> ', 'created' => '2017-07-12 16:42:05', 'tags' => '' ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/Solid-part-1-50472-small.jpg', 'namemedium' => '/files/uploads/postimages/Solid-part-1-50472-medium.jpg' ), 'Tofriend' => array( (int) 0 => array( [maximum depth reached] ), (int) 1 => array( [maximum depth reached] ), (int) 2 => array( [maximum depth reached] ) ) ), (int) 3 => array( 'Post' => array( 'id' => '8', 'user_id' => '0', 'title' => 'CSV files data into php array to store in MySql', 'body' => '<p><strong><em>What are CSV files?</em></strong></p> <p>A CSV (Comma Separated Values) files are text files, allows data to be saved in a structured format. CSV files can be used with Microsoft Excel, Google Spreadsheets or Open Office Calc kind of tools. These CSV files are saved with .csv extension. In CSV files data fields are usually separated by comma as delimiter, but can also use a tab or pipe symbol instead of comma. CSV files are used to import and export data from application to application. Mostly, the first record is a header containing a list of field names. Any programming language has technique to import and export data from and to database like MS-SQL, MySql, PostGres, etc..</p> <p>PHP is one of the best programming languages for import and export of the data with the database to and from flat files like CSV files.</p> <p><strong><em>Fetching the data from the CSV file</em></strong></p> <p>Open the file in the read mode and store the content into variable. We assume that the CSV file contains the information about the contacts having fields firstname, lastname, email, and phone exported and the file name is contacts.csv.</p> <p>$csvfilehandle = fopen("contacts.csv","r");</p> <p>Here $csvfilehandle is file pointer to a file "contacts.csv" successfully opened</p> <p>while (($line = fgetcsv($csvfilehandle,1000,',','"'))!==false){</p> <p> $data[] = $line;</p> <p>}</p> <p>Close the opened file handle with </p> <p>fclose($csvfilehandle);</p> <p>The first argument $csvfilehandle is the mandatory arguments and remaining are optional.</p> <p>1000 is a length of characters per line to be set. This should be greater than the longest line in the file. If you are not sure about the length then don`t specify it.</p> <p>',' comma is a delimiter you can set or according to the data in the file the delimiter is used.</p> <p>'"' is the enclosure in the file used for the field value</p> <p>Now you have all the data of the CSV file into the array $data. If you print this with print_r($data); you get values into array.</p> <p><strong><em>Importing data into MySQL table</em></strong></p> <p>Now to import the data into the MySQL table named contacts, we need to modify the above wile loop. Let`s do that now.</p> <p>while (($line = fgetcsv($csvfilehandle,1000,',','"'))!==false){ </p> <p> mysql_query("insert into contacts(</p> <p> firstname, lastname, email, telephone</p> <p> )VALUES(</p> <p> '".mysql_real_escape_string($line[0])."',</p> <p> '".mysql_real_escape_string($line[1])."',</p> <p> '".mysql_real_escape_string($line[2])."',</p> <p> '".mysql_real_escape_string($line[3])."'</p> <p> )")</p> <p>or die(mysql_error());</p> <p>}</p> <p>fclose($csvfilehandle);</p> <p>Write me back if you are working for such functionality and not getting through the code.</p> ', 'created' => '2016-11-03 07:17:48', 'tags' => '' ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/csv-files-data-into-88773-small.png', 'namemedium' => '/files/uploads/postimages/csv-files-data-into-88773-medium.png' ), 'Tofriend' => array() ), (int) 4 => array( 'Post' => array( 'id' => '7', 'user_id' => '0', 'title' => 'How the PHP script may report what is the total size of any web page browsed', 'body' => '<p>These days excellent work is being done to attract web site users by creating attractive and well managed web pages. While browsing any internet site or a web page as developer or designer of the web pages we might came across the thought, “how much size of this web page is? or how much costly to render this on my browser?”. Well today lets build a script which reports information of above questions. As usual we will be using PHP for scripting the code. This script includes two things in consideration. <strong>First,</strong> how many http/https requests are being used to render the page and <strong>Second,</strong> what is the total size of the rendered web page. We will create a script in a manner that it can be used from command line interface as well as from the browser. For this the cURL module is used. If it is not installed in your PHP set up then go to my previous article of installation and configuration of PHP.</p> <p>Ok. So now what is the meaning of <strong>First</strong> part, “how many http/https requests are”. When any web page is rendered or loaded in your browser, it is a combination of one or multiple CSS files, one or multiple javascripts or .js files, code of Html, multiple images, etc… we call them web page resources as all together they make a web page. While web page is loaded all these multiple files are being called from one or different locations with specific web address. These files are called one by one as it cannot called all once at a time. The separate calls for each of these files are known as http/https requests.</p> <p>Now let’s come to the Second part of the task – “what is the total size of the rendered web page” and that consist of file size of each of these resource we saw above. When http/https requests are responded uninterrupted then that response contains response header (developers and designers knows that). One of the headers is called “Content-Length” and that gives the size of that particular resource. We need to use built in API of PHP ie. get_headers and the argument would be the URL where the http/https request is sent. Bellow is the hint and good start of the code in PHP.</p> <p><strong><em>function file_size_rendered($url) { </em></strong></p> <p><strong><em>//where $url in the argument is the location where request is being sent.</em></strong></p> <p><strong><em> $headers = get_headers($url, 1);</em></strong> </p> <p><strong><em> if (isset($headers['Content-Length'])) </em></strong></p> <p><strong><em> return $headers['Content-Length'];</em></strong> </p> <p><strong><em>//Also check whether lower case of "L" is used in Content-length</em></strong></p> <p><strong><em> if (isset($headers['Content-length'])) </em></strong></p> <p><strong><em> return $headers['Content-length'];</em></strong></p> <p><strong><em>//if the content header is not found then use the curl request</em></strong></p> <p><strong><em> $c = curl_init();</em></strong></p> <p><strong><em> curl_setopt_array($c, array(</em></strong></p> <p><strong><em> CURLOPT_URL => $url,</em></strong></p> <p><strong><em> CURLOPT_RETURNTRANSFER => true,</em></strong></p> <p><strong><em> CURLOPT_HTTPHEADER => array('User-Agent: Mozilla/5.0 </em></strong></p> <p><strong><em> (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.3) </em></strong></p> <p><strong><em> Gecko/20090824 Firefox/3.5.3'),</em></strong></p> <p><strong><em> ));</em></strong></p> <p><strong><em> curl_exec($c);</em></strong> </p> <p><strong><em> $size = curl_getinfo($c, CURLINFO_SIZE_DOWNLOAD);</em></strong> </p> <p><strong><em> return $size;</em></strong> </p> <p><strong><em> curl_close($c);</em></strong></p> <p><strong><em>}</em></strong></p> <p>This article is just a good start to inspire for deeper understanding or the technique of coding. One can browse more or post questions to get answer on more specific tasks.</p> ', 'created' => '2015-12-28 10:52:20', 'tags' => '' ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/how-the-php-script-may-62903-small.jpg', 'namemedium' => '/files/uploads/postimages/how-the-php-script-may-62903-medium.jpg' ), 'Tofriend' => array() ) ) $regions = array() $appcountries = array( (int) 1 => 'Andorra', (int) 2 => 'United Arab Emirates', (int) 3 => 'Afghanistan', (int) 4 => 'Antigua and Barbuda', (int) 5 => 'Anguilla', (int) 6 => 'Albania', (int) 7 => 'Armenia', (int) 8 => 'Netherlands Antilles', (int) 9 => 'Angola', (int) 12 => 'Argentina', (int) 13 => 'American Samoa', (int) 14 => 'Austria', (int) 15 => 'Australia', (int) 16 => 'Aruba', (int) 17 => 'Azerbaijan', (int) 18 => 'Bosnia and Herzegovina', (int) 19 => 'Barbados', (int) 20 => 'Bangladesh', (int) 21 => 'Belgium', (int) 22 => 'Burkina Faso', (int) 23 => 'Bulgaria', (int) 24 => 'Bahrain', (int) 25 => 'Burundi', (int) 26 => 'Benin', (int) 27 => 'Bermuda', (int) 28 => 'Brunei Darussalam', (int) 29 => 'Bolivia', (int) 30 => 'Brazil', (int) 31 => 'Bahamas', (int) 32 => 'Bhutan', (int) 34 => 'Botswana', (int) 35 => 'Belarus', (int) 36 => 'Belize', (int) 37 => 'Canada', (int) 38 => 'Cocos (Keeling) Islands', (int) 40 => 'Central African Republic', (int) 41 => 'Congo', (int) 42 => 'Switzerland', (int) 43 => 'Cote D'Ivoire', (int) 44 => 'Cook Islands', (int) 45 => 'Chile', (int) 46 => 'Cameroon', (int) 47 => 'China', (int) 48 => 'Colombia', (int) 49 => 'Costa Rica', (int) 51 => 'Cuba', (int) 52 => 'Cape Verde', (int) 53 => 'Christmas Island', (int) 54 => 'Cyprus', (int) 55 => 'Czech Republic', (int) 56 => 'Germany', (int) 57 => 'Djibouti', (int) 58 => 'Denmark', (int) 59 => 'Dominica', (int) 60 => 'Dominican Republic', (int) 61 => 'Algeria', (int) 62 => 'Ecuador', (int) 63 => 'Estonia', (int) 64 => 'Egypt', (int) 65 => 'Western Sahara', (int) 66 => 'Eritrea', (int) 67 => 'Spain', (int) 68 => 'Ethiopia', (int) 70 => 'Finland', (int) 71 => 'Fiji', (int) 72 => 'Falkland Islands (Malvinas)', (int) 73 => 'Micronesia, Federated States of', (int) 74 => 'Faroe Islands', (int) 75 => 'France', (int) 77 => 'Gabon', (int) 78 => 'United Kingdom', (int) 79 => 'Grenada', (int) 80 => 'Georgia', (int) 81 => 'French Guiana', (int) 82 => 'Ghana', (int) 83 => 'Gibraltar', (int) 84 => 'Greenland', (int) 85 => 'Gambia', (int) 86 => 'Guinea', (int) 87 => 'Guadeloupe', (int) 88 => 'Equatorial Guinea', (int) 89 => 'Greece', (int) 90 => 'South Georgia and Sandwich Island', (int) 91 => 'Guatemala', (int) 93 => 'Guinea-Bissau', (int) 94 => 'Guyana', (int) 95 => 'Hong Kong', (int) 97 => 'Honduras', (int) 98 => 'Croatia', (int) 99 => 'Haiti', (int) 100 => 'Hungary', (int) 101 => 'Indonesia', (int) 102 => 'Ireland', (int) 103 => 'Israel', (int) 104 => 'India', (int) 106 => 'Iraq', (int) 107 => 'Iran, Islamic Republic of', (int) 108 => 'Iceland', (int) 109 => 'Italy', (int) 110 => 'Jamaica', (int) 111 => 'Jordan', (int) 112 => 'Japan', (int) 113 => 'Kenya', (int) 114 => 'Kyrgyzstan', (int) 115 => 'Cambodia', (int) 116 => 'Kiribati', (int) 117 => 'Comoros', (int) 118 => 'Saint Kitts and Nevis', (int) 119 => 'Korea, Democratic', (int) 120 => 'Korea, Republic of', (int) 121 => 'Kuwait', (int) 122 => 'Cayman Islands', (int) 123 => 'Kazakhstan', (int) 124 => 'Laos', (int) 125 => 'Lebanon', (int) 126 => 'Saint Lucia', (int) 127 => 'Liechtenstein', (int) 128 => 'Sri Lanka', (int) 129 => 'Liberia', (int) 130 => 'Lesotho', (int) 131 => 'Lithuania', (int) 132 => 'Luxembourg', (int) 133 => 'Latvia', (int) 134 => 'Libya', (int) 135 => 'Morocco', (int) 136 => 'Monaco', (int) 137 => 'Moldova', (int) 138 => 'Madagascar', (int) 139 => 'Marshall Islands', (int) 140 => 'Macedonia', (int) 141 => 'Mali', (int) 142 => 'Myanmar', (int) 143 => 'Mongolia', (int) 144 => 'Macau', (int) 145 => 'Northern Mariana Islands', (int) 146 => 'Martinique', (int) 147 => 'Mauritania', (int) 148 => 'Montserrat', (int) 149 => 'Malta', (int) 150 => 'Mauritius', (int) 151 => 'Maldives', (int) 152 => 'Malawi', (int) 153 => 'Mexico', (int) 154 => 'Malaysia', (int) 155 => 'Mozambique', (int) 156 => 'Namibia', (int) 157 => 'New Caledonia', (int) 158 => 'Niger', (int) 159 => 'Norfolk Island', (int) 160 => 'Nigeria', (int) 161 => 'Nicaragua', (int) 162 => 'Netherlands', (int) 163 => 'Norway', (int) 164 => 'Nepal', (int) 165 => 'Nauru', (int) 166 => 'Niue', (int) 167 => 'New Zealand', (int) 168 => 'Oman', (int) 169 => 'Panama', (int) 170 => 'Peru', (int) 171 => 'French Polynesia', (int) 172 => 'Papua New Guinea', (int) 173 => 'Philippines', (int) 174 => 'Pakistan', (int) 175 => 'Poland', (int) 176 => 'Saint Pierre and Miquelon', (int) 177 => 'Pitcairn', (int) 180 => 'Portugal', (int) 181 => 'Palau', (int) 182 => 'Paraguay', (int) 183 => 'Qatar', (int) 184 => 'Reunion', (int) 185 => 'Romania', (int) 186 => 'Russian Federation', (int) 187 => 'Rwanda', (int) 188 => 'Saudi Arabia', (int) 189 => 'Solomon Islands', (int) 190 => 'Seychelles', (int) 191 => 'Sudan', (int) 192 => 'Sweden', (int) 193 => 'Singapore', (int) 194 => 'Saint Helena', (int) 195 => 'Slovenia', (int) 196 => 'Svalbard and Jan Mayen', (int) 197 => 'Slovakia', (int) 198 => 'Sierra Leone', (int) 199 => 'San Marino', (int) 200 => 'Senegal', (int) 201 => 'Somalia', (int) 202 => 'Suriname', (int) 203 => 'Sao Tome and Principe', (int) 204 => 'El Salvador', (int) 205 => 'Syrian Arab Republic', (int) 206 => 'Swaziland', (int) 207 => 'Turks and Caicos Islands', (int) 208 => 'Chad', (int) 209 => 'French Southern Territories', (int) 210 => 'Togo', (int) 211 => 'Thailand', (int) 212 => 'Tajikistan', (int) 213 => 'Tokelau', (int) 215 => 'Turkmenistan', (int) 216 => 'Tunisia', (int) 217 => 'Tonga', (int) 218 => 'Turkey', (int) 219 => 'Trinidad and Tobago', (int) 220 => 'Tuvalu', (int) 221 => 'Taiwan', (int) 222 => 'Tanzania, United Republic', (int) 223 => 'Ukraine', (int) 224 => 'Uganda', (int) 226 => 'United States', (int) 227 => 'Uruguay', (int) 228 => 'Uzbekistan', (int) 230 => 'Saint Vincent and the Grenadines', (int) 231 => 'Venezuela', (int) 232 => 'Virgin Islands, British', (int) 233 => 'Virgin Islands, U.S.', (int) 234 => 'Vietnam', (int) 235 => 'Vanuatu', (int) 236 => 'Wallis and Futuna', (int) 237 => 'Samoa', (int) 238 => 'Yemen', (int) 239 => 'Mayotte', (int) 240 => 'South Africa', (int) 241 => 'Zambia', (int) 242 => 'Zaire', (int) 243 => 'Zimbabwe' ) $data = array( 'Post' => array( 'id' => '8', 'postcategory_id' => '7', 'user_id' => '0', 'title' => 'CSV files data into php array to store in MySql', 'body' => '<p><strong><em>What are CSV files?</em></strong></p> <p>A CSV (Comma Separated Values) files are text files, allows data to be saved in a structured format. CSV files can be used with Microsoft Excel, Google Spreadsheets or Open Office Calc kind of tools. These CSV files are saved with .csv extension. In CSV files data fields are usually separated by comma as delimiter, but can also use a tab or pipe symbol instead of comma. CSV files are used to import and export data from application to application. Mostly, the first record is a header containing a list of field names. Any programming language has technique to import and export data from and to database like MS-SQL, MySql, PostGres, etc..</p> <p>PHP is one of the best programming languages for import and export of the data with the database to and from flat files like CSV files.</p> <p><strong><em>Fetching the data from the CSV file</em></strong></p> <p>Open the file in the read mode and store the content into variable. We assume that the CSV file contains the information about the contacts having fields firstname, lastname, email, and phone exported and the file name is contacts.csv.</p> <p>$csvfilehandle = fopen("contacts.csv","r");</p> <p>Here $csvfilehandle is file pointer to a file "contacts.csv" successfully opened</p> <p>while (($line = fgetcsv($csvfilehandle,1000,',','"'))!==false){</p> <p> $data[] = $line;</p> <p>}</p> <p>Close the opened file handle with </p> <p>fclose($csvfilehandle);</p> <p>The first argument $csvfilehandle is the mandatory arguments and remaining are optional.</p> <p>1000 is a length of characters per line to be set. This should be greater than the longest line in the file. If you are not sure about the length then don`t specify it.</p> <p>',' comma is a delimiter you can set or according to the data in the file the delimiter is used.</p> <p>'"' is the enclosure in the file used for the field value</p> <p>Now you have all the data of the CSV file into the array $data. If you print this with print_r($data); you get values into array.</p> <p><strong><em>Importing data into MySQL table</em></strong></p> <p>Now to import the data into the MySQL table named contacts, we need to modify the above wile loop. Let`s do that now.</p> <p>while (($line = fgetcsv($csvfilehandle,1000,',','"'))!==false){ </p> <p> mysql_query("insert into contacts(</p> <p> firstname, lastname, email, telephone</p> <p> )VALUES(</p> <p> '".mysql_real_escape_string($line[0])."',</p> <p> '".mysql_real_escape_string($line[1])."',</p> <p> '".mysql_real_escape_string($line[2])."',</p> <p> '".mysql_real_escape_string($line[3])."'</p> <p> )")</p> <p>or die(mysql_error());</p> <p>}</p> <p>fclose($csvfilehandle);</p> <p>Write me back if you are working for such functionality and not getting through the code.</p> ', 'comment_count' => '1', 'postview_count' => '1540', 'active' => '1', 'created' => '2016-11-03 07:17:48', 'modified' => '2019-11-21 06:00:03', 'tags' => 'PHP, CSV files, File content' ), 'User' => array( 'id' => null, 'firstname' => null ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/csv-files-data-into-88773-small.png', 'namemedium' => '/files/uploads/postimages/csv-files-data-into-88773-medium.png' ), 'Rating' => array( (int) 0 => array( 'id' => '7', 'foreign_model' => 'Post', 'foreign_id' => '8', 'author_ip' => '49.34.160.19', 'rating' => '2.5', 'created' => '2016-11-03 07:18:34' ) ), 'Tag' => array( (int) 0 => array( 'id' => '4', 'name' => 'PHP', 'keyname' => 'php', 'Tagged' => array( [maximum depth reached] ) ), (int) 1 => array( 'id' => '18', 'name' => 'CSV files', 'keyname' => 'csvfiles', 'Tagged' => array( [maximum depth reached] ) ), (int) 2 => array( 'id' => '19', 'name' => 'File content', 'keyname' => 'filecontent', 'Tagged' => array( [maximum depth reached] ) ) ), 'RatingSummary' => array( 'total_votes' => (int) 1, 'total_rating' => (float) 2.5 ) ) $model = null $modelClass = null $submit_url = '/feedback/ratings/add' $element_id = 'rating-2065393822' $message_id = 'message-2065393822' $values_id = 'values-2065393822' $readonly = 'false' $value = (float) 2.5 $votes = (float) 1 $user_vote = (int) 0 $user_vote_message = 'Your vote: 0.0' $submitting_message = 'Sending vote...' $error_message = 'There was an error while saving your vote'include - APP/Plugin/Feedback/View/Elements/rating.ctp, line 59 View::_evaluate() - CORE/Cake/View/View.php, line 971 View::_render() - CORE/Cake/View/View.php, line 933 View::_renderElement() - CORE/Cake/View/View.php, line 1224 View::element() - CORE/Cake/View/View.php, line 418 RatingsHelper::display_for() - APP/Plugin/Feedback/View/Helper/RatingsHelper.php, line 53 include - APP/View/Posts/filter.ctp, line 30 View::_evaluate() - CORE/Cake/View/View.php, line 971 View::_render() - CORE/Cake/View/View.php, line 933 View::render() - CORE/Cake/View/View.php, line 473 Controller::render() - CORE/Cake/Controller/Controller.php, line 963 Dispatcher::_invoke() - CORE/Cake/Routing/Dispatcher.php, line 200 Dispatcher::dispatch() - CORE/Cake/Routing/Dispatcher.php, line 167 [main] - APP/webroot/index.php, line 109
How the PHP script may report what is the total size of any web pag...
Warning (2): key() expects parameter 1 to be array, null given [APP/Plugin/Feedback/View/Helper/RatingsHelper.php, line 73]Code Contextif (empty($model) && empty($modelClass))
{
$modelClass = key($this->models);
$data = array( 'Post' => array( 'id' => '7', 'postcategory_id' => '7', 'user_id' => '0', 'title' => 'How the PHP script may report what is the total size of any web page browsed', 'body' => '<p>These days excellent work is being done to attract web site users by creating attractive and well managed web pages. While browsing any internet site or a web page as developer or designer of the web pages we might came across the thought, “how much size of this web page is? or how much costly to render this on my browser?”. Well today lets build a script which reports information of above questions. As usual we will be using PHP for scripting the code. This script includes two things in consideration. <strong>First,</strong> how many http/https requests are being used to render the page and <strong>Second,</strong> what is the total size of the rendered web page. We will create a script in a manner that it can be used from command line interface as well as from the browser. For this the cURL module is used. If it is not installed in your PHP set up then go to my previous article of installation and configuration of PHP.</p> <p>Ok. So now what is the meaning of <strong>First</strong> part, “how many http/https requests are”. When any web page is rendered or loaded in your browser, it is a combination of one or multiple CSS files, one or multiple javascripts or .js files, code of Html, multiple images, etc… we call them web page resources as all together they make a web page. While web page is loaded all these multiple files are being called from one or different locations with specific web address. These files are called one by one as it cannot called all once at a time. The separate calls for each of these files are known as http/https requests.</p> <p>Now let’s come to the Second part of the task – “what is the total size of the rendered web page” and that consist of file size of each of these resource we saw above. When http/https requests are responded uninterrupted then that response contains response header (developers and designers knows that). One of the headers is called “Content-Length” and that gives the size of that particular resource. We need to use built in API of PHP ie. get_headers and the argument would be the URL where the http/https request is sent. Bellow is the hint and good start of the code in PHP.</p> <p><strong><em>function file_size_rendered($url) { </em></strong></p> <p><strong><em>//where $url in the argument is the location where request is being sent.</em></strong></p> <p><strong><em> $headers = get_headers($url, 1);</em></strong> </p> <p><strong><em> if (isset($headers['Content-Length'])) </em></strong></p> <p><strong><em> return $headers['Content-Length'];</em></strong> </p> <p><strong><em>//Also check whether lower case of "L" is used in Content-length</em></strong></p> <p><strong><em> if (isset($headers['Content-length'])) </em></strong></p> <p><strong><em> return $headers['Content-length'];</em></strong></p> <p><strong><em>//if the content header is not found then use the curl request</em></strong></p> <p><strong><em> $c = curl_init();</em></strong></p> <p><strong><em> curl_setopt_array($c, array(</em></strong></p> <p><strong><em> CURLOPT_URL => $url,</em></strong></p> <p><strong><em> CURLOPT_RETURNTRANSFER => true,</em></strong></p> <p><strong><em> CURLOPT_HTTPHEADER => array('User-Agent: Mozilla/5.0 </em></strong></p> <p><strong><em> (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.3) </em></strong></p> <p><strong><em> Gecko/20090824 Firefox/3.5.3'),</em></strong></p> <p><strong><em> ));</em></strong></p> <p><strong><em> curl_exec($c);</em></strong> </p> <p><strong><em> $size = curl_getinfo($c, CURLINFO_SIZE_DOWNLOAD);</em></strong> </p> <p><strong><em> return $size;</em></strong> </p> <p><strong><em> curl_close($c);</em></strong></p> <p><strong><em>}</em></strong></p> <p>This article is just a good start to inspire for deeper understanding or the technique of coding. One can browse more or post questions to get answer on more specific tasks.</p> ', 'comment_count' => '0', 'postview_count' => '1768', 'active' => '1', 'created' => '2015-12-28 10:52:20', 'modified' => '2019-11-21 06:00:37', 'tags' => 'PHP, Code, Tips' ), 'User' => array( 'id' => null, 'firstname' => null ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/how-the-php-script-may-62903-small.jpg', 'namemedium' => '/files/uploads/postimages/how-the-php-script-may-62903-medium.jpg' ), 'Rating' => array(), 'Tag' => array( (int) 0 => array( 'id' => '4', 'name' => 'PHP', 'keyname' => 'php', 'Tagged' => array( [maximum depth reached] ) ), (int) 1 => array( 'id' => '16', 'name' => 'Code', 'keyname' => 'code', 'Tagged' => array( [maximum depth reached] ) ), (int) 2 => array( 'id' => '17', 'name' => 'Tips', 'keyname' => 'tips', 'Tagged' => array( [maximum depth reached] ) ) ) ) $options = array() $model = null $modelClass = nullkey - [internal], line ?? RatingsHelper::prepareParams() - APP/Plugin/Feedback/View/Helper/RatingsHelper.php, line 73 RatingsHelper::display_for() - APP/Plugin/Feedback/View/Helper/RatingsHelper.php, line 48 include - APP/View/Posts/filter.ctp, line 30 View::_evaluate() - CORE/Cake/View/View.php, line 971 View::_render() - CORE/Cake/View/View.php, line 933 View::render() - CORE/Cake/View/View.php, line 473 Controller::render() - CORE/Cake/Controller/Controller.php, line 963 Dispatcher::_invoke() - CORE/Cake/Routing/Dispatcher.php, line 200 Dispatcher::dispatch() - CORE/Cake/Routing/Dispatcher.php, line 167 [main] - APP/webroot/index.php, line 109
Warning (2): current() expects parameter 1 to be array, null given [APP/Plugin/Feedback/View/Helper/RatingsHelper.php, line 74]Code Context{
$modelClass = key($this->models);
$model = current($this->models);
$data = array( 'Post' => array( 'id' => '7', 'postcategory_id' => '7', 'user_id' => '0', 'title' => 'How the PHP script may report what is the total size of any web page browsed', 'body' => '<p>These days excellent work is being done to attract web site users by creating attractive and well managed web pages. While browsing any internet site or a web page as developer or designer of the web pages we might came across the thought, “how much size of this web page is? or how much costly to render this on my browser?”. Well today lets build a script which reports information of above questions. As usual we will be using PHP for scripting the code. This script includes two things in consideration. <strong>First,</strong> how many http/https requests are being used to render the page and <strong>Second,</strong> what is the total size of the rendered web page. We will create a script in a manner that it can be used from command line interface as well as from the browser. For this the cURL module is used. If it is not installed in your PHP set up then go to my previous article of installation and configuration of PHP.</p> <p>Ok. So now what is the meaning of <strong>First</strong> part, “how many http/https requests are”. When any web page is rendered or loaded in your browser, it is a combination of one or multiple CSS files, one or multiple javascripts or .js files, code of Html, multiple images, etc… we call them web page resources as all together they make a web page. While web page is loaded all these multiple files are being called from one or different locations with specific web address. These files are called one by one as it cannot called all once at a time. The separate calls for each of these files are known as http/https requests.</p> <p>Now let’s come to the Second part of the task – “what is the total size of the rendered web page” and that consist of file size of each of these resource we saw above. When http/https requests are responded uninterrupted then that response contains response header (developers and designers knows that). One of the headers is called “Content-Length” and that gives the size of that particular resource. We need to use built in API of PHP ie. get_headers and the argument would be the URL where the http/https request is sent. Bellow is the hint and good start of the code in PHP.</p> <p><strong><em>function file_size_rendered($url) { </em></strong></p> <p><strong><em>//where $url in the argument is the location where request is being sent.</em></strong></p> <p><strong><em> $headers = get_headers($url, 1);</em></strong> </p> <p><strong><em> if (isset($headers['Content-Length'])) </em></strong></p> <p><strong><em> return $headers['Content-Length'];</em></strong> </p> <p><strong><em>//Also check whether lower case of "L" is used in Content-length</em></strong></p> <p><strong><em> if (isset($headers['Content-length'])) </em></strong></p> <p><strong><em> return $headers['Content-length'];</em></strong></p> <p><strong><em>//if the content header is not found then use the curl request</em></strong></p> <p><strong><em> $c = curl_init();</em></strong></p> <p><strong><em> curl_setopt_array($c, array(</em></strong></p> <p><strong><em> CURLOPT_URL => $url,</em></strong></p> <p><strong><em> CURLOPT_RETURNTRANSFER => true,</em></strong></p> <p><strong><em> CURLOPT_HTTPHEADER => array('User-Agent: Mozilla/5.0 </em></strong></p> <p><strong><em> (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.3) </em></strong></p> <p><strong><em> Gecko/20090824 Firefox/3.5.3'),</em></strong></p> <p><strong><em> ));</em></strong></p> <p><strong><em> curl_exec($c);</em></strong> </p> <p><strong><em> $size = curl_getinfo($c, CURLINFO_SIZE_DOWNLOAD);</em></strong> </p> <p><strong><em> return $size;</em></strong> </p> <p><strong><em> curl_close($c);</em></strong></p> <p><strong><em>}</em></strong></p> <p>This article is just a good start to inspire for deeper understanding or the technique of coding. One can browse more or post questions to get answer on more specific tasks.</p> ', 'comment_count' => '0', 'postview_count' => '1768', 'active' => '1', 'created' => '2015-12-28 10:52:20', 'modified' => '2019-11-21 06:00:37', 'tags' => 'PHP, Code, Tips' ), 'User' => array( 'id' => null, 'firstname' => null ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/how-the-php-script-may-62903-small.jpg', 'namemedium' => '/files/uploads/postimages/how-the-php-script-may-62903-medium.jpg' ), 'Rating' => array(), 'Tag' => array( (int) 0 => array( 'id' => '4', 'name' => 'PHP', 'keyname' => 'php', 'Tagged' => array( [maximum depth reached] ) ), (int) 1 => array( 'id' => '16', 'name' => 'Code', 'keyname' => 'code', 'Tagged' => array( [maximum depth reached] ) ), (int) 2 => array( 'id' => '17', 'name' => 'Tips', 'keyname' => 'tips', 'Tagged' => array( [maximum depth reached] ) ) ) ) $options = array() $model = null $modelClass = nullcurrent - [internal], line ?? RatingsHelper::prepareParams() - APP/Plugin/Feedback/View/Helper/RatingsHelper.php, line 74 RatingsHelper::display_for() - APP/Plugin/Feedback/View/Helper/RatingsHelper.php, line 48 include - APP/View/Posts/filter.ctp, line 30 View::_evaluate() - CORE/Cake/View/View.php, line 971 View::_render() - CORE/Cake/View/View.php, line 933 View::render() - CORE/Cake/View/View.php, line 473 Controller::render() - CORE/Cake/Controller/Controller.php, line 963 Dispatcher::_invoke() - CORE/Cake/Routing/Dispatcher.php, line 200 Dispatcher::dispatch() - CORE/Cake/Routing/Dispatcher.php, line 167 [main] - APP/webroot/index.php, line 109
Notice (8): Undefined index: [APP/Plugin/Feedback/View/Helper/RatingsHelper.php, line 81]Code Context$message_id = 'message-'.$random_id;
$values_id = 'values-'.$random_id;
$id = $data[$modelClass]['id'];
$data = array( 'Post' => array( 'id' => '7', 'postcategory_id' => '7', 'user_id' => '0', 'title' => 'How the PHP script may report what is the total size of any web page browsed', 'body' => '<p>These days excellent work is being done to attract web site users by creating attractive and well managed web pages. While browsing any internet site or a web page as developer or designer of the web pages we might came across the thought, “how much size of this web page is? or how much costly to render this on my browser?”. Well today lets build a script which reports information of above questions. As usual we will be using PHP for scripting the code. This script includes two things in consideration. <strong>First,</strong> how many http/https requests are being used to render the page and <strong>Second,</strong> what is the total size of the rendered web page. We will create a script in a manner that it can be used from command line interface as well as from the browser. For this the cURL module is used. If it is not installed in your PHP set up then go to my previous article of installation and configuration of PHP.</p> <p>Ok. So now what is the meaning of <strong>First</strong> part, “how many http/https requests are”. When any web page is rendered or loaded in your browser, it is a combination of one or multiple CSS files, one or multiple javascripts or .js files, code of Html, multiple images, etc… we call them web page resources as all together they make a web page. While web page is loaded all these multiple files are being called from one or different locations with specific web address. These files are called one by one as it cannot called all once at a time. The separate calls for each of these files are known as http/https requests.</p> <p>Now let’s come to the Second part of the task – “what is the total size of the rendered web page” and that consist of file size of each of these resource we saw above. When http/https requests are responded uninterrupted then that response contains response header (developers and designers knows that). One of the headers is called “Content-Length” and that gives the size of that particular resource. We need to use built in API of PHP ie. get_headers and the argument would be the URL where the http/https request is sent. Bellow is the hint and good start of the code in PHP.</p> <p><strong><em>function file_size_rendered($url) { </em></strong></p> <p><strong><em>//where $url in the argument is the location where request is being sent.</em></strong></p> <p><strong><em> $headers = get_headers($url, 1);</em></strong> </p> <p><strong><em> if (isset($headers['Content-Length'])) </em></strong></p> <p><strong><em> return $headers['Content-Length'];</em></strong> </p> <p><strong><em>//Also check whether lower case of "L" is used in Content-length</em></strong></p> <p><strong><em> if (isset($headers['Content-length'])) </em></strong></p> <p><strong><em> return $headers['Content-length'];</em></strong></p> <p><strong><em>//if the content header is not found then use the curl request</em></strong></p> <p><strong><em> $c = curl_init();</em></strong></p> <p><strong><em> curl_setopt_array($c, array(</em></strong></p> <p><strong><em> CURLOPT_URL => $url,</em></strong></p> <p><strong><em> CURLOPT_RETURNTRANSFER => true,</em></strong></p> <p><strong><em> CURLOPT_HTTPHEADER => array('User-Agent: Mozilla/5.0 </em></strong></p> <p><strong><em> (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.3) </em></strong></p> <p><strong><em> Gecko/20090824 Firefox/3.5.3'),</em></strong></p> <p><strong><em> ));</em></strong></p> <p><strong><em> curl_exec($c);</em></strong> </p> <p><strong><em> $size = curl_getinfo($c, CURLINFO_SIZE_DOWNLOAD);</em></strong> </p> <p><strong><em> return $size;</em></strong> </p> <p><strong><em> curl_close($c);</em></strong></p> <p><strong><em>}</em></strong></p> <p>This article is just a good start to inspire for deeper understanding or the technique of coding. One can browse more or post questions to get answer on more specific tasks.</p> ', 'comment_count' => '0', 'postview_count' => '1768', 'active' => '1', 'created' => '2015-12-28 10:52:20', 'modified' => '2019-11-21 06:00:37', 'tags' => 'PHP, Code, Tips' ), 'User' => array( 'id' => null, 'firstname' => null ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/how-the-php-script-may-62903-small.jpg', 'namemedium' => '/files/uploads/postimages/how-the-php-script-may-62903-medium.jpg' ), 'Rating' => array(), 'Tag' => array( (int) 0 => array( 'id' => '4', 'name' => 'PHP', 'keyname' => 'php', 'Tagged' => array( [maximum depth reached] ) ), (int) 1 => array( 'id' => '16', 'name' => 'Code', 'keyname' => 'code', 'Tagged' => array( [maximum depth reached] ) ), (int) 2 => array( 'id' => '17', 'name' => 'Tips', 'keyname' => 'tips', 'Tagged' => array( [maximum depth reached] ) ) ) ) $options = array() $model = null $modelClass = null $random_id = (int) 156490964 $element_id = 'rating-156490964' $message_id = 'message-156490964' $values_id = 'values-156490964'RatingsHelper::prepareParams() - APP/Plugin/Feedback/View/Helper/RatingsHelper.php, line 81 RatingsHelper::display_for() - APP/Plugin/Feedback/View/Helper/RatingsHelper.php, line 48 include - APP/View/Posts/filter.ctp, line 30 View::_evaluate() - CORE/Cake/View/View.php, line 971 View::_render() - CORE/Cake/View/View.php, line 933 View::render() - CORE/Cake/View/View.php, line 473 Controller::render() - CORE/Cake/Controller/Controller.php, line 963 Dispatcher::_invoke() - CORE/Cake/Routing/Dispatcher.php, line 200 Dispatcher::dispatch() - CORE/Cake/Routing/Dispatcher.php, line 167 [main] - APP/webroot/index.php, line 109
Notice (8): Undefined index: [APP/Plugin/Feedback/View/Elements/rating.ctp, line 59]Code ContextRating: {
foreign_model: '{$modelClass}',
foreign_id: '{$data[$modelClass]['id']}',
$viewFile = '/var/www/html/chirayuim/app/Plugin/Feedback/View/Elements/rating.ctp' $dataForView = array( 'tags' => array( (int) 0 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 1 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 2 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 3 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 4 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 5 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 6 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 7 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 8 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 9 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 10 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 11 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 12 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 13 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 14 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 15 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 16 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 17 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 18 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 19 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ) ), 'postcategories' => array( (int) 0 => array( 'Postcategory' => array( [maximum depth reached] ), 'ParentPostcategory' => array( [maximum depth reached] ), 'ChildPostcategory' => array([maximum depth reached]), 'Post' => array( [maximum depth reached] ), 'children' => array([maximum depth reached]) ), (int) 1 => array( 'Postcategory' => array( [maximum depth reached] ), 'ParentPostcategory' => array( [maximum depth reached] ), 'ChildPostcategory' => array([maximum depth reached]), 'Post' => array( [maximum depth reached] ), 'children' => array([maximum depth reached]) ), (int) 2 => array( 'Postcategory' => array( [maximum depth reached] ), 'ParentPostcategory' => array( [maximum depth reached] ), 'ChildPostcategory' => array( [maximum depth reached] ), 'Post' => array( [maximum depth reached] ), 'children' => array( [maximum depth reached] ) ), (int) 3 => array( 'Postcategory' => array( [maximum depth reached] ), 'ParentPostcategory' => array( [maximum depth reached] ), 'ChildPostcategory' => array([maximum depth reached]), 'Post' => array( [maximum depth reached] ), 'children' => array([maximum depth reached]) ) ), 'posts' => array( (int) 0 => array( 'Post' => array( [maximum depth reached] ), 'User' => array( [maximum depth reached] ), 'Postcoverimage' => array( [maximum depth reached] ), 'Rating' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), 'RatingSummary' => array( [maximum depth reached] ) ), (int) 1 => array( 'Post' => array( [maximum depth reached] ), 'User' => array( [maximum depth reached] ), 'Postcoverimage' => array( [maximum depth reached] ), 'Rating' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), 'RatingSummary' => array( [maximum depth reached] ) ), (int) 2 => array( 'Post' => array( [maximum depth reached] ), 'User' => array( [maximum depth reached] ), 'Postcoverimage' => array( [maximum depth reached] ), 'Rating' => array([maximum depth reached]), 'Tag' => array( [maximum depth reached] ) ), (int) 3 => array( 'Post' => array( [maximum depth reached] ), 'User' => array( [maximum depth reached] ), 'Postcoverimage' => array( [maximum depth reached] ), 'Rating' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), 'RatingSummary' => array( [maximum depth reached] ) ), (int) 4 => array( 'Post' => array( [maximum depth reached] ), 'User' => array( [maximum depth reached] ), 'Postcoverimage' => array( [maximum depth reached] ), 'Rating' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), 'RatingSummary' => array( [maximum depth reached] ) ) ), 'masterclass' => '', 'appposts' => array( (int) 0 => array( 'Post' => array( [maximum depth reached] ), 'Postcoverimage' => array( [maximum depth reached] ), 'Tofriend' => array([maximum depth reached]) ), (int) 1 => array( 'Post' => array( [maximum depth reached] ), 'Postcoverimage' => array( [maximum depth reached] ), 'Tofriend' => array( [maximum depth reached] ) ), (int) 2 => array( 'Post' => array( [maximum depth reached] ), 'Postcoverimage' => array( [maximum depth reached] ), 'Tofriend' => array( [maximum depth reached] ) ), (int) 3 => array( 'Post' => array( [maximum depth reached] ), 'Postcoverimage' => array( [maximum depth reached] ), 'Tofriend' => array([maximum depth reached]) ), (int) 4 => array( 'Post' => array( [maximum depth reached] ), 'Postcoverimage' => array( [maximum depth reached] ), 'Tofriend' => array([maximum depth reached]) ) ), 'regions' => array(), 'appcountries' => array( (int) 1 => 'Andorra', (int) 2 => 'United Arab Emirates', (int) 3 => 'Afghanistan', (int) 4 => 'Antigua and Barbuda', (int) 5 => 'Anguilla', (int) 6 => 'Albania', (int) 7 => 'Armenia', (int) 8 => 'Netherlands Antilles', (int) 9 => 'Angola', (int) 12 => 'Argentina', (int) 13 => 'American Samoa', (int) 14 => 'Austria', (int) 15 => 'Australia', (int) 16 => 'Aruba', (int) 17 => 'Azerbaijan', (int) 18 => 'Bosnia and Herzegovina', (int) 19 => 'Barbados', (int) 20 => 'Bangladesh', (int) 21 => 'Belgium', (int) 22 => 'Burkina Faso', (int) 23 => 'Bulgaria', (int) 24 => 'Bahrain', (int) 25 => 'Burundi', (int) 26 => 'Benin', (int) 27 => 'Bermuda', (int) 28 => 'Brunei Darussalam', (int) 29 => 'Bolivia', (int) 30 => 'Brazil', (int) 31 => 'Bahamas', (int) 32 => 'Bhutan', (int) 34 => 'Botswana', (int) 35 => 'Belarus', (int) 36 => 'Belize', (int) 37 => 'Canada', (int) 38 => 'Cocos (Keeling) Islands', (int) 40 => 'Central African Republic', (int) 41 => 'Congo', (int) 42 => 'Switzerland', (int) 43 => 'Cote D'Ivoire', (int) 44 => 'Cook Islands', (int) 45 => 'Chile', (int) 46 => 'Cameroon', (int) 47 => 'China', (int) 48 => 'Colombia', (int) 49 => 'Costa Rica', (int) 51 => 'Cuba', (int) 52 => 'Cape Verde', (int) 53 => 'Christmas Island', (int) 54 => 'Cyprus', (int) 55 => 'Czech Republic', (int) 56 => 'Germany', (int) 57 => 'Djibouti', (int) 58 => 'Denmark', (int) 59 => 'Dominica', (int) 60 => 'Dominican Republic', (int) 61 => 'Algeria', (int) 62 => 'Ecuador', (int) 63 => 'Estonia', (int) 64 => 'Egypt', (int) 65 => 'Western Sahara', (int) 66 => 'Eritrea', (int) 67 => 'Spain', (int) 68 => 'Ethiopia', (int) 70 => 'Finland', (int) 71 => 'Fiji', (int) 72 => 'Falkland Islands (Malvinas)', (int) 73 => 'Micronesia, Federated States of', (int) 74 => 'Faroe Islands', (int) 75 => 'France', (int) 77 => 'Gabon', (int) 78 => 'United Kingdom', (int) 79 => 'Grenada', (int) 80 => 'Georgia', (int) 81 => 'French Guiana', (int) 82 => 'Ghana', (int) 83 => 'Gibraltar', (int) 84 => 'Greenland', (int) 85 => 'Gambia', (int) 86 => 'Guinea', (int) 87 => 'Guadeloupe', (int) 88 => 'Equatorial Guinea', (int) 89 => 'Greece', (int) 90 => 'South Georgia and Sandwich Island', (int) 91 => 'Guatemala', (int) 93 => 'Guinea-Bissau', (int) 94 => 'Guyana', (int) 95 => 'Hong Kong', (int) 97 => 'Honduras', (int) 98 => 'Croatia', (int) 99 => 'Haiti', (int) 100 => 'Hungary', (int) 101 => 'Indonesia', (int) 102 => 'Ireland', (int) 103 => 'Israel', (int) 104 => 'India', (int) 106 => 'Iraq', (int) 107 => 'Iran, Islamic Republic of', (int) 108 => 'Iceland', (int) 109 => 'Italy', (int) 110 => 'Jamaica', (int) 111 => 'Jordan', (int) 112 => 'Japan', (int) 113 => 'Kenya', (int) 114 => 'Kyrgyzstan', (int) 115 => 'Cambodia', (int) 116 => 'Kiribati', (int) 117 => 'Comoros', (int) 118 => 'Saint Kitts and Nevis', (int) 119 => 'Korea, Democratic', (int) 120 => 'Korea, Republic of', (int) 121 => 'Kuwait', (int) 122 => 'Cayman Islands', (int) 123 => 'Kazakhstan', (int) 124 => 'Laos', (int) 125 => 'Lebanon', (int) 126 => 'Saint Lucia', (int) 127 => 'Liechtenstein', (int) 128 => 'Sri Lanka', (int) 129 => 'Liberia', (int) 130 => 'Lesotho', (int) 131 => 'Lithuania', (int) 132 => 'Luxembourg', (int) 133 => 'Latvia', (int) 134 => 'Libya', (int) 135 => 'Morocco', (int) 136 => 'Monaco', (int) 137 => 'Moldova', (int) 138 => 'Madagascar', (int) 139 => 'Marshall Islands', (int) 140 => 'Macedonia', (int) 141 => 'Mali', (int) 142 => 'Myanmar', (int) 143 => 'Mongolia', (int) 144 => 'Macau', (int) 145 => 'Northern Mariana Islands', (int) 146 => 'Martinique', (int) 147 => 'Mauritania', (int) 148 => 'Montserrat', (int) 149 => 'Malta', (int) 150 => 'Mauritius', (int) 151 => 'Maldives', (int) 152 => 'Malawi', (int) 153 => 'Mexico', (int) 154 => 'Malaysia', (int) 155 => 'Mozambique', (int) 156 => 'Namibia', (int) 157 => 'New Caledonia', (int) 158 => 'Niger', (int) 159 => 'Norfolk Island', (int) 160 => 'Nigeria', (int) 161 => 'Nicaragua', (int) 162 => 'Netherlands', (int) 163 => 'Norway', (int) 164 => 'Nepal', (int) 165 => 'Nauru', (int) 166 => 'Niue', (int) 167 => 'New Zealand', (int) 168 => 'Oman', (int) 169 => 'Panama', (int) 170 => 'Peru', (int) 171 => 'French Polynesia', (int) 172 => 'Papua New Guinea', (int) 173 => 'Philippines', (int) 174 => 'Pakistan', (int) 175 => 'Poland', (int) 176 => 'Saint Pierre and Miquelon', (int) 177 => 'Pitcairn', (int) 180 => 'Portugal', (int) 181 => 'Palau', (int) 182 => 'Paraguay', (int) 183 => 'Qatar', (int) 184 => 'Reunion', (int) 185 => 'Romania', (int) 186 => 'Russian Federation', (int) 187 => 'Rwanda', (int) 188 => 'Saudi Arabia', (int) 189 => 'Solomon Islands', (int) 190 => 'Seychelles', (int) 191 => 'Sudan', (int) 192 => 'Sweden', (int) 193 => 'Singapore', (int) 194 => 'Saint Helena', (int) 195 => 'Slovenia', (int) 196 => 'Svalbard and Jan Mayen', (int) 197 => 'Slovakia', (int) 198 => 'Sierra Leone', (int) 199 => 'San Marino', (int) 200 => 'Senegal', (int) 201 => 'Somalia', (int) 202 => 'Suriname', (int) 203 => 'Sao Tome and Principe', (int) 204 => 'El Salvador', (int) 205 => 'Syrian Arab Republic', (int) 206 => 'Swaziland', (int) 207 => 'Turks and Caicos Islands', (int) 208 => 'Chad', (int) 209 => 'French Southern Territories', (int) 210 => 'Togo', (int) 211 => 'Thailand', (int) 212 => 'Tajikistan', (int) 213 => 'Tokelau', (int) 215 => 'Turkmenistan', (int) 216 => 'Tunisia', (int) 217 => 'Tonga', (int) 218 => 'Turkey', (int) 219 => 'Trinidad and Tobago', (int) 220 => 'Tuvalu', (int) 221 => 'Taiwan', (int) 222 => 'Tanzania, United Republic', (int) 223 => 'Ukraine', (int) 224 => 'Uganda', (int) 226 => 'United States', (int) 227 => 'Uruguay', (int) 228 => 'Uzbekistan', (int) 230 => 'Saint Vincent and the Grenadines', (int) 231 => 'Venezuela', (int) 232 => 'Virgin Islands, British', (int) 233 => 'Virgin Islands, U.S.', (int) 234 => 'Vietnam', (int) 235 => 'Vanuatu', (int) 236 => 'Wallis and Futuna', (int) 237 => 'Samoa', (int) 238 => 'Yemen', (int) 239 => 'Mayotte', (int) 240 => 'South Africa', (int) 241 => 'Zambia', (int) 242 => 'Zaire', (int) 243 => 'Zimbabwe' ), 'data' => array( 'Post' => array( 'id' => '7', 'postcategory_id' => '7', 'user_id' => '0', 'title' => 'How the PHP script may report what is the total size of any web page browsed', 'body' => '<p>These days excellent work is being done to attract web site users by creating attractive and well managed web pages. While browsing any internet site or a web page as developer or designer of the web pages we might came across the thought, “how much size of this web page is? or how much costly to render this on my browser?”. Well today lets build a script which reports information of above questions. As usual we will be using PHP for scripting the code. This script includes two things in consideration. <strong>First,</strong> how many http/https requests are being used to render the page and <strong>Second,</strong> what is the total size of the rendered web page. We will create a script in a manner that it can be used from command line interface as well as from the browser. For this the cURL module is used. If it is not installed in your PHP set up then go to my previous article of installation and configuration of PHP.</p> <p>Ok. So now what is the meaning of <strong>First</strong> part, “how many http/https requests are”. When any web page is rendered or loaded in your browser, it is a combination of one or multiple CSS files, one or multiple javascripts or .js files, code of Html, multiple images, etc… we call them web page resources as all together they make a web page. While web page is loaded all these multiple files are being called from one or different locations with specific web address. These files are called one by one as it cannot called all once at a time. The separate calls for each of these files are known as http/https requests.</p> <p>Now let’s come to the Second part of the task – “what is the total size of the rendered web page” and that consist of file size of each of these resource we saw above. When http/https requests are responded uninterrupted then that response contains response header (developers and designers knows that). One of the headers is called “Content-Length” and that gives the size of that particular resource. We need to use built in API of PHP ie. get_headers and the argument would be the URL where the http/https request is sent. Bellow is the hint and good start of the code in PHP.</p> <p><strong><em>function file_size_rendered($url) { </em></strong></p> <p><strong><em>//where $url in the argument is the location where request is being sent.</em></strong></p> <p><strong><em> $headers = get_headers($url, 1);</em></strong> </p> <p><strong><em> if (isset($headers['Content-Length'])) </em></strong></p> <p><strong><em> return $headers['Content-Length'];</em></strong> </p> <p><strong><em>//Also check whether lower case of "L" is used in Content-length</em></strong></p> <p><strong><em> if (isset($headers['Content-length'])) </em></strong></p> <p><strong><em> return $headers['Content-length'];</em></strong></p> <p><strong><em>//if the content header is not found then use the curl request</em></strong></p> <p><strong><em> $c = curl_init();</em></strong></p> <p><strong><em> curl_setopt_array($c, array(</em></strong></p> <p><strong><em> CURLOPT_URL => $url,</em></strong></p> <p><strong><em> CURLOPT_RETURNTRANSFER => true,</em></strong></p> <p><strong><em> CURLOPT_HTTPHEADER => array('User-Agent: Mozilla/5.0 </em></strong></p> <p><strong><em> (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.3) </em></strong></p> <p><strong><em> Gecko/20090824 Firefox/3.5.3'),</em></strong></p> <p><strong><em> ));</em></strong></p> <p><strong><em> curl_exec($c);</em></strong> </p> <p><strong><em> $size = curl_getinfo($c, CURLINFO_SIZE_DOWNLOAD);</em></strong> </p> <p><strong><em> return $size;</em></strong> </p> <p><strong><em> curl_close($c);</em></strong></p> <p><strong><em>}</em></strong></p> <p>This article is just a good start to inspire for deeper understanding or the technique of coding. One can browse more or post questions to get answer on more specific tasks.</p> ', 'comment_count' => '0', 'postview_count' => '1768', 'active' => '1', 'created' => '2015-12-28 10:52:20', 'modified' => '2019-11-21 06:00:37', 'tags' => 'PHP, Code, Tips' ), 'User' => array( 'id' => null, 'firstname' => null ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/how-the-php-script-may-62903-small.jpg', 'namemedium' => '/files/uploads/postimages/how-the-php-script-may-62903-medium.jpg' ), 'Rating' => array(), 'Tag' => array( (int) 0 => array( [maximum depth reached] ), (int) 1 => array( [maximum depth reached] ), (int) 2 => array( [maximum depth reached] ) ) ), 'model' => null, 'modelClass' => null, 'submit_url' => '/feedback/ratings/add', 'element_id' => 'rating-156490964', 'message_id' => 'message-156490964', 'values_id' => 'values-156490964', 'readonly' => 'false', 'value' => (int) 0, 'votes' => (int) 0, 'user_vote' => (int) 0 ) $tags = array( (int) 0 => array( 'Tagged' => array( 'tag_id' => '1' ), 'Tag' => array( 'id' => '1', 'identifier' => null, 'name' => 'Configuration', 'keyname' => 'configuration', 'weight' => (float) 12, 'occurrence' => '2' ), (int) 0 => array( 'occurrence' => '2' ) ), (int) 1 => array( 'Tagged' => array( 'tag_id' => '2' ), 'Tag' => array( 'id' => '2', 'identifier' => null, 'name' => 'PHP5', 'keyname' => 'php5', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 2 => array( 'Tagged' => array( 'tag_id' => '3' ), 'Tag' => array( 'id' => '3', 'identifier' => null, 'name' => 'Apache2', 'keyname' => 'apache2', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 3 => array( 'Tagged' => array( 'tag_id' => '4' ), 'Tag' => array( 'id' => '4', 'identifier' => null, 'name' => 'PHP', 'keyname' => 'php', 'weight' => (float) 20, 'occurrence' => '6' ), (int) 0 => array( 'occurrence' => '6' ) ), (int) 4 => array( 'Tagged' => array( 'tag_id' => '5' ), 'Tag' => array( 'id' => '5', 'identifier' => null, 'name' => 'Sourcecode', 'keyname' => 'sourcecode', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 5 => array( 'Tagged' => array( 'tag_id' => '6' ), 'Tag' => array( 'id' => '6', 'identifier' => null, 'name' => 'Warnings', 'keyname' => 'warnings', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 6 => array( 'Tagged' => array( 'tag_id' => '7' ), 'Tag' => array( 'id' => '7', 'identifier' => null, 'name' => 'Timezone', 'keyname' => 'timezone', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 7 => array( 'Tagged' => array( 'tag_id' => '8' ), 'Tag' => array( 'id' => '8', 'identifier' => null, 'name' => 'Linux', 'keyname' => 'linux', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 8 => array( 'Tagged' => array( 'tag_id' => '9' ), 'Tag' => array( 'id' => '9', 'identifier' => null, 'name' => 'Apache', 'keyname' => 'apache', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 9 => array( 'Tagged' => array( 'tag_id' => '10' ), 'Tag' => array( 'id' => '10', 'identifier' => null, 'name' => 'Installation', 'keyname' => 'installation', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 10 => array( 'Tagged' => array( 'tag_id' => '11' ), 'Tag' => array( 'id' => '11', 'identifier' => null, 'name' => 'Open Authentication', 'keyname' => 'openauthentication', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 11 => array( 'Tagged' => array( 'tag_id' => '12' ), 'Tag' => array( 'id' => '12', 'identifier' => null, 'name' => 'Social Network Login', 'keyname' => 'socialnetworklogin', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 12 => array( 'Tagged' => array( 'tag_id' => '13' ), 'Tag' => array( 'id' => '13', 'identifier' => null, 'name' => 'oAuth', 'keyname' => 'oauth', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 13 => array( 'Tagged' => array( 'tag_id' => '14' ), 'Tag' => array( 'id' => '14', 'identifier' => null, 'name' => 'Web Developement', 'keyname' => 'webdevelopement', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 14 => array( 'Tagged' => array( 'tag_id' => '15' ), 'Tag' => array( 'id' => '15', 'identifier' => null, 'name' => 'Security', 'keyname' => 'security', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 15 => array( 'Tagged' => array( 'tag_id' => '16' ), 'Tag' => array( 'id' => '16', 'identifier' => null, 'name' => 'Code', 'keyname' => 'code', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 16 => array( 'Tagged' => array( 'tag_id' => '17' ), 'Tag' => array( 'id' => '17', 'identifier' => null, 'name' => 'Tips', 'keyname' => 'tips', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 17 => array( 'Tagged' => array( 'tag_id' => '18' ), 'Tag' => array( 'id' => '18', 'identifier' => null, 'name' => 'CSV files', 'keyname' => 'csvfiles', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 18 => array( 'Tagged' => array( 'tag_id' => '19' ), 'Tag' => array( 'id' => '19', 'identifier' => null, 'name' => 'File content', 'keyname' => 'filecontent', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 19 => array( 'Tagged' => array( 'tag_id' => '20' ), 'Tag' => array( 'id' => '20', 'identifier' => null, 'name' => 'Software Design', 'keyname' => 'softwaredesign', 'weight' => (float) 12, 'occurrence' => '2' ), (int) 0 => array( 'occurrence' => '2' ) ) ) $postcategories = array( (int) 0 => array( 'Postcategory' => array( 'id' => '5', 'parent_id' => null, 'name' => 'PHP Configuration', 'active' => '1', 'lft' => '1', 'rght' => '2', 'created' => '2015-05-06 13:24:33', 'modified' => '2015-05-06 13:24:33' ), 'ParentPostcategory' => array( 'id' => null, 'parent_id' => null, 'name' => null, 'active' => null, 'lft' => null, 'rght' => null, 'created' => null, 'modified' => null ), 'ChildPostcategory' => array(), 'Post' => array( (int) 0 => array( [maximum depth reached] ), (int) 1 => array( [maximum depth reached] ), (int) 2 => array( [maximum depth reached] ) ), 'children' => array() ), (int) 1 => array( 'Postcategory' => array( 'id' => '6', 'parent_id' => null, 'name' => 'PHP installation', 'active' => '1', 'lft' => '3', 'rght' => '4', 'created' => '2015-05-06 13:36:53', 'modified' => '2015-05-06 13:36:53' ), 'ParentPostcategory' => array( 'id' => null, 'parent_id' => null, 'name' => null, 'active' => null, 'lft' => null, 'rght' => null, 'created' => null, 'modified' => null ), 'ChildPostcategory' => array(), 'Post' => array( (int) 0 => array( [maximum depth reached] ) ), 'children' => array() ), (int) 2 => array( 'Postcategory' => array( 'id' => '7', 'parent_id' => null, 'name' => 'Web development', 'active' => '1', 'lft' => '5', 'rght' => '8', 'created' => '2015-06-06 05:44:15', 'modified' => '2015-06-06 05:44:15' ), 'ParentPostcategory' => array( 'id' => null, 'parent_id' => null, 'name' => null, 'active' => null, 'lft' => null, 'rght' => null, 'created' => null, 'modified' => null ), 'ChildPostcategory' => array( (int) 0 => array( [maximum depth reached] ) ), 'Post' => array( (int) 0 => array( [maximum depth reached] ), (int) 1 => array( [maximum depth reached] ), (int) 2 => array( [maximum depth reached] ) ), 'children' => array( (int) 0 => array( [maximum depth reached] ) ) ), (int) 3 => array( 'Postcategory' => array( 'id' => '9', 'parent_id' => null, 'name' => 'Software Design', 'active' => '1', 'lft' => '9', 'rght' => '10', 'created' => '2017-07-12 16:27:21', 'modified' => '2017-07-12 16:27:21' ), 'ParentPostcategory' => array( 'id' => null, 'parent_id' => null, 'name' => null, 'active' => null, 'lft' => null, 'rght' => null, 'created' => null, 'modified' => null ), 'ChildPostcategory' => array(), 'Post' => array( (int) 0 => array( [maximum depth reached] ), (int) 1 => array( [maximum depth reached] ) ), 'children' => array() ) ) $posts = array( (int) 0 => array( 'Post' => array( 'id' => '11', 'postcategory_id' => '8', 'user_id' => '1', 'title' => 'Connecting remote server using SSH', 'body' => '<p>SSH stands for secured shall - a secured network service over an unsecured network. It is a network protocol. It provides an encrypted data communication between two computers. SSH can be used interactively to enable terminal sessions. SSH is also used in scripts to remotely and securely access data and other resources. In order to connect to remote server with SSH, you need:</p> <p>1) Server IP or domain name</p> <p>2) Username</p> <p>3) Password</p> <p>4) SSH client - I recommend PuTTY (you can easily download from internet) for windows operating system while Linux and MAC users can use OpenSSH which is mostly installed in their OS.</p> <p><strong>Useful SSH commands frequently used by developers:</strong></p> <p><em>>_ ssh <remote_host></em></p> <p><remote_host> is an IP address or domain name that you are trying to connect to. This command assumes that your username on the remote system is the same as your username on your local system.</p> <p> <em>>_ ssh remote_username@<remote_host></em></p> <p>If your username is different on the remote system. You can specify by using this syntax.</p> <p>Once you are connected to the server, you will be asked to provide a password. SSH works by connecting a client program to an SSH server. In above commands, SSH is the client program. The SSH server is at the <em>remote_host</em> that is specified.</p> <p><strong>How to configure SSH</strong></p> <p>When you change the configuration of SSH, you are changing the settings of the sshd server. In Ubuntu, the main sshd configuration file is located at <em>/etc/ssh/sshd_config</em>.</p> <p>While it is helpful to be able to log in to a remote system using passwords, it is much better idea to set up Key-based authentication.</p> <p>Key based authentication works by creating a pair of keys: <strong>a private key</strong> and <strong>a public key.</strong></p> <p>The private key is located on the client machine. The public key is placed on any server you wish to access. Please check how to generate public and private keys with PuTTY for windows and with ssh-keygen for linux and mac OS. The folder in which the private key is placed default in the windows is c:\users\<username>\.ssh while in unix based system it is under /home/<username>/.ssh</p> <p>The public key is added to a special file within the user account you will be logging into called ~/.ssh/authorized_keys</p> <p>When you attempt to connect using a key pair, the server will use the public key to create a message for the client computer that can only be read with private key.</p> <p>The client computer then sends the appropriate response back to the server and the server will know that the client is legitimate. This entire process is done in the background after keys are correctly setup.</p> <p>SSH operates on TCP port 22 by default. The server listens on port 22 though this can be changed through custom port number in <em>sshd_config</em> file.</p> <p><em>>_ ssh -p</em> <em>7322 remote_username@<remote_host></em></p> <p>If you are not connecting <em>remote host</em> at the default port 22, then you need to specify the custom port number in the command. The above command shows remote host is being connected at the port number 7322.</p> ', 'comment_count' => '0', 'postview_count' => '1161', 'active' => '1', 'created' => '2019-11-29 13:06:49', 'modified' => '2019-11-29 13:06:49', 'tags' => 'SSH, Network, Secure' ), 'User' => array( 'id' => '1', 'firstname' => 'Chirayu' ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/ssh-connect-16148-small.jpg', 'namemedium' => '/files/uploads/postimages/ssh-connect-16148-medium.jpg' ), 'Rating' => array( (int) 0 => array( [maximum depth reached] ) ), 'Tag' => array( (int) 0 => array( [maximum depth reached] ), (int) 1 => array( [maximum depth reached] ), (int) 2 => array( [maximum depth reached] ) ), 'RatingSummary' => array( 'total_votes' => (int) 1, 'total_rating' => (float) 3.5 ) ), (int) 1 => array( 'Post' => array( 'id' => '8', 'postcategory_id' => '7', 'user_id' => '0', 'title' => 'CSV files data into php array to store in MySql', 'body' => '<p><strong><em>What are CSV files?</em></strong></p> <p>A CSV (Comma Separated Values) files are text files, allows data to be saved in a structured format. CSV files can be used with Microsoft Excel, Google Spreadsheets or Open Office Calc kind of tools. These CSV files are saved with .csv extension. In CSV files data fields are usually separated by comma as delimiter, but can also use a tab or pipe symbol instead of comma. CSV files are used to import and export data from application to application. Mostly, the first record is a header containing a list of field names. Any programming language has technique to import and export data from and to database like MS-SQL, MySql, PostGres, etc..</p> <p>PHP is one of the best programming languages for import and export of the data with the database to and from flat files like CSV files.</p> <p><strong><em>Fetching the data from the CSV file</em></strong></p> <p>Open the file in the read mode and store the content into variable. We assume that the CSV file contains the information about the contacts having fields firstname, lastname, email, and phone exported and the file name is contacts.csv.</p> <p>$csvfilehandle = fopen("contacts.csv","r");</p> <p>Here $csvfilehandle is file pointer to a file "contacts.csv" successfully opened</p> <p>while (($line = fgetcsv($csvfilehandle,1000,',','"'))!==false){</p> <p> $data[] = $line;</p> <p>}</p> <p>Close the opened file handle with </p> <p>fclose($csvfilehandle);</p> <p>The first argument $csvfilehandle is the mandatory arguments and remaining are optional.</p> <p>1000 is a length of characters per line to be set. This should be greater than the longest line in the file. If you are not sure about the length then don`t specify it.</p> <p>',' comma is a delimiter you can set or according to the data in the file the delimiter is used.</p> <p>'"' is the enclosure in the file used for the field value</p> <p>Now you have all the data of the CSV file into the array $data. If you print this with print_r($data); you get values into array.</p> <p><strong><em>Importing data into MySQL table</em></strong></p> <p>Now to import the data into the MySQL table named contacts, we need to modify the above wile loop. Let`s do that now.</p> <p>while (($line = fgetcsv($csvfilehandle,1000,',','"'))!==false){ </p> <p> mysql_query("insert into contacts(</p> <p> firstname, lastname, email, telephone</p> <p> )VALUES(</p> <p> '".mysql_real_escape_string($line[0])."',</p> <p> '".mysql_real_escape_string($line[1])."',</p> <p> '".mysql_real_escape_string($line[2])."',</p> <p> '".mysql_real_escape_string($line[3])."'</p> <p> )")</p> <p>or die(mysql_error());</p> <p>}</p> <p>fclose($csvfilehandle);</p> <p>Write me back if you are working for such functionality and not getting through the code.</p> ', 'comment_count' => '1', 'postview_count' => '1540', 'active' => '1', 'created' => '2016-11-03 07:17:48', 'modified' => '2019-11-21 06:00:03', 'tags' => 'PHP, CSV files, File content' ), 'User' => array( 'id' => null, 'firstname' => null ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/csv-files-data-into-88773-small.png', 'namemedium' => '/files/uploads/postimages/csv-files-data-into-88773-medium.png' ), 'Rating' => array( (int) 0 => array( [maximum depth reached] ) ), 'Tag' => array( (int) 0 => array( [maximum depth reached] ), (int) 1 => array( [maximum depth reached] ), (int) 2 => array( [maximum depth reached] ) ), 'RatingSummary' => array( 'total_votes' => (int) 1, 'total_rating' => (float) 2.5 ) ), (int) 2 => array( 'Post' => array( 'id' => '7', 'postcategory_id' => '7', 'user_id' => '0', 'title' => 'How the PHP script may report what is the total size of any web page browsed', 'body' => '<p>These days excellent work is being done to attract web site users by creating attractive and well managed web pages. While browsing any internet site or a web page as developer or designer of the web pages we might came across the thought, “how much size of this web page is? or how much costly to render this on my browser?”. Well today lets build a script which reports information of above questions. As usual we will be using PHP for scripting the code. This script includes two things in consideration. <strong>First,</strong> how many http/https requests are being used to render the page and <strong>Second,</strong> what is the total size of the rendered web page. We will create a script in a manner that it can be used from command line interface as well as from the browser. For this the cURL module is used. If it is not installed in your PHP set up then go to my previous article of installation and configuration of PHP.</p> <p>Ok. So now what is the meaning of <strong>First</strong> part, “how many http/https requests are”. When any web page is rendered or loaded in your browser, it is a combination of one or multiple CSS files, one or multiple javascripts or .js files, code of Html, multiple images, etc… we call them web page resources as all together they make a web page. While web page is loaded all these multiple files are being called from one or different locations with specific web address. These files are called one by one as it cannot called all once at a time. The separate calls for each of these files are known as http/https requests.</p> <p>Now let’s come to the Second part of the task – “what is the total size of the rendered web page” and that consist of file size of each of these resource we saw above. When http/https requests are responded uninterrupted then that response contains response header (developers and designers knows that). One of the headers is called “Content-Length” and that gives the size of that particular resource. We need to use built in API of PHP ie. get_headers and the argument would be the URL where the http/https request is sent. Bellow is the hint and good start of the code in PHP.</p> <p><strong><em>function file_size_rendered($url) { </em></strong></p> <p><strong><em>//where $url in the argument is the location where request is being sent.</em></strong></p> <p><strong><em> $headers = get_headers($url, 1);</em></strong> </p> <p><strong><em> if (isset($headers['Content-Length'])) </em></strong></p> <p><strong><em> return $headers['Content-Length'];</em></strong> </p> <p><strong><em>//Also check whether lower case of "L" is used in Content-length</em></strong></p> <p><strong><em> if (isset($headers['Content-length'])) </em></strong></p> <p><strong><em> return $headers['Content-length'];</em></strong></p> <p><strong><em>//if the content header is not found then use the curl request</em></strong></p> <p><strong><em> $c = curl_init();</em></strong></p> <p><strong><em> curl_setopt_array($c, array(</em></strong></p> <p><strong><em> CURLOPT_URL => $url,</em></strong></p> <p><strong><em> CURLOPT_RETURNTRANSFER => true,</em></strong></p> <p><strong><em> CURLOPT_HTTPHEADER => array('User-Agent: Mozilla/5.0 </em></strong></p> <p><strong><em> (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.3) </em></strong></p> <p><strong><em> Gecko/20090824 Firefox/3.5.3'),</em></strong></p> <p><strong><em> ));</em></strong></p> <p><strong><em> curl_exec($c);</em></strong> </p> <p><strong><em> $size = curl_getinfo($c, CURLINFO_SIZE_DOWNLOAD);</em></strong> </p> <p><strong><em> return $size;</em></strong> </p> <p><strong><em> curl_close($c);</em></strong></p> <p><strong><em>}</em></strong></p> <p>This article is just a good start to inspire for deeper understanding or the technique of coding. One can browse more or post questions to get answer on more specific tasks.</p> ', 'comment_count' => '0', 'postview_count' => '1768', 'active' => '1', 'created' => '2015-12-28 10:52:20', 'modified' => '2019-11-21 06:00:37', 'tags' => 'PHP, Code, Tips' ), 'User' => array( 'id' => null, 'firstname' => null ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/how-the-php-script-may-62903-small.jpg', 'namemedium' => '/files/uploads/postimages/how-the-php-script-may-62903-medium.jpg' ), 'Rating' => array(), 'Tag' => array( (int) 0 => array( [maximum depth reached] ), (int) 1 => array( [maximum depth reached] ), (int) 2 => array( [maximum depth reached] ) ) ), (int) 3 => array( 'Post' => array( 'id' => '6', 'postcategory_id' => '8', 'user_id' => '1', 'title' => 'Developing secured web application with PHP', 'body' => '<p>Your PHP web application is deployed on the secured platform is great but it is not just enough to consider your application is secured. It is equally or more important that your source code is also developed in the same intensity of security and passed through security testing. I would like to propose certain check list to consider before you go live with your site. PHP is considered one of the easiest languages for developing web applications and this gives chance to startup developers to leave common PHP security pitfalls in development.</p> <p>Listed out bellow are few points which can be used as a check list before you publish your web application.</p> <ul> <li><strong><em>Character encoding:</em></strong> The thumb rule is always create a valid output and use UTF-8 for the encoding like in Html, Database, Html, JS, URLs, Emails and wherever it is possible.</li> <li><strong><em>User Input Data Validation:</em></strong> Validate the user input data according to which purpose it is collected from them. It is always a good idea to validate the user input data at the PHP logic even if your JavaScript validate it at the browser itself. Type-casting is also helpful in most of the cases.</li> <li><strong><em>CSRF or XSRF – Cross Site Request Forgeries: </em></strong>a request from the different site which misuses users authenticated stat data to hack or perform unwanted operations. While user is logged in, his session data is shared across all tabs in the same browser. Code the PHP script that way it uses minimum time of GET requests or probably only to access the information rather than transactions. Avoid using $_REQUEST as much possible instead use $_GET or $_POST accordingly wherever you retrieve variables.</li> </ul> <p>Another way is to generate a random value known as token while user successfully log in at the application. Store this token value in the session and check in application logic whenever user requests or post any information.</p> <ul> <li><strong><em>XSS – Cross site scripting: </em></strong>always validate HTML inputs from user’s submitted data in case like accepting comments on the posts, or collecting reviews and display them on the site. It may use to steal session an cookie data and run kind of JS script on the browser. Use strip_tags() and /or htmlspecialchars() functions which encode and prevent users data to create an HTML tags.</li> <li><strong><em>Non-disclose of file system</em></strong>: If your website allows to download any file to its users, always use some functions which takes file path as an internal system input and use respective header() arguments to download the file. Do not create a like for the file which displays whole folder structure in the link itself to download the file.</li> <li><strong><em>Restrict the file uploads</em></strong>: a user could upload a .php extension file or any other executable file through your file upload feature on site. Check the MIME type of the uploaded file with the function like finfo_file() or any similar to validate the type of file. Create an array of allowable file extensions and keep checking with the uploaded file extension is present in the allowable array or not.</li> <li><strong><em>SQL injection</em></strong>: any input which is concatenated into a string as an SQL query is called the SQL injection. Characters like semicolon, single quote, double quote, hyphens, etc which are used in the SQL queries or statements, should be escaped. This compromise the database and it allowed to be accessed by unauthorized way. Developer can use the pair of prepare () and execute () statement to execute the query rather than simply write a row query to fire on database. Most of the new generation frameworks for PHP take care of this.</li> <li>Other security measures includes <ul style="list-style-type:circle"> <li>Use a proper error handling.</li> <li>Always use .php extensions to included files.</li> <li>Filter values of “From” header before you create that in the Email function.</li> <li>Use strong password hashing algorithm while storing the passwords.</li> <li>Encrypt the session data before you store.</li> <li>Strong cipher code to encrypt data is also a good measure.</li> </ul> </li> </ul> <p style="margin-left:.25in">Web application security measures are taken at the time of designing its architecture. Also it should not happen that steps taken from the security point of view decreases the scope of usability. Security must be implemented keeping in the mind of your website users and must be included in the development budget.</p> <p style="margin-left:.25in">This is a short tutorial for PHP developers and has just stretched the surface of the development techniques. It is up to the developer who understands the depth of vulnerabilities and possible attacks on applications over the web. Developers are required to drill more on each points which are listed and /or which are left from discussion here.</p> ', 'comment_count' => '0', 'postview_count' => '1740', 'active' => '1', 'created' => '2015-07-17 13:54:47', 'modified' => '2019-11-21 06:01:23', 'tags' => 'PHP, Web Developement, Security' ), 'User' => array( 'id' => '1', 'firstname' => 'Chirayu' ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/developing-secured-web-application-65142-small.jpg', 'namemedium' => '/files/uploads/postimages/developing-secured-web-application-65142-medium.jpg' ), 'Rating' => array( (int) 0 => array( [maximum depth reached] ), (int) 1 => array( [maximum depth reached] ) ), 'Tag' => array( (int) 0 => array( [maximum depth reached] ), (int) 1 => array( [maximum depth reached] ), (int) 2 => array( [maximum depth reached] ) ), 'RatingSummary' => array( 'total_votes' => (int) 2, 'total_rating' => (float) 4 ) ), (int) 4 => array( 'Post' => array( 'id' => '5', 'postcategory_id' => '7', 'user_id' => '1', 'title' => 'Social website login for your site is Open source standards for authorization', 'body' => '<p>You might have seen many of sites now showing links or buttons of Facebook, Twitter, Google + or other social network sites on their sign up and sign in page. This is to make users life bit easier for the login or sign up process on various websites. What happens when you click on any of that link? Have you tried anytime?</p> <p>Let’s see how you as a developer can develop this feature for your website. For this we consider a use case.</p> <p><em>User came to the sign in page of your site and he looked at the login with “facebook” or “twitter” or “google” (or any of the site) link. He has a separate account of any of these listed social network sites which you have integrated in your website. He clicks on any of the link and now he is redirected to the respective site for authentication. He provides correct credential for that social network site. He is now authenticated by that social network site and if it is for the first time he is using this authentication system, he has to agree to share his profile data with the other site from where he is coming for the authentication.</em></p> <p>When user agrees to share his profile data on successful login, that social network site redirect him to your site with user’s profile information. Of course password would not be sent to your site. This authenticating social network site will generate one token for this session and send along with the user’s profile data. This token is unique to user and your site. Now all communication and data exchange between your site and the authenticating social network site happens with this token generated by the authenticated site. Give essential profile data to your website login system and create a successful login session at your website and treat him as a logged in user.</p> <p> You can store this user information into your database and send an email to him with the new login credentials to login in your site directly in future. If he doesn’t want to login from your site directly, he still has an option to login again from the social network site which he chooses. Check every time while login weather he is the stored user with his unique field value like email address or username and if not found in your database store it and or otherwise directly give an authentication to the logged in section of your site.</p> <p>All of these redirections and authentications are made through APIs provided by these authenticating sites. Most of these sites do provide a sign in APIs but do not have the APIs for sign off from the authenticated site (There are few exceptions in this). Once user is logged in to your website through open authentication system via a different web site, he has to actually login into that website. Now when he clicks on the logout link of your site, he logs out from your site not from the site from where he was authenticated. This is risk if any user is accessing your site from the public computer and forgets to log off from the authenticated site. His account would be compromised.</p> <p>You as a developer of your site must provide information about the risk factors to your users before they use separate authentication system for your site. Developers need to create an account on these sites and get secret API key to use their APIs and use this secret key into data transactions with the site.</p> <p>Here are few providers of open authentication services are also called resource owners to authorize other web service or web site to their resources without sharing their users’ credentials.</p> <p>Amazon, Dropbox, Facebook, Flickr, GitHub, Instagram, LinkedIn, Twitter, Tumblrand …..And many of others.</p> ', 'comment_count' => '0', 'postview_count' => '2059', 'active' => '1', 'created' => '2015-06-15 08:15:29', 'modified' => '2019-11-21 06:01:51', 'tags' => 'Open Authentication, Social Network Login, oAuth' ), 'User' => array( 'id' => '1', 'firstname' => 'Chirayu' ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/social-website-login-for-65938-small.jpg', 'namemedium' => '/files/uploads/postimages/social-website-login-for-65938-medium.jpg' ), 'Rating' => array( (int) 0 => array( [maximum depth reached] ) ), 'Tag' => array( (int) 0 => array( [maximum depth reached] ), (int) 1 => array( [maximum depth reached] ), (int) 2 => array( [maximum depth reached] ) ), 'RatingSummary' => array( 'total_votes' => (int) 1, 'total_rating' => (float) 5 ) ) ) $masterclass = '' $appposts = array( (int) 0 => array( 'Post' => array( 'id' => '11', 'user_id' => '1', 'title' => 'Connecting remote server using SSH', 'body' => '<p>SSH stands for secured shall - a secured network service over an unsecured network. It is a network protocol. It provides an encrypted data communication between two computers. SSH can be used interactively to enable terminal sessions. SSH is also used in scripts to remotely and securely access data and other resources. In order to connect to remote server with SSH, you need:</p> <p>1) Server IP or domain name</p> <p>2) Username</p> <p>3) Password</p> <p>4) SSH client - I recommend PuTTY (you can easily download from internet) for windows operating system while Linux and MAC users can use OpenSSH which is mostly installed in their OS.</p> <p><strong>Useful SSH commands frequently used by developers:</strong></p> <p><em>>_ ssh <remote_host></em></p> <p><remote_host> is an IP address or domain name that you are trying to connect to. This command assumes that your username on the remote system is the same as your username on your local system.</p> <p> <em>>_ ssh remote_username@<remote_host></em></p> <p>If your username is different on the remote system. You can specify by using this syntax.</p> <p>Once you are connected to the server, you will be asked to provide a password. SSH works by connecting a client program to an SSH server. In above commands, SSH is the client program. The SSH server is at the <em>remote_host</em> that is specified.</p> <p><strong>How to configure SSH</strong></p> <p>When you change the configuration of SSH, you are changing the settings of the sshd server. In Ubuntu, the main sshd configuration file is located at <em>/etc/ssh/sshd_config</em>.</p> <p>While it is helpful to be able to log in to a remote system using passwords, it is much better idea to set up Key-based authentication.</p> <p>Key based authentication works by creating a pair of keys: <strong>a private key</strong> and <strong>a public key.</strong></p> <p>The private key is located on the client machine. The public key is placed on any server you wish to access. Please check how to generate public and private keys with PuTTY for windows and with ssh-keygen for linux and mac OS. The folder in which the private key is placed default in the windows is c:\users\<username>\.ssh while in unix based system it is under /home/<username>/.ssh</p> <p>The public key is added to a special file within the user account you will be logging into called ~/.ssh/authorized_keys</p> <p>When you attempt to connect using a key pair, the server will use the public key to create a message for the client computer that can only be read with private key.</p> <p>The client computer then sends the appropriate response back to the server and the server will know that the client is legitimate. This entire process is done in the background after keys are correctly setup.</p> <p>SSH operates on TCP port 22 by default. The server listens on port 22 though this can be changed through custom port number in <em>sshd_config</em> file.</p> <p><em>>_ ssh -p</em> <em>7322 remote_username@<remote_host></em></p> <p>If you are not connecting <em>remote host</em> at the default port 22, then you need to specify the custom port number in the command. The above command shows remote host is being connected at the port number 7322.</p> ', 'created' => '2019-11-29 13:06:49', 'tags' => '' ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/ssh-connect-16148-small.jpg', 'namemedium' => '/files/uploads/postimages/ssh-connect-16148-medium.jpg' ), 'Tofriend' => array() ), (int) 1 => array( 'Post' => array( 'id' => '10', 'user_id' => '0', 'title' => 'SOLID Part-2 : Principle of Open and Closed', 'body' => '<p>Any project has a scope of changes in terms of features, functionalities and workflows. Practically, to design application prefactly from begining is almost impossible even in the agile development. Classes and interfaces are pillers of application designs.</p> <p>SOLID is one of the proven set of design principles that are meant to guide developers to design and build robust, easily maintainable and scalable software.<br /> This article is focused ont he second principle of SOLID : The principle of Open / Closed.<br /> It satates that : Software entities (ie. classes, interfaces, functions etc) should be Open to extended but closed for modifications.<br /> Lets Check first what does it mean by this principle.</p> <p>A class is closed since it may be compiled, stored in the library, baselined and used by client classes. But it is also open, since any new class may use it as parent and adding new features.</p> <p>Fortunately we have a concept of Inheritance to achieve this goal. But, inheritance introduces tight coupling if the subclasses depend on implementation details of their parent class.</p> <p>my recomandation is to start designe inheritance with interfaces instead of superclasses. The interfaces are closed for modifications, you can provide new implementations to extend the functionality of your software.</p> <p>Let’s see an example that uses the Open/Closed Principle.</p> <p>We will need a Employee interface, the Company class, which uses the Employees, and some implementation of the Employee interface.<br /> The Company class should know just one thing about the Employees — what methods to call. This is what all the Employees have in common, so we will have a Employee interface with just the common methods(ie. someWork).</p> <p>public interface Employee{<br /> public void someWork();<br /> }</p> <p>And a Company class that encapsulates an Employye implementation and executes it.<br /> public class Company() {<br /> private Employee emp;<br /> // we set the strategy in the constructor<br /> public Company(Employee emp) {<br /> this.emp = emp;<br /> }</p> <p> public void completeTheWork() {<br /> this.emp.someWork();<br /> }<br /> }</p> <p>And let’s create two implementations for the Employee interface.</p> <p>public class Employee1 implements Employee {<br /> public void someWork() {<br /> System.out.println(“Work of Emoloyee 1”);<br /> }<br /> }</p> <p>public class Employee2 implements Employee {<br /> public void someWork() {<br /> System.out.println(“Work of Emoloyee 2”);<br /> }<br /> }</p> <p>Now lets use some dependency Injection to see how it works. We need to create one Perform class.</p> <p>public class Perform() {<br /> public static void main(String[] args) {<br /> Context context = new Company(new Employee1()); // we inject the Employee1<br /> context.completeTheWorky(); // it will print “Execute employee 1”;</p> <p> context = new Company(new Employee2()); // we inject the Employee2<br /> context.completeTheWork(); // it will print “Execute employee 2”<br /> }<br /> }</p> <p>So the Company is decoupled from a specific Employee class. You could implement many Employees it needed and no matter how they work and what you want them to do, you don’t need to modify the Company class. The Company class knows just that it must call someWork method and it is enough.</p> <p>After taking a closer look at the Single Responsibility Principle, we now discussed the Open/Closed Principle.<br /> It uses Interfaces to enable you the functionality of your application without changing the existing code.</p> ', 'created' => '2019-05-24 11:59:08', 'tags' => '' ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/Solid-part-2-28564-small.jpg', 'namemedium' => '/files/uploads/postimages/Solid-part-2-28564-medium.jpg' ), 'Tofriend' => array( (int) 0 => array( [maximum depth reached] ) ) ), (int) 2 => array( 'Post' => array( 'id' => '9', 'user_id' => '0', 'title' => 'SOLID Part-1 : Single Responsibility Principle - Software design', 'body' => '<p>S O L I D</p> <p>'S' represents Single Responsibility Principle</p> <p>Every class should have responsibility over a single part of the functionality provided by the software and that responsibility should be entirely encapsulated by the class. In other words there should never be more than one trigger or reason for a class to change. When a (functional) responsibility is divided over more than one class, all classes’ part of that responsibility has to change.</p> <p>The code must be maintainable. When we need to make a change in a class having more responsibilities the change might affect the other functionality related to the other responsibility of the class. The code, which cannot adapt to change requirements with ease, is not a well defined.</p> <p>When we design our classes, we should take care that one class at the most is responsible for doing only one task or single responsibility. Not only should the class, even operations or methods in the class defined in a way that it has only one responsibility to handle. To understand this let us take an example of Employee class. Class Employee is made with few of its attributes and operations.</p> <p>Class Employee{</p> <p> private String employeeId;</p> <p> private String name;</p> <p> private string address;</p> <p> private Date dateOfJoining;</p> <p> private Int DesignationId;</p> <p> </p> <p> public amtIncrement(){</p> <p> //increment logic implementation</p> <p> }</p> <p> public calDOR(){</p> <p> //Date of retirement logic implementation</p> <p> } </p> <p> public setDateOfJoining(){</p> <p> }</p> <p> public setEmployeeId(){</p> <p> }</p> <p> public getDateOfJoining(){</p> <p> }</p> <p> public getDesignationId(){ </p> <p> } </p> <p>}</p> <p>The above class is correctly structured and it has employee attributes declared. Also it has operations related to employee.</p> <p>Here Employee class should have only responsibility to maintain and manage the data of employee in formations. But this class is violating the principle of Single Responsibility. How?</p> <p><strong>First,</strong> the logic of calculating the Date of Retirement is not the employee's responsibility. This might be defined under the HR class and calculate by taking employee's Date of Joining in the organization which is an attribute of Employee class. So if any change happens in the HR policies, the Employee Class does not get updated. Just because HR policies updated this has nothing to do with the Employee entity.</p> <p><strong>Second,</strong> the logic of calculating the amount of increment is a responsibility of Finance class and it calculated by taking the level or designation of the employee in the organization. So if any change happens to the financial status, the Employee class doesn’t get affected with that.</p> <p>If the class has only one reason to change then it stays less fragile. More responsibilities lead to more dependencies and higher coupling. A test class for a ‘one responsibility class’ will have less test cases (branches). If a class has one purpose it will usually have less dependencies, thus less mocking and test preparing.</p> <p>The Single Responsibility Principle represents a good way of identifying classes during the design phase of an application and it reminds you to think of all the ways a class can evolve. Class and module design is highly affected by SRP and it leads to a low coupled design with less and lighter dependencies.</p> <p>Points to consider when you design the class.</p> <ul> <li>Define clearly what this class is going to do.</li> <li>Reduce the long procedures of the logic. Divide into multiple chunks.</li> <li>Write the code in the way that very small steps can be tested independently.</li> </ul> ', 'created' => '2017-07-12 16:42:05', 'tags' => '' ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/Solid-part-1-50472-small.jpg', 'namemedium' => '/files/uploads/postimages/Solid-part-1-50472-medium.jpg' ), 'Tofriend' => array( (int) 0 => array( [maximum depth reached] ), (int) 1 => array( [maximum depth reached] ), (int) 2 => array( [maximum depth reached] ) ) ), (int) 3 => array( 'Post' => array( 'id' => '8', 'user_id' => '0', 'title' => 'CSV files data into php array to store in MySql', 'body' => '<p><strong><em>What are CSV files?</em></strong></p> <p>A CSV (Comma Separated Values) files are text files, allows data to be saved in a structured format. CSV files can be used with Microsoft Excel, Google Spreadsheets or Open Office Calc kind of tools. These CSV files are saved with .csv extension. In CSV files data fields are usually separated by comma as delimiter, but can also use a tab or pipe symbol instead of comma. CSV files are used to import and export data from application to application. Mostly, the first record is a header containing a list of field names. Any programming language has technique to import and export data from and to database like MS-SQL, MySql, PostGres, etc..</p> <p>PHP is one of the best programming languages for import and export of the data with the database to and from flat files like CSV files.</p> <p><strong><em>Fetching the data from the CSV file</em></strong></p> <p>Open the file in the read mode and store the content into variable. We assume that the CSV file contains the information about the contacts having fields firstname, lastname, email, and phone exported and the file name is contacts.csv.</p> <p>$csvfilehandle = fopen("contacts.csv","r");</p> <p>Here $csvfilehandle is file pointer to a file "contacts.csv" successfully opened</p> <p>while (($line = fgetcsv($csvfilehandle,1000,',','"'))!==false){</p> <p> $data[] = $line;</p> <p>}</p> <p>Close the opened file handle with </p> <p>fclose($csvfilehandle);</p> <p>The first argument $csvfilehandle is the mandatory arguments and remaining are optional.</p> <p>1000 is a length of characters per line to be set. This should be greater than the longest line in the file. If you are not sure about the length then don`t specify it.</p> <p>',' comma is a delimiter you can set or according to the data in the file the delimiter is used.</p> <p>'"' is the enclosure in the file used for the field value</p> <p>Now you have all the data of the CSV file into the array $data. If you print this with print_r($data); you get values into array.</p> <p><strong><em>Importing data into MySQL table</em></strong></p> <p>Now to import the data into the MySQL table named contacts, we need to modify the above wile loop. Let`s do that now.</p> <p>while (($line = fgetcsv($csvfilehandle,1000,',','"'))!==false){ </p> <p> mysql_query("insert into contacts(</p> <p> firstname, lastname, email, telephone</p> <p> )VALUES(</p> <p> '".mysql_real_escape_string($line[0])."',</p> <p> '".mysql_real_escape_string($line[1])."',</p> <p> '".mysql_real_escape_string($line[2])."',</p> <p> '".mysql_real_escape_string($line[3])."'</p> <p> )")</p> <p>or die(mysql_error());</p> <p>}</p> <p>fclose($csvfilehandle);</p> <p>Write me back if you are working for such functionality and not getting through the code.</p> ', 'created' => '2016-11-03 07:17:48', 'tags' => '' ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/csv-files-data-into-88773-small.png', 'namemedium' => '/files/uploads/postimages/csv-files-data-into-88773-medium.png' ), 'Tofriend' => array() ), (int) 4 => array( 'Post' => array( 'id' => '7', 'user_id' => '0', 'title' => 'How the PHP script may report what is the total size of any web page browsed', 'body' => '<p>These days excellent work is being done to attract web site users by creating attractive and well managed web pages. While browsing any internet site or a web page as developer or designer of the web pages we might came across the thought, “how much size of this web page is? or how much costly to render this on my browser?”. Well today lets build a script which reports information of above questions. As usual we will be using PHP for scripting the code. This script includes two things in consideration. <strong>First,</strong> how many http/https requests are being used to render the page and <strong>Second,</strong> what is the total size of the rendered web page. We will create a script in a manner that it can be used from command line interface as well as from the browser. For this the cURL module is used. If it is not installed in your PHP set up then go to my previous article of installation and configuration of PHP.</p> <p>Ok. So now what is the meaning of <strong>First</strong> part, “how many http/https requests are”. When any web page is rendered or loaded in your browser, it is a combination of one or multiple CSS files, one or multiple javascripts or .js files, code of Html, multiple images, etc… we call them web page resources as all together they make a web page. While web page is loaded all these multiple files are being called from one or different locations with specific web address. These files are called one by one as it cannot called all once at a time. The separate calls for each of these files are known as http/https requests.</p> <p>Now let’s come to the Second part of the task – “what is the total size of the rendered web page” and that consist of file size of each of these resource we saw above. When http/https requests are responded uninterrupted then that response contains response header (developers and designers knows that). One of the headers is called “Content-Length” and that gives the size of that particular resource. We need to use built in API of PHP ie. get_headers and the argument would be the URL where the http/https request is sent. Bellow is the hint and good start of the code in PHP.</p> <p><strong><em>function file_size_rendered($url) { </em></strong></p> <p><strong><em>//where $url in the argument is the location where request is being sent.</em></strong></p> <p><strong><em> $headers = get_headers($url, 1);</em></strong> </p> <p><strong><em> if (isset($headers['Content-Length'])) </em></strong></p> <p><strong><em> return $headers['Content-Length'];</em></strong> </p> <p><strong><em>//Also check whether lower case of "L" is used in Content-length</em></strong></p> <p><strong><em> if (isset($headers['Content-length'])) </em></strong></p> <p><strong><em> return $headers['Content-length'];</em></strong></p> <p><strong><em>//if the content header is not found then use the curl request</em></strong></p> <p><strong><em> $c = curl_init();</em></strong></p> <p><strong><em> curl_setopt_array($c, array(</em></strong></p> <p><strong><em> CURLOPT_URL => $url,</em></strong></p> <p><strong><em> CURLOPT_RETURNTRANSFER => true,</em></strong></p> <p><strong><em> CURLOPT_HTTPHEADER => array('User-Agent: Mozilla/5.0 </em></strong></p> <p><strong><em> (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.3) </em></strong></p> <p><strong><em> Gecko/20090824 Firefox/3.5.3'),</em></strong></p> <p><strong><em> ));</em></strong></p> <p><strong><em> curl_exec($c);</em></strong> </p> <p><strong><em> $size = curl_getinfo($c, CURLINFO_SIZE_DOWNLOAD);</em></strong> </p> <p><strong><em> return $size;</em></strong> </p> <p><strong><em> curl_close($c);</em></strong></p> <p><strong><em>}</em></strong></p> <p>This article is just a good start to inspire for deeper understanding or the technique of coding. One can browse more or post questions to get answer on more specific tasks.</p> ', 'created' => '2015-12-28 10:52:20', 'tags' => '' ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/how-the-php-script-may-62903-small.jpg', 'namemedium' => '/files/uploads/postimages/how-the-php-script-may-62903-medium.jpg' ), 'Tofriend' => array() ) ) $regions = array() $appcountries = array( (int) 1 => 'Andorra', (int) 2 => 'United Arab Emirates', (int) 3 => 'Afghanistan', (int) 4 => 'Antigua and Barbuda', (int) 5 => 'Anguilla', (int) 6 => 'Albania', (int) 7 => 'Armenia', (int) 8 => 'Netherlands Antilles', (int) 9 => 'Angola', (int) 12 => 'Argentina', (int) 13 => 'American Samoa', (int) 14 => 'Austria', (int) 15 => 'Australia', (int) 16 => 'Aruba', (int) 17 => 'Azerbaijan', (int) 18 => 'Bosnia and Herzegovina', (int) 19 => 'Barbados', (int) 20 => 'Bangladesh', (int) 21 => 'Belgium', (int) 22 => 'Burkina Faso', (int) 23 => 'Bulgaria', (int) 24 => 'Bahrain', (int) 25 => 'Burundi', (int) 26 => 'Benin', (int) 27 => 'Bermuda', (int) 28 => 'Brunei Darussalam', (int) 29 => 'Bolivia', (int) 30 => 'Brazil', (int) 31 => 'Bahamas', (int) 32 => 'Bhutan', (int) 34 => 'Botswana', (int) 35 => 'Belarus', (int) 36 => 'Belize', (int) 37 => 'Canada', (int) 38 => 'Cocos (Keeling) Islands', (int) 40 => 'Central African Republic', (int) 41 => 'Congo', (int) 42 => 'Switzerland', (int) 43 => 'Cote D'Ivoire', (int) 44 => 'Cook Islands', (int) 45 => 'Chile', (int) 46 => 'Cameroon', (int) 47 => 'China', (int) 48 => 'Colombia', (int) 49 => 'Costa Rica', (int) 51 => 'Cuba', (int) 52 => 'Cape Verde', (int) 53 => 'Christmas Island', (int) 54 => 'Cyprus', (int) 55 => 'Czech Republic', (int) 56 => 'Germany', (int) 57 => 'Djibouti', (int) 58 => 'Denmark', (int) 59 => 'Dominica', (int) 60 => 'Dominican Republic', (int) 61 => 'Algeria', (int) 62 => 'Ecuador', (int) 63 => 'Estonia', (int) 64 => 'Egypt', (int) 65 => 'Western Sahara', (int) 66 => 'Eritrea', (int) 67 => 'Spain', (int) 68 => 'Ethiopia', (int) 70 => 'Finland', (int) 71 => 'Fiji', (int) 72 => 'Falkland Islands (Malvinas)', (int) 73 => 'Micronesia, Federated States of', (int) 74 => 'Faroe Islands', (int) 75 => 'France', (int) 77 => 'Gabon', (int) 78 => 'United Kingdom', (int) 79 => 'Grenada', (int) 80 => 'Georgia', (int) 81 => 'French Guiana', (int) 82 => 'Ghana', (int) 83 => 'Gibraltar', (int) 84 => 'Greenland', (int) 85 => 'Gambia', (int) 86 => 'Guinea', (int) 87 => 'Guadeloupe', (int) 88 => 'Equatorial Guinea', (int) 89 => 'Greece', (int) 90 => 'South Georgia and Sandwich Island', (int) 91 => 'Guatemala', (int) 93 => 'Guinea-Bissau', (int) 94 => 'Guyana', (int) 95 => 'Hong Kong', (int) 97 => 'Honduras', (int) 98 => 'Croatia', (int) 99 => 'Haiti', (int) 100 => 'Hungary', (int) 101 => 'Indonesia', (int) 102 => 'Ireland', (int) 103 => 'Israel', (int) 104 => 'India', (int) 106 => 'Iraq', (int) 107 => 'Iran, Islamic Republic of', (int) 108 => 'Iceland', (int) 109 => 'Italy', (int) 110 => 'Jamaica', (int) 111 => 'Jordan', (int) 112 => 'Japan', (int) 113 => 'Kenya', (int) 114 => 'Kyrgyzstan', (int) 115 => 'Cambodia', (int) 116 => 'Kiribati', (int) 117 => 'Comoros', (int) 118 => 'Saint Kitts and Nevis', (int) 119 => 'Korea, Democratic', (int) 120 => 'Korea, Republic of', (int) 121 => 'Kuwait', (int) 122 => 'Cayman Islands', (int) 123 => 'Kazakhstan', (int) 124 => 'Laos', (int) 125 => 'Lebanon', (int) 126 => 'Saint Lucia', (int) 127 => 'Liechtenstein', (int) 128 => 'Sri Lanka', (int) 129 => 'Liberia', (int) 130 => 'Lesotho', (int) 131 => 'Lithuania', (int) 132 => 'Luxembourg', (int) 133 => 'Latvia', (int) 134 => 'Libya', (int) 135 => 'Morocco', (int) 136 => 'Monaco', (int) 137 => 'Moldova', (int) 138 => 'Madagascar', (int) 139 => 'Marshall Islands', (int) 140 => 'Macedonia', (int) 141 => 'Mali', (int) 142 => 'Myanmar', (int) 143 => 'Mongolia', (int) 144 => 'Macau', (int) 145 => 'Northern Mariana Islands', (int) 146 => 'Martinique', (int) 147 => 'Mauritania', (int) 148 => 'Montserrat', (int) 149 => 'Malta', (int) 150 => 'Mauritius', (int) 151 => 'Maldives', (int) 152 => 'Malawi', (int) 153 => 'Mexico', (int) 154 => 'Malaysia', (int) 155 => 'Mozambique', (int) 156 => 'Namibia', (int) 157 => 'New Caledonia', (int) 158 => 'Niger', (int) 159 => 'Norfolk Island', (int) 160 => 'Nigeria', (int) 161 => 'Nicaragua', (int) 162 => 'Netherlands', (int) 163 => 'Norway', (int) 164 => 'Nepal', (int) 165 => 'Nauru', (int) 166 => 'Niue', (int) 167 => 'New Zealand', (int) 168 => 'Oman', (int) 169 => 'Panama', (int) 170 => 'Peru', (int) 171 => 'French Polynesia', (int) 172 => 'Papua New Guinea', (int) 173 => 'Philippines', (int) 174 => 'Pakistan', (int) 175 => 'Poland', (int) 176 => 'Saint Pierre and Miquelon', (int) 177 => 'Pitcairn', (int) 180 => 'Portugal', (int) 181 => 'Palau', (int) 182 => 'Paraguay', (int) 183 => 'Qatar', (int) 184 => 'Reunion', (int) 185 => 'Romania', (int) 186 => 'Russian Federation', (int) 187 => 'Rwanda', (int) 188 => 'Saudi Arabia', (int) 189 => 'Solomon Islands', (int) 190 => 'Seychelles', (int) 191 => 'Sudan', (int) 192 => 'Sweden', (int) 193 => 'Singapore', (int) 194 => 'Saint Helena', (int) 195 => 'Slovenia', (int) 196 => 'Svalbard and Jan Mayen', (int) 197 => 'Slovakia', (int) 198 => 'Sierra Leone', (int) 199 => 'San Marino', (int) 200 => 'Senegal', (int) 201 => 'Somalia', (int) 202 => 'Suriname', (int) 203 => 'Sao Tome and Principe', (int) 204 => 'El Salvador', (int) 205 => 'Syrian Arab Republic', (int) 206 => 'Swaziland', (int) 207 => 'Turks and Caicos Islands', (int) 208 => 'Chad', (int) 209 => 'French Southern Territories', (int) 210 => 'Togo', (int) 211 => 'Thailand', (int) 212 => 'Tajikistan', (int) 213 => 'Tokelau', (int) 215 => 'Turkmenistan', (int) 216 => 'Tunisia', (int) 217 => 'Tonga', (int) 218 => 'Turkey', (int) 219 => 'Trinidad and Tobago', (int) 220 => 'Tuvalu', (int) 221 => 'Taiwan', (int) 222 => 'Tanzania, United Republic', (int) 223 => 'Ukraine', (int) 224 => 'Uganda', (int) 226 => 'United States', (int) 227 => 'Uruguay', (int) 228 => 'Uzbekistan', (int) 230 => 'Saint Vincent and the Grenadines', (int) 231 => 'Venezuela', (int) 232 => 'Virgin Islands, British', (int) 233 => 'Virgin Islands, U.S.', (int) 234 => 'Vietnam', (int) 235 => 'Vanuatu', (int) 236 => 'Wallis and Futuna', (int) 237 => 'Samoa', (int) 238 => 'Yemen', (int) 239 => 'Mayotte', (int) 240 => 'South Africa', (int) 241 => 'Zambia', (int) 242 => 'Zaire', (int) 243 => 'Zimbabwe' ) $data = array( 'Post' => array( 'id' => '7', 'postcategory_id' => '7', 'user_id' => '0', 'title' => 'How the PHP script may report what is the total size of any web page browsed', 'body' => '<p>These days excellent work is being done to attract web site users by creating attractive and well managed web pages. While browsing any internet site or a web page as developer or designer of the web pages we might came across the thought, “how much size of this web page is? or how much costly to render this on my browser?”. Well today lets build a script which reports information of above questions. As usual we will be using PHP for scripting the code. This script includes two things in consideration. <strong>First,</strong> how many http/https requests are being used to render the page and <strong>Second,</strong> what is the total size of the rendered web page. We will create a script in a manner that it can be used from command line interface as well as from the browser. For this the cURL module is used. If it is not installed in your PHP set up then go to my previous article of installation and configuration of PHP.</p> <p>Ok. So now what is the meaning of <strong>First</strong> part, “how many http/https requests are”. When any web page is rendered or loaded in your browser, it is a combination of one or multiple CSS files, one or multiple javascripts or .js files, code of Html, multiple images, etc… we call them web page resources as all together they make a web page. While web page is loaded all these multiple files are being called from one or different locations with specific web address. These files are called one by one as it cannot called all once at a time. The separate calls for each of these files are known as http/https requests.</p> <p>Now let’s come to the Second part of the task – “what is the total size of the rendered web page” and that consist of file size of each of these resource we saw above. When http/https requests are responded uninterrupted then that response contains response header (developers and designers knows that). One of the headers is called “Content-Length” and that gives the size of that particular resource. We need to use built in API of PHP ie. get_headers and the argument would be the URL where the http/https request is sent. Bellow is the hint and good start of the code in PHP.</p> <p><strong><em>function file_size_rendered($url) { </em></strong></p> <p><strong><em>//where $url in the argument is the location where request is being sent.</em></strong></p> <p><strong><em> $headers = get_headers($url, 1);</em></strong> </p> <p><strong><em> if (isset($headers['Content-Length'])) </em></strong></p> <p><strong><em> return $headers['Content-Length'];</em></strong> </p> <p><strong><em>//Also check whether lower case of "L" is used in Content-length</em></strong></p> <p><strong><em> if (isset($headers['Content-length'])) </em></strong></p> <p><strong><em> return $headers['Content-length'];</em></strong></p> <p><strong><em>//if the content header is not found then use the curl request</em></strong></p> <p><strong><em> $c = curl_init();</em></strong></p> <p><strong><em> curl_setopt_array($c, array(</em></strong></p> <p><strong><em> CURLOPT_URL => $url,</em></strong></p> <p><strong><em> CURLOPT_RETURNTRANSFER => true,</em></strong></p> <p><strong><em> CURLOPT_HTTPHEADER => array('User-Agent: Mozilla/5.0 </em></strong></p> <p><strong><em> (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.3) </em></strong></p> <p><strong><em> Gecko/20090824 Firefox/3.5.3'),</em></strong></p> <p><strong><em> ));</em></strong></p> <p><strong><em> curl_exec($c);</em></strong> </p> <p><strong><em> $size = curl_getinfo($c, CURLINFO_SIZE_DOWNLOAD);</em></strong> </p> <p><strong><em> return $size;</em></strong> </p> <p><strong><em> curl_close($c);</em></strong></p> <p><strong><em>}</em></strong></p> <p>This article is just a good start to inspire for deeper understanding or the technique of coding. One can browse more or post questions to get answer on more specific tasks.</p> ', 'comment_count' => '0', 'postview_count' => '1768', 'active' => '1', 'created' => '2015-12-28 10:52:20', 'modified' => '2019-11-21 06:00:37', 'tags' => 'PHP, Code, Tips' ), 'User' => array( 'id' => null, 'firstname' => null ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/how-the-php-script-may-62903-small.jpg', 'namemedium' => '/files/uploads/postimages/how-the-php-script-may-62903-medium.jpg' ), 'Rating' => array(), 'Tag' => array( (int) 0 => array( 'id' => '4', 'name' => 'PHP', 'keyname' => 'php', 'Tagged' => array( [maximum depth reached] ) ), (int) 1 => array( 'id' => '16', 'name' => 'Code', 'keyname' => 'code', 'Tagged' => array( [maximum depth reached] ) ), (int) 2 => array( 'id' => '17', 'name' => 'Tips', 'keyname' => 'tips', 'Tagged' => array( [maximum depth reached] ) ) ) ) $model = null $modelClass = null $submit_url = '/feedback/ratings/add' $element_id = 'rating-156490964' $message_id = 'message-156490964' $values_id = 'values-156490964' $readonly = 'false' $value = (int) 0 $votes = (int) 0 $user_vote = (int) 0 $user_vote_message = 'Your vote: 0.0' $submitting_message = 'Sending vote...' $error_message = 'There was an error while saving your vote'include - APP/Plugin/Feedback/View/Elements/rating.ctp, line 59 View::_evaluate() - CORE/Cake/View/View.php, line 971 View::_render() - CORE/Cake/View/View.php, line 933 View::_renderElement() - CORE/Cake/View/View.php, line 1224 View::element() - CORE/Cake/View/View.php, line 418 RatingsHelper::display_for() - APP/Plugin/Feedback/View/Helper/RatingsHelper.php, line 53 include - APP/View/Posts/filter.ctp, line 30 View::_evaluate() - CORE/Cake/View/View.php, line 971 View::_render() - CORE/Cake/View/View.php, line 933 View::render() - CORE/Cake/View/View.php, line 473 Controller::render() - CORE/Cake/Controller/Controller.php, line 963 Dispatcher::_invoke() - CORE/Cake/Routing/Dispatcher.php, line 200 Dispatcher::dispatch() - CORE/Cake/Routing/Dispatcher.php, line 167 [main] - APP/webroot/index.php, line 109
Developing secured web application with PHP
Warning (2): key() expects parameter 1 to be array, null given [APP/Plugin/Feedback/View/Helper/RatingsHelper.php, line 73]Code Contextif (empty($model) && empty($modelClass))
{
$modelClass = key($this->models);
$data = array( 'Post' => array( 'id' => '6', 'postcategory_id' => '8', 'user_id' => '1', 'title' => 'Developing secured web application with PHP', 'body' => '<p>Your PHP web application is deployed on the secured platform is great but it is not just enough to consider your application is secured. It is equally or more important that your source code is also developed in the same intensity of security and passed through security testing. I would like to propose certain check list to consider before you go live with your site. PHP is considered one of the easiest languages for developing web applications and this gives chance to startup developers to leave common PHP security pitfalls in development.</p> <p>Listed out bellow are few points which can be used as a check list before you publish your web application.</p> <ul> <li><strong><em>Character encoding:</em></strong> The thumb rule is always create a valid output and use UTF-8 for the encoding like in Html, Database, Html, JS, URLs, Emails and wherever it is possible.</li> <li><strong><em>User Input Data Validation:</em></strong> Validate the user input data according to which purpose it is collected from them. It is always a good idea to validate the user input data at the PHP logic even if your JavaScript validate it at the browser itself. Type-casting is also helpful in most of the cases.</li> <li><strong><em>CSRF or XSRF – Cross Site Request Forgeries: </em></strong>a request from the different site which misuses users authenticated stat data to hack or perform unwanted operations. While user is logged in, his session data is shared across all tabs in the same browser. Code the PHP script that way it uses minimum time of GET requests or probably only to access the information rather than transactions. Avoid using $_REQUEST as much possible instead use $_GET or $_POST accordingly wherever you retrieve variables.</li> </ul> <p>Another way is to generate a random value known as token while user successfully log in at the application. Store this token value in the session and check in application logic whenever user requests or post any information.</p> <ul> <li><strong><em>XSS – Cross site scripting: </em></strong>always validate HTML inputs from user’s submitted data in case like accepting comments on the posts, or collecting reviews and display them on the site. It may use to steal session an cookie data and run kind of JS script on the browser. Use strip_tags() and /or htmlspecialchars() functions which encode and prevent users data to create an HTML tags.</li> <li><strong><em>Non-disclose of file system</em></strong>: If your website allows to download any file to its users, always use some functions which takes file path as an internal system input and use respective header() arguments to download the file. Do not create a like for the file which displays whole folder structure in the link itself to download the file.</li> <li><strong><em>Restrict the file uploads</em></strong>: a user could upload a .php extension file or any other executable file through your file upload feature on site. Check the MIME type of the uploaded file with the function like finfo_file() or any similar to validate the type of file. Create an array of allowable file extensions and keep checking with the uploaded file extension is present in the allowable array or not.</li> <li><strong><em>SQL injection</em></strong>: any input which is concatenated into a string as an SQL query is called the SQL injection. Characters like semicolon, single quote, double quote, hyphens, etc which are used in the SQL queries or statements, should be escaped. This compromise the database and it allowed to be accessed by unauthorized way. Developer can use the pair of prepare () and execute () statement to execute the query rather than simply write a row query to fire on database. Most of the new generation frameworks for PHP take care of this.</li> <li>Other security measures includes <ul style="list-style-type:circle"> <li>Use a proper error handling.</li> <li>Always use .php extensions to included files.</li> <li>Filter values of “From” header before you create that in the Email function.</li> <li>Use strong password hashing algorithm while storing the passwords.</li> <li>Encrypt the session data before you store.</li> <li>Strong cipher code to encrypt data is also a good measure.</li> </ul> </li> </ul> <p style="margin-left:.25in">Web application security measures are taken at the time of designing its architecture. Also it should not happen that steps taken from the security point of view decreases the scope of usability. Security must be implemented keeping in the mind of your website users and must be included in the development budget.</p> <p style="margin-left:.25in">This is a short tutorial for PHP developers and has just stretched the surface of the development techniques. It is up to the developer who understands the depth of vulnerabilities and possible attacks on applications over the web. Developers are required to drill more on each points which are listed and /or which are left from discussion here.</p> ', 'comment_count' => '0', 'postview_count' => '1740', 'active' => '1', 'created' => '2015-07-17 13:54:47', 'modified' => '2019-11-21 06:01:23', 'tags' => 'PHP, Web Developement, Security' ), 'User' => array( 'id' => '1', 'firstname' => 'Chirayu' ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/developing-secured-web-application-65142-small.jpg', 'namemedium' => '/files/uploads/postimages/developing-secured-web-application-65142-medium.jpg' ), 'Rating' => array( (int) 0 => array( 'id' => '3', 'foreign_model' => 'Post', 'foreign_id' => '6', 'author_ip' => '123.239.58.58', 'rating' => '3.5', 'created' => '2015-07-17 16:15:56' ), (int) 1 => array( 'id' => '12', 'foreign_model' => 'Post', 'foreign_id' => '6', 'author_ip' => '103.241.226.4', 'rating' => '4.5', 'created' => '2020-07-12 15:43:47' ) ), 'Tag' => array( (int) 0 => array( 'id' => '4', 'name' => 'PHP', 'keyname' => 'php', 'Tagged' => array( [maximum depth reached] ) ), (int) 1 => array( 'id' => '14', 'name' => 'Web Developement', 'keyname' => 'webdevelopement', 'Tagged' => array( [maximum depth reached] ) ), (int) 2 => array( 'id' => '15', 'name' => 'Security', 'keyname' => 'security', 'Tagged' => array( [maximum depth reached] ) ) ), 'RatingSummary' => array( 'total_votes' => (int) 2, 'total_rating' => (float) 4 ) ) $options = array() $model = null $modelClass = nullkey - [internal], line ?? RatingsHelper::prepareParams() - APP/Plugin/Feedback/View/Helper/RatingsHelper.php, line 73 RatingsHelper::display_for() - APP/Plugin/Feedback/View/Helper/RatingsHelper.php, line 48 include - APP/View/Posts/filter.ctp, line 30 View::_evaluate() - CORE/Cake/View/View.php, line 971 View::_render() - CORE/Cake/View/View.php, line 933 View::render() - CORE/Cake/View/View.php, line 473 Controller::render() - CORE/Cake/Controller/Controller.php, line 963 Dispatcher::_invoke() - CORE/Cake/Routing/Dispatcher.php, line 200 Dispatcher::dispatch() - CORE/Cake/Routing/Dispatcher.php, line 167 [main] - APP/webroot/index.php, line 109
Warning (2): current() expects parameter 1 to be array, null given [APP/Plugin/Feedback/View/Helper/RatingsHelper.php, line 74]Code Context{
$modelClass = key($this->models);
$model = current($this->models);
$data = array( 'Post' => array( 'id' => '6', 'postcategory_id' => '8', 'user_id' => '1', 'title' => 'Developing secured web application with PHP', 'body' => '<p>Your PHP web application is deployed on the secured platform is great but it is not just enough to consider your application is secured. It is equally or more important that your source code is also developed in the same intensity of security and passed through security testing. I would like to propose certain check list to consider before you go live with your site. PHP is considered one of the easiest languages for developing web applications and this gives chance to startup developers to leave common PHP security pitfalls in development.</p> <p>Listed out bellow are few points which can be used as a check list before you publish your web application.</p> <ul> <li><strong><em>Character encoding:</em></strong> The thumb rule is always create a valid output and use UTF-8 for the encoding like in Html, Database, Html, JS, URLs, Emails and wherever it is possible.</li> <li><strong><em>User Input Data Validation:</em></strong> Validate the user input data according to which purpose it is collected from them. It is always a good idea to validate the user input data at the PHP logic even if your JavaScript validate it at the browser itself. Type-casting is also helpful in most of the cases.</li> <li><strong><em>CSRF or XSRF – Cross Site Request Forgeries: </em></strong>a request from the different site which misuses users authenticated stat data to hack or perform unwanted operations. While user is logged in, his session data is shared across all tabs in the same browser. Code the PHP script that way it uses minimum time of GET requests or probably only to access the information rather than transactions. Avoid using $_REQUEST as much possible instead use $_GET or $_POST accordingly wherever you retrieve variables.</li> </ul> <p>Another way is to generate a random value known as token while user successfully log in at the application. Store this token value in the session and check in application logic whenever user requests or post any information.</p> <ul> <li><strong><em>XSS – Cross site scripting: </em></strong>always validate HTML inputs from user’s submitted data in case like accepting comments on the posts, or collecting reviews and display them on the site. It may use to steal session an cookie data and run kind of JS script on the browser. Use strip_tags() and /or htmlspecialchars() functions which encode and prevent users data to create an HTML tags.</li> <li><strong><em>Non-disclose of file system</em></strong>: If your website allows to download any file to its users, always use some functions which takes file path as an internal system input and use respective header() arguments to download the file. Do not create a like for the file which displays whole folder structure in the link itself to download the file.</li> <li><strong><em>Restrict the file uploads</em></strong>: a user could upload a .php extension file or any other executable file through your file upload feature on site. Check the MIME type of the uploaded file with the function like finfo_file() or any similar to validate the type of file. Create an array of allowable file extensions and keep checking with the uploaded file extension is present in the allowable array or not.</li> <li><strong><em>SQL injection</em></strong>: any input which is concatenated into a string as an SQL query is called the SQL injection. Characters like semicolon, single quote, double quote, hyphens, etc which are used in the SQL queries or statements, should be escaped. This compromise the database and it allowed to be accessed by unauthorized way. Developer can use the pair of prepare () and execute () statement to execute the query rather than simply write a row query to fire on database. Most of the new generation frameworks for PHP take care of this.</li> <li>Other security measures includes <ul style="list-style-type:circle"> <li>Use a proper error handling.</li> <li>Always use .php extensions to included files.</li> <li>Filter values of “From” header before you create that in the Email function.</li> <li>Use strong password hashing algorithm while storing the passwords.</li> <li>Encrypt the session data before you store.</li> <li>Strong cipher code to encrypt data is also a good measure.</li> </ul> </li> </ul> <p style="margin-left:.25in">Web application security measures are taken at the time of designing its architecture. Also it should not happen that steps taken from the security point of view decreases the scope of usability. Security must be implemented keeping in the mind of your website users and must be included in the development budget.</p> <p style="margin-left:.25in">This is a short tutorial for PHP developers and has just stretched the surface of the development techniques. It is up to the developer who understands the depth of vulnerabilities and possible attacks on applications over the web. Developers are required to drill more on each points which are listed and /or which are left from discussion here.</p> ', 'comment_count' => '0', 'postview_count' => '1740', 'active' => '1', 'created' => '2015-07-17 13:54:47', 'modified' => '2019-11-21 06:01:23', 'tags' => 'PHP, Web Developement, Security' ), 'User' => array( 'id' => '1', 'firstname' => 'Chirayu' ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/developing-secured-web-application-65142-small.jpg', 'namemedium' => '/files/uploads/postimages/developing-secured-web-application-65142-medium.jpg' ), 'Rating' => array( (int) 0 => array( 'id' => '3', 'foreign_model' => 'Post', 'foreign_id' => '6', 'author_ip' => '123.239.58.58', 'rating' => '3.5', 'created' => '2015-07-17 16:15:56' ), (int) 1 => array( 'id' => '12', 'foreign_model' => 'Post', 'foreign_id' => '6', 'author_ip' => '103.241.226.4', 'rating' => '4.5', 'created' => '2020-07-12 15:43:47' ) ), 'Tag' => array( (int) 0 => array( 'id' => '4', 'name' => 'PHP', 'keyname' => 'php', 'Tagged' => array( [maximum depth reached] ) ), (int) 1 => array( 'id' => '14', 'name' => 'Web Developement', 'keyname' => 'webdevelopement', 'Tagged' => array( [maximum depth reached] ) ), (int) 2 => array( 'id' => '15', 'name' => 'Security', 'keyname' => 'security', 'Tagged' => array( [maximum depth reached] ) ) ), 'RatingSummary' => array( 'total_votes' => (int) 2, 'total_rating' => (float) 4 ) ) $options = array() $model = null $modelClass = nullcurrent - [internal], line ?? RatingsHelper::prepareParams() - APP/Plugin/Feedback/View/Helper/RatingsHelper.php, line 74 RatingsHelper::display_for() - APP/Plugin/Feedback/View/Helper/RatingsHelper.php, line 48 include - APP/View/Posts/filter.ctp, line 30 View::_evaluate() - CORE/Cake/View/View.php, line 971 View::_render() - CORE/Cake/View/View.php, line 933 View::render() - CORE/Cake/View/View.php, line 473 Controller::render() - CORE/Cake/Controller/Controller.php, line 963 Dispatcher::_invoke() - CORE/Cake/Routing/Dispatcher.php, line 200 Dispatcher::dispatch() - CORE/Cake/Routing/Dispatcher.php, line 167 [main] - APP/webroot/index.php, line 109
Notice (8): Undefined index: [APP/Plugin/Feedback/View/Helper/RatingsHelper.php, line 81]Code Context$message_id = 'message-'.$random_id;
$values_id = 'values-'.$random_id;
$id = $data[$modelClass]['id'];
$data = array( 'Post' => array( 'id' => '6', 'postcategory_id' => '8', 'user_id' => '1', 'title' => 'Developing secured web application with PHP', 'body' => '<p>Your PHP web application is deployed on the secured platform is great but it is not just enough to consider your application is secured. It is equally or more important that your source code is also developed in the same intensity of security and passed through security testing. I would like to propose certain check list to consider before you go live with your site. PHP is considered one of the easiest languages for developing web applications and this gives chance to startup developers to leave common PHP security pitfalls in development.</p> <p>Listed out bellow are few points which can be used as a check list before you publish your web application.</p> <ul> <li><strong><em>Character encoding:</em></strong> The thumb rule is always create a valid output and use UTF-8 for the encoding like in Html, Database, Html, JS, URLs, Emails and wherever it is possible.</li> <li><strong><em>User Input Data Validation:</em></strong> Validate the user input data according to which purpose it is collected from them. It is always a good idea to validate the user input data at the PHP logic even if your JavaScript validate it at the browser itself. Type-casting is also helpful in most of the cases.</li> <li><strong><em>CSRF or XSRF – Cross Site Request Forgeries: </em></strong>a request from the different site which misuses users authenticated stat data to hack or perform unwanted operations. While user is logged in, his session data is shared across all tabs in the same browser. Code the PHP script that way it uses minimum time of GET requests or probably only to access the information rather than transactions. Avoid using $_REQUEST as much possible instead use $_GET or $_POST accordingly wherever you retrieve variables.</li> </ul> <p>Another way is to generate a random value known as token while user successfully log in at the application. Store this token value in the session and check in application logic whenever user requests or post any information.</p> <ul> <li><strong><em>XSS – Cross site scripting: </em></strong>always validate HTML inputs from user’s submitted data in case like accepting comments on the posts, or collecting reviews and display them on the site. It may use to steal session an cookie data and run kind of JS script on the browser. Use strip_tags() and /or htmlspecialchars() functions which encode and prevent users data to create an HTML tags.</li> <li><strong><em>Non-disclose of file system</em></strong>: If your website allows to download any file to its users, always use some functions which takes file path as an internal system input and use respective header() arguments to download the file. Do not create a like for the file which displays whole folder structure in the link itself to download the file.</li> <li><strong><em>Restrict the file uploads</em></strong>: a user could upload a .php extension file or any other executable file through your file upload feature on site. Check the MIME type of the uploaded file with the function like finfo_file() or any similar to validate the type of file. Create an array of allowable file extensions and keep checking with the uploaded file extension is present in the allowable array or not.</li> <li><strong><em>SQL injection</em></strong>: any input which is concatenated into a string as an SQL query is called the SQL injection. Characters like semicolon, single quote, double quote, hyphens, etc which are used in the SQL queries or statements, should be escaped. This compromise the database and it allowed to be accessed by unauthorized way. Developer can use the pair of prepare () and execute () statement to execute the query rather than simply write a row query to fire on database. Most of the new generation frameworks for PHP take care of this.</li> <li>Other security measures includes <ul style="list-style-type:circle"> <li>Use a proper error handling.</li> <li>Always use .php extensions to included files.</li> <li>Filter values of “From” header before you create that in the Email function.</li> <li>Use strong password hashing algorithm while storing the passwords.</li> <li>Encrypt the session data before you store.</li> <li>Strong cipher code to encrypt data is also a good measure.</li> </ul> </li> </ul> <p style="margin-left:.25in">Web application security measures are taken at the time of designing its architecture. Also it should not happen that steps taken from the security point of view decreases the scope of usability. Security must be implemented keeping in the mind of your website users and must be included in the development budget.</p> <p style="margin-left:.25in">This is a short tutorial for PHP developers and has just stretched the surface of the development techniques. It is up to the developer who understands the depth of vulnerabilities and possible attacks on applications over the web. Developers are required to drill more on each points which are listed and /or which are left from discussion here.</p> ', 'comment_count' => '0', 'postview_count' => '1740', 'active' => '1', 'created' => '2015-07-17 13:54:47', 'modified' => '2019-11-21 06:01:23', 'tags' => 'PHP, Web Developement, Security' ), 'User' => array( 'id' => '1', 'firstname' => 'Chirayu' ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/developing-secured-web-application-65142-small.jpg', 'namemedium' => '/files/uploads/postimages/developing-secured-web-application-65142-medium.jpg' ), 'Rating' => array( (int) 0 => array( 'id' => '3', 'foreign_model' => 'Post', 'foreign_id' => '6', 'author_ip' => '123.239.58.58', 'rating' => '3.5', 'created' => '2015-07-17 16:15:56' ), (int) 1 => array( 'id' => '12', 'foreign_model' => 'Post', 'foreign_id' => '6', 'author_ip' => '103.241.226.4', 'rating' => '4.5', 'created' => '2020-07-12 15:43:47' ) ), 'Tag' => array( (int) 0 => array( 'id' => '4', 'name' => 'PHP', 'keyname' => 'php', 'Tagged' => array( [maximum depth reached] ) ), (int) 1 => array( 'id' => '14', 'name' => 'Web Developement', 'keyname' => 'webdevelopement', 'Tagged' => array( [maximum depth reached] ) ), (int) 2 => array( 'id' => '15', 'name' => 'Security', 'keyname' => 'security', 'Tagged' => array( [maximum depth reached] ) ) ), 'RatingSummary' => array( 'total_votes' => (int) 2, 'total_rating' => (float) 4 ) ) $options = array() $model = null $modelClass = null $random_id = (int) 1279000763 $element_id = 'rating-1279000763' $message_id = 'message-1279000763' $values_id = 'values-1279000763'RatingsHelper::prepareParams() - APP/Plugin/Feedback/View/Helper/RatingsHelper.php, line 81 RatingsHelper::display_for() - APP/Plugin/Feedback/View/Helper/RatingsHelper.php, line 48 include - APP/View/Posts/filter.ctp, line 30 View::_evaluate() - CORE/Cake/View/View.php, line 971 View::_render() - CORE/Cake/View/View.php, line 933 View::render() - CORE/Cake/View/View.php, line 473 Controller::render() - CORE/Cake/Controller/Controller.php, line 963 Dispatcher::_invoke() - CORE/Cake/Routing/Dispatcher.php, line 200 Dispatcher::dispatch() - CORE/Cake/Routing/Dispatcher.php, line 167 [main] - APP/webroot/index.php, line 109
Notice (8): Undefined index: [APP/Plugin/Feedback/View/Elements/rating.ctp, line 59]Code ContextRating: {
foreign_model: '{$modelClass}',
foreign_id: '{$data[$modelClass]['id']}',
$viewFile = '/var/www/html/chirayuim/app/Plugin/Feedback/View/Elements/rating.ctp' $dataForView = array( 'tags' => array( (int) 0 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 1 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 2 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 3 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 4 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 5 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 6 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 7 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 8 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 9 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 10 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 11 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 12 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 13 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 14 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 15 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 16 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 17 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 18 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 19 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ) ), 'postcategories' => array( (int) 0 => array( 'Postcategory' => array( [maximum depth reached] ), 'ParentPostcategory' => array( [maximum depth reached] ), 'ChildPostcategory' => array([maximum depth reached]), 'Post' => array( [maximum depth reached] ), 'children' => array([maximum depth reached]) ), (int) 1 => array( 'Postcategory' => array( [maximum depth reached] ), 'ParentPostcategory' => array( [maximum depth reached] ), 'ChildPostcategory' => array([maximum depth reached]), 'Post' => array( [maximum depth reached] ), 'children' => array([maximum depth reached]) ), (int) 2 => array( 'Postcategory' => array( [maximum depth reached] ), 'ParentPostcategory' => array( [maximum depth reached] ), 'ChildPostcategory' => array( [maximum depth reached] ), 'Post' => array( [maximum depth reached] ), 'children' => array( [maximum depth reached] ) ), (int) 3 => array( 'Postcategory' => array( [maximum depth reached] ), 'ParentPostcategory' => array( [maximum depth reached] ), 'ChildPostcategory' => array([maximum depth reached]), 'Post' => array( [maximum depth reached] ), 'children' => array([maximum depth reached]) ) ), 'posts' => array( (int) 0 => array( 'Post' => array( [maximum depth reached] ), 'User' => array( [maximum depth reached] ), 'Postcoverimage' => array( [maximum depth reached] ), 'Rating' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), 'RatingSummary' => array( [maximum depth reached] ) ), (int) 1 => array( 'Post' => array( [maximum depth reached] ), 'User' => array( [maximum depth reached] ), 'Postcoverimage' => array( [maximum depth reached] ), 'Rating' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), 'RatingSummary' => array( [maximum depth reached] ) ), (int) 2 => array( 'Post' => array( [maximum depth reached] ), 'User' => array( [maximum depth reached] ), 'Postcoverimage' => array( [maximum depth reached] ), 'Rating' => array([maximum depth reached]), 'Tag' => array( [maximum depth reached] ) ), (int) 3 => array( 'Post' => array( [maximum depth reached] ), 'User' => array( [maximum depth reached] ), 'Postcoverimage' => array( [maximum depth reached] ), 'Rating' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), 'RatingSummary' => array( [maximum depth reached] ) ), (int) 4 => array( 'Post' => array( [maximum depth reached] ), 'User' => array( [maximum depth reached] ), 'Postcoverimage' => array( [maximum depth reached] ), 'Rating' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), 'RatingSummary' => array( [maximum depth reached] ) ) ), 'masterclass' => '', 'appposts' => array( (int) 0 => array( 'Post' => array( [maximum depth reached] ), 'Postcoverimage' => array( [maximum depth reached] ), 'Tofriend' => array([maximum depth reached]) ), (int) 1 => array( 'Post' => array( [maximum depth reached] ), 'Postcoverimage' => array( [maximum depth reached] ), 'Tofriend' => array( [maximum depth reached] ) ), (int) 2 => array( 'Post' => array( [maximum depth reached] ), 'Postcoverimage' => array( [maximum depth reached] ), 'Tofriend' => array( [maximum depth reached] ) ), (int) 3 => array( 'Post' => array( [maximum depth reached] ), 'Postcoverimage' => array( [maximum depth reached] ), 'Tofriend' => array([maximum depth reached]) ), (int) 4 => array( 'Post' => array( [maximum depth reached] ), 'Postcoverimage' => array( [maximum depth reached] ), 'Tofriend' => array([maximum depth reached]) ) ), 'regions' => array(), 'appcountries' => array( (int) 1 => 'Andorra', (int) 2 => 'United Arab Emirates', (int) 3 => 'Afghanistan', (int) 4 => 'Antigua and Barbuda', (int) 5 => 'Anguilla', (int) 6 => 'Albania', (int) 7 => 'Armenia', (int) 8 => 'Netherlands Antilles', (int) 9 => 'Angola', (int) 12 => 'Argentina', (int) 13 => 'American Samoa', (int) 14 => 'Austria', (int) 15 => 'Australia', (int) 16 => 'Aruba', (int) 17 => 'Azerbaijan', (int) 18 => 'Bosnia and Herzegovina', (int) 19 => 'Barbados', (int) 20 => 'Bangladesh', (int) 21 => 'Belgium', (int) 22 => 'Burkina Faso', (int) 23 => 'Bulgaria', (int) 24 => 'Bahrain', (int) 25 => 'Burundi', (int) 26 => 'Benin', (int) 27 => 'Bermuda', (int) 28 => 'Brunei Darussalam', (int) 29 => 'Bolivia', (int) 30 => 'Brazil', (int) 31 => 'Bahamas', (int) 32 => 'Bhutan', (int) 34 => 'Botswana', (int) 35 => 'Belarus', (int) 36 => 'Belize', (int) 37 => 'Canada', (int) 38 => 'Cocos (Keeling) Islands', (int) 40 => 'Central African Republic', (int) 41 => 'Congo', (int) 42 => 'Switzerland', (int) 43 => 'Cote D'Ivoire', (int) 44 => 'Cook Islands', (int) 45 => 'Chile', (int) 46 => 'Cameroon', (int) 47 => 'China', (int) 48 => 'Colombia', (int) 49 => 'Costa Rica', (int) 51 => 'Cuba', (int) 52 => 'Cape Verde', (int) 53 => 'Christmas Island', (int) 54 => 'Cyprus', (int) 55 => 'Czech Republic', (int) 56 => 'Germany', (int) 57 => 'Djibouti', (int) 58 => 'Denmark', (int) 59 => 'Dominica', (int) 60 => 'Dominican Republic', (int) 61 => 'Algeria', (int) 62 => 'Ecuador', (int) 63 => 'Estonia', (int) 64 => 'Egypt', (int) 65 => 'Western Sahara', (int) 66 => 'Eritrea', (int) 67 => 'Spain', (int) 68 => 'Ethiopia', (int) 70 => 'Finland', (int) 71 => 'Fiji', (int) 72 => 'Falkland Islands (Malvinas)', (int) 73 => 'Micronesia, Federated States of', (int) 74 => 'Faroe Islands', (int) 75 => 'France', (int) 77 => 'Gabon', (int) 78 => 'United Kingdom', (int) 79 => 'Grenada', (int) 80 => 'Georgia', (int) 81 => 'French Guiana', (int) 82 => 'Ghana', (int) 83 => 'Gibraltar', (int) 84 => 'Greenland', (int) 85 => 'Gambia', (int) 86 => 'Guinea', (int) 87 => 'Guadeloupe', (int) 88 => 'Equatorial Guinea', (int) 89 => 'Greece', (int) 90 => 'South Georgia and Sandwich Island', (int) 91 => 'Guatemala', (int) 93 => 'Guinea-Bissau', (int) 94 => 'Guyana', (int) 95 => 'Hong Kong', (int) 97 => 'Honduras', (int) 98 => 'Croatia', (int) 99 => 'Haiti', (int) 100 => 'Hungary', (int) 101 => 'Indonesia', (int) 102 => 'Ireland', (int) 103 => 'Israel', (int) 104 => 'India', (int) 106 => 'Iraq', (int) 107 => 'Iran, Islamic Republic of', (int) 108 => 'Iceland', (int) 109 => 'Italy', (int) 110 => 'Jamaica', (int) 111 => 'Jordan', (int) 112 => 'Japan', (int) 113 => 'Kenya', (int) 114 => 'Kyrgyzstan', (int) 115 => 'Cambodia', (int) 116 => 'Kiribati', (int) 117 => 'Comoros', (int) 118 => 'Saint Kitts and Nevis', (int) 119 => 'Korea, Democratic', (int) 120 => 'Korea, Republic of', (int) 121 => 'Kuwait', (int) 122 => 'Cayman Islands', (int) 123 => 'Kazakhstan', (int) 124 => 'Laos', (int) 125 => 'Lebanon', (int) 126 => 'Saint Lucia', (int) 127 => 'Liechtenstein', (int) 128 => 'Sri Lanka', (int) 129 => 'Liberia', (int) 130 => 'Lesotho', (int) 131 => 'Lithuania', (int) 132 => 'Luxembourg', (int) 133 => 'Latvia', (int) 134 => 'Libya', (int) 135 => 'Morocco', (int) 136 => 'Monaco', (int) 137 => 'Moldova', (int) 138 => 'Madagascar', (int) 139 => 'Marshall Islands', (int) 140 => 'Macedonia', (int) 141 => 'Mali', (int) 142 => 'Myanmar', (int) 143 => 'Mongolia', (int) 144 => 'Macau', (int) 145 => 'Northern Mariana Islands', (int) 146 => 'Martinique', (int) 147 => 'Mauritania', (int) 148 => 'Montserrat', (int) 149 => 'Malta', (int) 150 => 'Mauritius', (int) 151 => 'Maldives', (int) 152 => 'Malawi', (int) 153 => 'Mexico', (int) 154 => 'Malaysia', (int) 155 => 'Mozambique', (int) 156 => 'Namibia', (int) 157 => 'New Caledonia', (int) 158 => 'Niger', (int) 159 => 'Norfolk Island', (int) 160 => 'Nigeria', (int) 161 => 'Nicaragua', (int) 162 => 'Netherlands', (int) 163 => 'Norway', (int) 164 => 'Nepal', (int) 165 => 'Nauru', (int) 166 => 'Niue', (int) 167 => 'New Zealand', (int) 168 => 'Oman', (int) 169 => 'Panama', (int) 170 => 'Peru', (int) 171 => 'French Polynesia', (int) 172 => 'Papua New Guinea', (int) 173 => 'Philippines', (int) 174 => 'Pakistan', (int) 175 => 'Poland', (int) 176 => 'Saint Pierre and Miquelon', (int) 177 => 'Pitcairn', (int) 180 => 'Portugal', (int) 181 => 'Palau', (int) 182 => 'Paraguay', (int) 183 => 'Qatar', (int) 184 => 'Reunion', (int) 185 => 'Romania', (int) 186 => 'Russian Federation', (int) 187 => 'Rwanda', (int) 188 => 'Saudi Arabia', (int) 189 => 'Solomon Islands', (int) 190 => 'Seychelles', (int) 191 => 'Sudan', (int) 192 => 'Sweden', (int) 193 => 'Singapore', (int) 194 => 'Saint Helena', (int) 195 => 'Slovenia', (int) 196 => 'Svalbard and Jan Mayen', (int) 197 => 'Slovakia', (int) 198 => 'Sierra Leone', (int) 199 => 'San Marino', (int) 200 => 'Senegal', (int) 201 => 'Somalia', (int) 202 => 'Suriname', (int) 203 => 'Sao Tome and Principe', (int) 204 => 'El Salvador', (int) 205 => 'Syrian Arab Republic', (int) 206 => 'Swaziland', (int) 207 => 'Turks and Caicos Islands', (int) 208 => 'Chad', (int) 209 => 'French Southern Territories', (int) 210 => 'Togo', (int) 211 => 'Thailand', (int) 212 => 'Tajikistan', (int) 213 => 'Tokelau', (int) 215 => 'Turkmenistan', (int) 216 => 'Tunisia', (int) 217 => 'Tonga', (int) 218 => 'Turkey', (int) 219 => 'Trinidad and Tobago', (int) 220 => 'Tuvalu', (int) 221 => 'Taiwan', (int) 222 => 'Tanzania, United Republic', (int) 223 => 'Ukraine', (int) 224 => 'Uganda', (int) 226 => 'United States', (int) 227 => 'Uruguay', (int) 228 => 'Uzbekistan', (int) 230 => 'Saint Vincent and the Grenadines', (int) 231 => 'Venezuela', (int) 232 => 'Virgin Islands, British', (int) 233 => 'Virgin Islands, U.S.', (int) 234 => 'Vietnam', (int) 235 => 'Vanuatu', (int) 236 => 'Wallis and Futuna', (int) 237 => 'Samoa', (int) 238 => 'Yemen', (int) 239 => 'Mayotte', (int) 240 => 'South Africa', (int) 241 => 'Zambia', (int) 242 => 'Zaire', (int) 243 => 'Zimbabwe' ), 'data' => array( 'Post' => array( 'id' => '6', 'postcategory_id' => '8', 'user_id' => '1', 'title' => 'Developing secured web application with PHP', 'body' => '<p>Your PHP web application is deployed on the secured platform is great but it is not just enough to consider your application is secured. It is equally or more important that your source code is also developed in the same intensity of security and passed through security testing. I would like to propose certain check list to consider before you go live with your site. PHP is considered one of the easiest languages for developing web applications and this gives chance to startup developers to leave common PHP security pitfalls in development.</p> <p>Listed out bellow are few points which can be used as a check list before you publish your web application.</p> <ul> <li><strong><em>Character encoding:</em></strong> The thumb rule is always create a valid output and use UTF-8 for the encoding like in Html, Database, Html, JS, URLs, Emails and wherever it is possible.</li> <li><strong><em>User Input Data Validation:</em></strong> Validate the user input data according to which purpose it is collected from them. It is always a good idea to validate the user input data at the PHP logic even if your JavaScript validate it at the browser itself. Type-casting is also helpful in most of the cases.</li> <li><strong><em>CSRF or XSRF – Cross Site Request Forgeries: </em></strong>a request from the different site which misuses users authenticated stat data to hack or perform unwanted operations. While user is logged in, his session data is shared across all tabs in the same browser. Code the PHP script that way it uses minimum time of GET requests or probably only to access the information rather than transactions. Avoid using $_REQUEST as much possible instead use $_GET or $_POST accordingly wherever you retrieve variables.</li> </ul> <p>Another way is to generate a random value known as token while user successfully log in at the application. Store this token value in the session and check in application logic whenever user requests or post any information.</p> <ul> <li><strong><em>XSS – Cross site scripting: </em></strong>always validate HTML inputs from user’s submitted data in case like accepting comments on the posts, or collecting reviews and display them on the site. It may use to steal session an cookie data and run kind of JS script on the browser. Use strip_tags() and /or htmlspecialchars() functions which encode and prevent users data to create an HTML tags.</li> <li><strong><em>Non-disclose of file system</em></strong>: If your website allows to download any file to its users, always use some functions which takes file path as an internal system input and use respective header() arguments to download the file. Do not create a like for the file which displays whole folder structure in the link itself to download the file.</li> <li><strong><em>Restrict the file uploads</em></strong>: a user could upload a .php extension file or any other executable file through your file upload feature on site. Check the MIME type of the uploaded file with the function like finfo_file() or any similar to validate the type of file. Create an array of allowable file extensions and keep checking with the uploaded file extension is present in the allowable array or not.</li> <li><strong><em>SQL injection</em></strong>: any input which is concatenated into a string as an SQL query is called the SQL injection. Characters like semicolon, single quote, double quote, hyphens, etc which are used in the SQL queries or statements, should be escaped. This compromise the database and it allowed to be accessed by unauthorized way. Developer can use the pair of prepare () and execute () statement to execute the query rather than simply write a row query to fire on database. Most of the new generation frameworks for PHP take care of this.</li> <li>Other security measures includes <ul style="list-style-type:circle"> <li>Use a proper error handling.</li> <li>Always use .php extensions to included files.</li> <li>Filter values of “From” header before you create that in the Email function.</li> <li>Use strong password hashing algorithm while storing the passwords.</li> <li>Encrypt the session data before you store.</li> <li>Strong cipher code to encrypt data is also a good measure.</li> </ul> </li> </ul> <p style="margin-left:.25in">Web application security measures are taken at the time of designing its architecture. Also it should not happen that steps taken from the security point of view decreases the scope of usability. Security must be implemented keeping in the mind of your website users and must be included in the development budget.</p> <p style="margin-left:.25in">This is a short tutorial for PHP developers and has just stretched the surface of the development techniques. It is up to the developer who understands the depth of vulnerabilities and possible attacks on applications over the web. Developers are required to drill more on each points which are listed and /or which are left from discussion here.</p> ', 'comment_count' => '0', 'postview_count' => '1740', 'active' => '1', 'created' => '2015-07-17 13:54:47', 'modified' => '2019-11-21 06:01:23', 'tags' => 'PHP, Web Developement, Security' ), 'User' => array( 'id' => '1', 'firstname' => 'Chirayu' ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/developing-secured-web-application-65142-small.jpg', 'namemedium' => '/files/uploads/postimages/developing-secured-web-application-65142-medium.jpg' ), 'Rating' => array( (int) 0 => array( [maximum depth reached] ), (int) 1 => array( [maximum depth reached] ) ), 'Tag' => array( (int) 0 => array( [maximum depth reached] ), (int) 1 => array( [maximum depth reached] ), (int) 2 => array( [maximum depth reached] ) ), 'RatingSummary' => array( 'total_votes' => (int) 2, 'total_rating' => (float) 4 ) ), 'model' => null, 'modelClass' => null, 'submit_url' => '/feedback/ratings/add', 'element_id' => 'rating-1279000763', 'message_id' => 'message-1279000763', 'values_id' => 'values-1279000763', 'readonly' => 'false', 'value' => (float) 4, 'votes' => (float) 2, 'user_vote' => (int) 0 ) $tags = array( (int) 0 => array( 'Tagged' => array( 'tag_id' => '1' ), 'Tag' => array( 'id' => '1', 'identifier' => null, 'name' => 'Configuration', 'keyname' => 'configuration', 'weight' => (float) 12, 'occurrence' => '2' ), (int) 0 => array( 'occurrence' => '2' ) ), (int) 1 => array( 'Tagged' => array( 'tag_id' => '2' ), 'Tag' => array( 'id' => '2', 'identifier' => null, 'name' => 'PHP5', 'keyname' => 'php5', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 2 => array( 'Tagged' => array( 'tag_id' => '3' ), 'Tag' => array( 'id' => '3', 'identifier' => null, 'name' => 'Apache2', 'keyname' => 'apache2', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 3 => array( 'Tagged' => array( 'tag_id' => '4' ), 'Tag' => array( 'id' => '4', 'identifier' => null, 'name' => 'PHP', 'keyname' => 'php', 'weight' => (float) 20, 'occurrence' => '6' ), (int) 0 => array( 'occurrence' => '6' ) ), (int) 4 => array( 'Tagged' => array( 'tag_id' => '5' ), 'Tag' => array( 'id' => '5', 'identifier' => null, 'name' => 'Sourcecode', 'keyname' => 'sourcecode', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 5 => array( 'Tagged' => array( 'tag_id' => '6' ), 'Tag' => array( 'id' => '6', 'identifier' => null, 'name' => 'Warnings', 'keyname' => 'warnings', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 6 => array( 'Tagged' => array( 'tag_id' => '7' ), 'Tag' => array( 'id' => '7', 'identifier' => null, 'name' => 'Timezone', 'keyname' => 'timezone', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 7 => array( 'Tagged' => array( 'tag_id' => '8' ), 'Tag' => array( 'id' => '8', 'identifier' => null, 'name' => 'Linux', 'keyname' => 'linux', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 8 => array( 'Tagged' => array( 'tag_id' => '9' ), 'Tag' => array( 'id' => '9', 'identifier' => null, 'name' => 'Apache', 'keyname' => 'apache', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 9 => array( 'Tagged' => array( 'tag_id' => '10' ), 'Tag' => array( 'id' => '10', 'identifier' => null, 'name' => 'Installation', 'keyname' => 'installation', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 10 => array( 'Tagged' => array( 'tag_id' => '11' ), 'Tag' => array( 'id' => '11', 'identifier' => null, 'name' => 'Open Authentication', 'keyname' => 'openauthentication', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 11 => array( 'Tagged' => array( 'tag_id' => '12' ), 'Tag' => array( 'id' => '12', 'identifier' => null, 'name' => 'Social Network Login', 'keyname' => 'socialnetworklogin', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 12 => array( 'Tagged' => array( 'tag_id' => '13' ), 'Tag' => array( 'id' => '13', 'identifier' => null, 'name' => 'oAuth', 'keyname' => 'oauth', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 13 => array( 'Tagged' => array( 'tag_id' => '14' ), 'Tag' => array( 'id' => '14', 'identifier' => null, 'name' => 'Web Developement', 'keyname' => 'webdevelopement', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 14 => array( 'Tagged' => array( 'tag_id' => '15' ), 'Tag' => array( 'id' => '15', 'identifier' => null, 'name' => 'Security', 'keyname' => 'security', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 15 => array( 'Tagged' => array( 'tag_id' => '16' ), 'Tag' => array( 'id' => '16', 'identifier' => null, 'name' => 'Code', 'keyname' => 'code', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 16 => array( 'Tagged' => array( 'tag_id' => '17' ), 'Tag' => array( 'id' => '17', 'identifier' => null, 'name' => 'Tips', 'keyname' => 'tips', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 17 => array( 'Tagged' => array( 'tag_id' => '18' ), 'Tag' => array( 'id' => '18', 'identifier' => null, 'name' => 'CSV files', 'keyname' => 'csvfiles', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 18 => array( 'Tagged' => array( 'tag_id' => '19' ), 'Tag' => array( 'id' => '19', 'identifier' => null, 'name' => 'File content', 'keyname' => 'filecontent', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 19 => array( 'Tagged' => array( 'tag_id' => '20' ), 'Tag' => array( 'id' => '20', 'identifier' => null, 'name' => 'Software Design', 'keyname' => 'softwaredesign', 'weight' => (float) 12, 'occurrence' => '2' ), (int) 0 => array( 'occurrence' => '2' ) ) ) $postcategories = array( (int) 0 => array( 'Postcategory' => array( 'id' => '5', 'parent_id' => null, 'name' => 'PHP Configuration', 'active' => '1', 'lft' => '1', 'rght' => '2', 'created' => '2015-05-06 13:24:33', 'modified' => '2015-05-06 13:24:33' ), 'ParentPostcategory' => array( 'id' => null, 'parent_id' => null, 'name' => null, 'active' => null, 'lft' => null, 'rght' => null, 'created' => null, 'modified' => null ), 'ChildPostcategory' => array(), 'Post' => array( (int) 0 => array( [maximum depth reached] ), (int) 1 => array( [maximum depth reached] ), (int) 2 => array( [maximum depth reached] ) ), 'children' => array() ), (int) 1 => array( 'Postcategory' => array( 'id' => '6', 'parent_id' => null, 'name' => 'PHP installation', 'active' => '1', 'lft' => '3', 'rght' => '4', 'created' => '2015-05-06 13:36:53', 'modified' => '2015-05-06 13:36:53' ), 'ParentPostcategory' => array( 'id' => null, 'parent_id' => null, 'name' => null, 'active' => null, 'lft' => null, 'rght' => null, 'created' => null, 'modified' => null ), 'ChildPostcategory' => array(), 'Post' => array( (int) 0 => array( [maximum depth reached] ) ), 'children' => array() ), (int) 2 => array( 'Postcategory' => array( 'id' => '7', 'parent_id' => null, 'name' => 'Web development', 'active' => '1', 'lft' => '5', 'rght' => '8', 'created' => '2015-06-06 05:44:15', 'modified' => '2015-06-06 05:44:15' ), 'ParentPostcategory' => array( 'id' => null, 'parent_id' => null, 'name' => null, 'active' => null, 'lft' => null, 'rght' => null, 'created' => null, 'modified' => null ), 'ChildPostcategory' => array( (int) 0 => array( [maximum depth reached] ) ), 'Post' => array( (int) 0 => array( [maximum depth reached] ), (int) 1 => array( [maximum depth reached] ), (int) 2 => array( [maximum depth reached] ) ), 'children' => array( (int) 0 => array( [maximum depth reached] ) ) ), (int) 3 => array( 'Postcategory' => array( 'id' => '9', 'parent_id' => null, 'name' => 'Software Design', 'active' => '1', 'lft' => '9', 'rght' => '10', 'created' => '2017-07-12 16:27:21', 'modified' => '2017-07-12 16:27:21' ), 'ParentPostcategory' => array( 'id' => null, 'parent_id' => null, 'name' => null, 'active' => null, 'lft' => null, 'rght' => null, 'created' => null, 'modified' => null ), 'ChildPostcategory' => array(), 'Post' => array( (int) 0 => array( [maximum depth reached] ), (int) 1 => array( [maximum depth reached] ) ), 'children' => array() ) ) $posts = array( (int) 0 => array( 'Post' => array( 'id' => '11', 'postcategory_id' => '8', 'user_id' => '1', 'title' => 'Connecting remote server using SSH', 'body' => '<p>SSH stands for secured shall - a secured network service over an unsecured network. It is a network protocol. It provides an encrypted data communication between two computers. SSH can be used interactively to enable terminal sessions. SSH is also used in scripts to remotely and securely access data and other resources. In order to connect to remote server with SSH, you need:</p> <p>1) Server IP or domain name</p> <p>2) Username</p> <p>3) Password</p> <p>4) SSH client - I recommend PuTTY (you can easily download from internet) for windows operating system while Linux and MAC users can use OpenSSH which is mostly installed in their OS.</p> <p><strong>Useful SSH commands frequently used by developers:</strong></p> <p><em>>_ ssh <remote_host></em></p> <p><remote_host> is an IP address or domain name that you are trying to connect to. This command assumes that your username on the remote system is the same as your username on your local system.</p> <p> <em>>_ ssh remote_username@<remote_host></em></p> <p>If your username is different on the remote system. You can specify by using this syntax.</p> <p>Once you are connected to the server, you will be asked to provide a password. SSH works by connecting a client program to an SSH server. In above commands, SSH is the client program. The SSH server is at the <em>remote_host</em> that is specified.</p> <p><strong>How to configure SSH</strong></p> <p>When you change the configuration of SSH, you are changing the settings of the sshd server. In Ubuntu, the main sshd configuration file is located at <em>/etc/ssh/sshd_config</em>.</p> <p>While it is helpful to be able to log in to a remote system using passwords, it is much better idea to set up Key-based authentication.</p> <p>Key based authentication works by creating a pair of keys: <strong>a private key</strong> and <strong>a public key.</strong></p> <p>The private key is located on the client machine. The public key is placed on any server you wish to access. Please check how to generate public and private keys with PuTTY for windows and with ssh-keygen for linux and mac OS. The folder in which the private key is placed default in the windows is c:\users\<username>\.ssh while in unix based system it is under /home/<username>/.ssh</p> <p>The public key is added to a special file within the user account you will be logging into called ~/.ssh/authorized_keys</p> <p>When you attempt to connect using a key pair, the server will use the public key to create a message for the client computer that can only be read with private key.</p> <p>The client computer then sends the appropriate response back to the server and the server will know that the client is legitimate. This entire process is done in the background after keys are correctly setup.</p> <p>SSH operates on TCP port 22 by default. The server listens on port 22 though this can be changed through custom port number in <em>sshd_config</em> file.</p> <p><em>>_ ssh -p</em> <em>7322 remote_username@<remote_host></em></p> <p>If you are not connecting <em>remote host</em> at the default port 22, then you need to specify the custom port number in the command. The above command shows remote host is being connected at the port number 7322.</p> ', 'comment_count' => '0', 'postview_count' => '1161', 'active' => '1', 'created' => '2019-11-29 13:06:49', 'modified' => '2019-11-29 13:06:49', 'tags' => 'SSH, Network, Secure' ), 'User' => array( 'id' => '1', 'firstname' => 'Chirayu' ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/ssh-connect-16148-small.jpg', 'namemedium' => '/files/uploads/postimages/ssh-connect-16148-medium.jpg' ), 'Rating' => array( (int) 0 => array( [maximum depth reached] ) ), 'Tag' => array( (int) 0 => array( [maximum depth reached] ), (int) 1 => array( [maximum depth reached] ), (int) 2 => array( [maximum depth reached] ) ), 'RatingSummary' => array( 'total_votes' => (int) 1, 'total_rating' => (float) 3.5 ) ), (int) 1 => array( 'Post' => array( 'id' => '8', 'postcategory_id' => '7', 'user_id' => '0', 'title' => 'CSV files data into php array to store in MySql', 'body' => '<p><strong><em>What are CSV files?</em></strong></p> <p>A CSV (Comma Separated Values) files are text files, allows data to be saved in a structured format. CSV files can be used with Microsoft Excel, Google Spreadsheets or Open Office Calc kind of tools. These CSV files are saved with .csv extension. In CSV files data fields are usually separated by comma as delimiter, but can also use a tab or pipe symbol instead of comma. CSV files are used to import and export data from application to application. Mostly, the first record is a header containing a list of field names. Any programming language has technique to import and export data from and to database like MS-SQL, MySql, PostGres, etc..</p> <p>PHP is one of the best programming languages for import and export of the data with the database to and from flat files like CSV files.</p> <p><strong><em>Fetching the data from the CSV file</em></strong></p> <p>Open the file in the read mode and store the content into variable. We assume that the CSV file contains the information about the contacts having fields firstname, lastname, email, and phone exported and the file name is contacts.csv.</p> <p>$csvfilehandle = fopen("contacts.csv","r");</p> <p>Here $csvfilehandle is file pointer to a file "contacts.csv" successfully opened</p> <p>while (($line = fgetcsv($csvfilehandle,1000,',','"'))!==false){</p> <p> $data[] = $line;</p> <p>}</p> <p>Close the opened file handle with </p> <p>fclose($csvfilehandle);</p> <p>The first argument $csvfilehandle is the mandatory arguments and remaining are optional.</p> <p>1000 is a length of characters per line to be set. This should be greater than the longest line in the file. If you are not sure about the length then don`t specify it.</p> <p>',' comma is a delimiter you can set or according to the data in the file the delimiter is used.</p> <p>'"' is the enclosure in the file used for the field value</p> <p>Now you have all the data of the CSV file into the array $data. If you print this with print_r($data); you get values into array.</p> <p><strong><em>Importing data into MySQL table</em></strong></p> <p>Now to import the data into the MySQL table named contacts, we need to modify the above wile loop. Let`s do that now.</p> <p>while (($line = fgetcsv($csvfilehandle,1000,',','"'))!==false){ </p> <p> mysql_query("insert into contacts(</p> <p> firstname, lastname, email, telephone</p> <p> )VALUES(</p> <p> '".mysql_real_escape_string($line[0])."',</p> <p> '".mysql_real_escape_string($line[1])."',</p> <p> '".mysql_real_escape_string($line[2])."',</p> <p> '".mysql_real_escape_string($line[3])."'</p> <p> )")</p> <p>or die(mysql_error());</p> <p>}</p> <p>fclose($csvfilehandle);</p> <p>Write me back if you are working for such functionality and not getting through the code.</p> ', 'comment_count' => '1', 'postview_count' => '1540', 'active' => '1', 'created' => '2016-11-03 07:17:48', 'modified' => '2019-11-21 06:00:03', 'tags' => 'PHP, CSV files, File content' ), 'User' => array( 'id' => null, 'firstname' => null ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/csv-files-data-into-88773-small.png', 'namemedium' => '/files/uploads/postimages/csv-files-data-into-88773-medium.png' ), 'Rating' => array( (int) 0 => array( [maximum depth reached] ) ), 'Tag' => array( (int) 0 => array( [maximum depth reached] ), (int) 1 => array( [maximum depth reached] ), (int) 2 => array( [maximum depth reached] ) ), 'RatingSummary' => array( 'total_votes' => (int) 1, 'total_rating' => (float) 2.5 ) ), (int) 2 => array( 'Post' => array( 'id' => '7', 'postcategory_id' => '7', 'user_id' => '0', 'title' => 'How the PHP script may report what is the total size of any web page browsed', 'body' => '<p>These days excellent work is being done to attract web site users by creating attractive and well managed web pages. While browsing any internet site or a web page as developer or designer of the web pages we might came across the thought, “how much size of this web page is? or how much costly to render this on my browser?”. Well today lets build a script which reports information of above questions. As usual we will be using PHP for scripting the code. This script includes two things in consideration. <strong>First,</strong> how many http/https requests are being used to render the page and <strong>Second,</strong> what is the total size of the rendered web page. We will create a script in a manner that it can be used from command line interface as well as from the browser. For this the cURL module is used. If it is not installed in your PHP set up then go to my previous article of installation and configuration of PHP.</p> <p>Ok. So now what is the meaning of <strong>First</strong> part, “how many http/https requests are”. When any web page is rendered or loaded in your browser, it is a combination of one or multiple CSS files, one or multiple javascripts or .js files, code of Html, multiple images, etc… we call them web page resources as all together they make a web page. While web page is loaded all these multiple files are being called from one or different locations with specific web address. These files are called one by one as it cannot called all once at a time. The separate calls for each of these files are known as http/https requests.</p> <p>Now let’s come to the Second part of the task – “what is the total size of the rendered web page” and that consist of file size of each of these resource we saw above. When http/https requests are responded uninterrupted then that response contains response header (developers and designers knows that). One of the headers is called “Content-Length” and that gives the size of that particular resource. We need to use built in API of PHP ie. get_headers and the argument would be the URL where the http/https request is sent. Bellow is the hint and good start of the code in PHP.</p> <p><strong><em>function file_size_rendered($url) { </em></strong></p> <p><strong><em>//where $url in the argument is the location where request is being sent.</em></strong></p> <p><strong><em> $headers = get_headers($url, 1);</em></strong> </p> <p><strong><em> if (isset($headers['Content-Length'])) </em></strong></p> <p><strong><em> return $headers['Content-Length'];</em></strong> </p> <p><strong><em>//Also check whether lower case of "L" is used in Content-length</em></strong></p> <p><strong><em> if (isset($headers['Content-length'])) </em></strong></p> <p><strong><em> return $headers['Content-length'];</em></strong></p> <p><strong><em>//if the content header is not found then use the curl request</em></strong></p> <p><strong><em> $c = curl_init();</em></strong></p> <p><strong><em> curl_setopt_array($c, array(</em></strong></p> <p><strong><em> CURLOPT_URL => $url,</em></strong></p> <p><strong><em> CURLOPT_RETURNTRANSFER => true,</em></strong></p> <p><strong><em> CURLOPT_HTTPHEADER => array('User-Agent: Mozilla/5.0 </em></strong></p> <p><strong><em> (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.3) </em></strong></p> <p><strong><em> Gecko/20090824 Firefox/3.5.3'),</em></strong></p> <p><strong><em> ));</em></strong></p> <p><strong><em> curl_exec($c);</em></strong> </p> <p><strong><em> $size = curl_getinfo($c, CURLINFO_SIZE_DOWNLOAD);</em></strong> </p> <p><strong><em> return $size;</em></strong> </p> <p><strong><em> curl_close($c);</em></strong></p> <p><strong><em>}</em></strong></p> <p>This article is just a good start to inspire for deeper understanding or the technique of coding. One can browse more or post questions to get answer on more specific tasks.</p> ', 'comment_count' => '0', 'postview_count' => '1768', 'active' => '1', 'created' => '2015-12-28 10:52:20', 'modified' => '2019-11-21 06:00:37', 'tags' => 'PHP, Code, Tips' ), 'User' => array( 'id' => null, 'firstname' => null ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/how-the-php-script-may-62903-small.jpg', 'namemedium' => '/files/uploads/postimages/how-the-php-script-may-62903-medium.jpg' ), 'Rating' => array(), 'Tag' => array( (int) 0 => array( [maximum depth reached] ), (int) 1 => array( [maximum depth reached] ), (int) 2 => array( [maximum depth reached] ) ) ), (int) 3 => array( 'Post' => array( 'id' => '6', 'postcategory_id' => '8', 'user_id' => '1', 'title' => 'Developing secured web application with PHP', 'body' => '<p>Your PHP web application is deployed on the secured platform is great but it is not just enough to consider your application is secured. It is equally or more important that your source code is also developed in the same intensity of security and passed through security testing. I would like to propose certain check list to consider before you go live with your site. PHP is considered one of the easiest languages for developing web applications and this gives chance to startup developers to leave common PHP security pitfalls in development.</p> <p>Listed out bellow are few points which can be used as a check list before you publish your web application.</p> <ul> <li><strong><em>Character encoding:</em></strong> The thumb rule is always create a valid output and use UTF-8 for the encoding like in Html, Database, Html, JS, URLs, Emails and wherever it is possible.</li> <li><strong><em>User Input Data Validation:</em></strong> Validate the user input data according to which purpose it is collected from them. It is always a good idea to validate the user input data at the PHP logic even if your JavaScript validate it at the browser itself. Type-casting is also helpful in most of the cases.</li> <li><strong><em>CSRF or XSRF – Cross Site Request Forgeries: </em></strong>a request from the different site which misuses users authenticated stat data to hack or perform unwanted operations. While user is logged in, his session data is shared across all tabs in the same browser. Code the PHP script that way it uses minimum time of GET requests or probably only to access the information rather than transactions. Avoid using $_REQUEST as much possible instead use $_GET or $_POST accordingly wherever you retrieve variables.</li> </ul> <p>Another way is to generate a random value known as token while user successfully log in at the application. Store this token value in the session and check in application logic whenever user requests or post any information.</p> <ul> <li><strong><em>XSS – Cross site scripting: </em></strong>always validate HTML inputs from user’s submitted data in case like accepting comments on the posts, or collecting reviews and display them on the site. It may use to steal session an cookie data and run kind of JS script on the browser. Use strip_tags() and /or htmlspecialchars() functions which encode and prevent users data to create an HTML tags.</li> <li><strong><em>Non-disclose of file system</em></strong>: If your website allows to download any file to its users, always use some functions which takes file path as an internal system input and use respective header() arguments to download the file. Do not create a like for the file which displays whole folder structure in the link itself to download the file.</li> <li><strong><em>Restrict the file uploads</em></strong>: a user could upload a .php extension file or any other executable file through your file upload feature on site. Check the MIME type of the uploaded file with the function like finfo_file() or any similar to validate the type of file. Create an array of allowable file extensions and keep checking with the uploaded file extension is present in the allowable array or not.</li> <li><strong><em>SQL injection</em></strong>: any input which is concatenated into a string as an SQL query is called the SQL injection. Characters like semicolon, single quote, double quote, hyphens, etc which are used in the SQL queries or statements, should be escaped. This compromise the database and it allowed to be accessed by unauthorized way. Developer can use the pair of prepare () and execute () statement to execute the query rather than simply write a row query to fire on database. Most of the new generation frameworks for PHP take care of this.</li> <li>Other security measures includes <ul style="list-style-type:circle"> <li>Use a proper error handling.</li> <li>Always use .php extensions to included files.</li> <li>Filter values of “From” header before you create that in the Email function.</li> <li>Use strong password hashing algorithm while storing the passwords.</li> <li>Encrypt the session data before you store.</li> <li>Strong cipher code to encrypt data is also a good measure.</li> </ul> </li> </ul> <p style="margin-left:.25in">Web application security measures are taken at the time of designing its architecture. Also it should not happen that steps taken from the security point of view decreases the scope of usability. Security must be implemented keeping in the mind of your website users and must be included in the development budget.</p> <p style="margin-left:.25in">This is a short tutorial for PHP developers and has just stretched the surface of the development techniques. It is up to the developer who understands the depth of vulnerabilities and possible attacks on applications over the web. Developers are required to drill more on each points which are listed and /or which are left from discussion here.</p> ', 'comment_count' => '0', 'postview_count' => '1740', 'active' => '1', 'created' => '2015-07-17 13:54:47', 'modified' => '2019-11-21 06:01:23', 'tags' => 'PHP, Web Developement, Security' ), 'User' => array( 'id' => '1', 'firstname' => 'Chirayu' ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/developing-secured-web-application-65142-small.jpg', 'namemedium' => '/files/uploads/postimages/developing-secured-web-application-65142-medium.jpg' ), 'Rating' => array( (int) 0 => array( [maximum depth reached] ), (int) 1 => array( [maximum depth reached] ) ), 'Tag' => array( (int) 0 => array( [maximum depth reached] ), (int) 1 => array( [maximum depth reached] ), (int) 2 => array( [maximum depth reached] ) ), 'RatingSummary' => array( 'total_votes' => (int) 2, 'total_rating' => (float) 4 ) ), (int) 4 => array( 'Post' => array( 'id' => '5', 'postcategory_id' => '7', 'user_id' => '1', 'title' => 'Social website login for your site is Open source standards for authorization', 'body' => '<p>You might have seen many of sites now showing links or buttons of Facebook, Twitter, Google + or other social network sites on their sign up and sign in page. This is to make users life bit easier for the login or sign up process on various websites. What happens when you click on any of that link? Have you tried anytime?</p> <p>Let’s see how you as a developer can develop this feature for your website. For this we consider a use case.</p> <p><em>User came to the sign in page of your site and he looked at the login with “facebook” or “twitter” or “google” (or any of the site) link. He has a separate account of any of these listed social network sites which you have integrated in your website. He clicks on any of the link and now he is redirected to the respective site for authentication. He provides correct credential for that social network site. He is now authenticated by that social network site and if it is for the first time he is using this authentication system, he has to agree to share his profile data with the other site from where he is coming for the authentication.</em></p> <p>When user agrees to share his profile data on successful login, that social network site redirect him to your site with user’s profile information. Of course password would not be sent to your site. This authenticating social network site will generate one token for this session and send along with the user’s profile data. This token is unique to user and your site. Now all communication and data exchange between your site and the authenticating social network site happens with this token generated by the authenticated site. Give essential profile data to your website login system and create a successful login session at your website and treat him as a logged in user.</p> <p> You can store this user information into your database and send an email to him with the new login credentials to login in your site directly in future. If he doesn’t want to login from your site directly, he still has an option to login again from the social network site which he chooses. Check every time while login weather he is the stored user with his unique field value like email address or username and if not found in your database store it and or otherwise directly give an authentication to the logged in section of your site.</p> <p>All of these redirections and authentications are made through APIs provided by these authenticating sites. Most of these sites do provide a sign in APIs but do not have the APIs for sign off from the authenticated site (There are few exceptions in this). Once user is logged in to your website through open authentication system via a different web site, he has to actually login into that website. Now when he clicks on the logout link of your site, he logs out from your site not from the site from where he was authenticated. This is risk if any user is accessing your site from the public computer and forgets to log off from the authenticated site. His account would be compromised.</p> <p>You as a developer of your site must provide information about the risk factors to your users before they use separate authentication system for your site. Developers need to create an account on these sites and get secret API key to use their APIs and use this secret key into data transactions with the site.</p> <p>Here are few providers of open authentication services are also called resource owners to authorize other web service or web site to their resources without sharing their users’ credentials.</p> <p>Amazon, Dropbox, Facebook, Flickr, GitHub, Instagram, LinkedIn, Twitter, Tumblrand …..And many of others.</p> ', 'comment_count' => '0', 'postview_count' => '2059', 'active' => '1', 'created' => '2015-06-15 08:15:29', 'modified' => '2019-11-21 06:01:51', 'tags' => 'Open Authentication, Social Network Login, oAuth' ), 'User' => array( 'id' => '1', 'firstname' => 'Chirayu' ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/social-website-login-for-65938-small.jpg', 'namemedium' => '/files/uploads/postimages/social-website-login-for-65938-medium.jpg' ), 'Rating' => array( (int) 0 => array( [maximum depth reached] ) ), 'Tag' => array( (int) 0 => array( [maximum depth reached] ), (int) 1 => array( [maximum depth reached] ), (int) 2 => array( [maximum depth reached] ) ), 'RatingSummary' => array( 'total_votes' => (int) 1, 'total_rating' => (float) 5 ) ) ) $masterclass = '' $appposts = array( (int) 0 => array( 'Post' => array( 'id' => '11', 'user_id' => '1', 'title' => 'Connecting remote server using SSH', 'body' => '<p>SSH stands for secured shall - a secured network service over an unsecured network. It is a network protocol. It provides an encrypted data communication between two computers. SSH can be used interactively to enable terminal sessions. SSH is also used in scripts to remotely and securely access data and other resources. In order to connect to remote server with SSH, you need:</p> <p>1) Server IP or domain name</p> <p>2) Username</p> <p>3) Password</p> <p>4) SSH client - I recommend PuTTY (you can easily download from internet) for windows operating system while Linux and MAC users can use OpenSSH which is mostly installed in their OS.</p> <p><strong>Useful SSH commands frequently used by developers:</strong></p> <p><em>>_ ssh <remote_host></em></p> <p><remote_host> is an IP address or domain name that you are trying to connect to. This command assumes that your username on the remote system is the same as your username on your local system.</p> <p> <em>>_ ssh remote_username@<remote_host></em></p> <p>If your username is different on the remote system. You can specify by using this syntax.</p> <p>Once you are connected to the server, you will be asked to provide a password. SSH works by connecting a client program to an SSH server. In above commands, SSH is the client program. The SSH server is at the <em>remote_host</em> that is specified.</p> <p><strong>How to configure SSH</strong></p> <p>When you change the configuration of SSH, you are changing the settings of the sshd server. In Ubuntu, the main sshd configuration file is located at <em>/etc/ssh/sshd_config</em>.</p> <p>While it is helpful to be able to log in to a remote system using passwords, it is much better idea to set up Key-based authentication.</p> <p>Key based authentication works by creating a pair of keys: <strong>a private key</strong> and <strong>a public key.</strong></p> <p>The private key is located on the client machine. The public key is placed on any server you wish to access. Please check how to generate public and private keys with PuTTY for windows and with ssh-keygen for linux and mac OS. The folder in which the private key is placed default in the windows is c:\users\<username>\.ssh while in unix based system it is under /home/<username>/.ssh</p> <p>The public key is added to a special file within the user account you will be logging into called ~/.ssh/authorized_keys</p> <p>When you attempt to connect using a key pair, the server will use the public key to create a message for the client computer that can only be read with private key.</p> <p>The client computer then sends the appropriate response back to the server and the server will know that the client is legitimate. This entire process is done in the background after keys are correctly setup.</p> <p>SSH operates on TCP port 22 by default. The server listens on port 22 though this can be changed through custom port number in <em>sshd_config</em> file.</p> <p><em>>_ ssh -p</em> <em>7322 remote_username@<remote_host></em></p> <p>If you are not connecting <em>remote host</em> at the default port 22, then you need to specify the custom port number in the command. The above command shows remote host is being connected at the port number 7322.</p> ', 'created' => '2019-11-29 13:06:49', 'tags' => '' ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/ssh-connect-16148-small.jpg', 'namemedium' => '/files/uploads/postimages/ssh-connect-16148-medium.jpg' ), 'Tofriend' => array() ), (int) 1 => array( 'Post' => array( 'id' => '10', 'user_id' => '0', 'title' => 'SOLID Part-2 : Principle of Open and Closed', 'body' => '<p>Any project has a scope of changes in terms of features, functionalities and workflows. Practically, to design application prefactly from begining is almost impossible even in the agile development. Classes and interfaces are pillers of application designs.</p> <p>SOLID is one of the proven set of design principles that are meant to guide developers to design and build robust, easily maintainable and scalable software.<br /> This article is focused ont he second principle of SOLID : The principle of Open / Closed.<br /> It satates that : Software entities (ie. classes, interfaces, functions etc) should be Open to extended but closed for modifications.<br /> Lets Check first what does it mean by this principle.</p> <p>A class is closed since it may be compiled, stored in the library, baselined and used by client classes. But it is also open, since any new class may use it as parent and adding new features.</p> <p>Fortunately we have a concept of Inheritance to achieve this goal. But, inheritance introduces tight coupling if the subclasses depend on implementation details of their parent class.</p> <p>my recomandation is to start designe inheritance with interfaces instead of superclasses. The interfaces are closed for modifications, you can provide new implementations to extend the functionality of your software.</p> <p>Let’s see an example that uses the Open/Closed Principle.</p> <p>We will need a Employee interface, the Company class, which uses the Employees, and some implementation of the Employee interface.<br /> The Company class should know just one thing about the Employees — what methods to call. This is what all the Employees have in common, so we will have a Employee interface with just the common methods(ie. someWork).</p> <p>public interface Employee{<br /> public void someWork();<br /> }</p> <p>And a Company class that encapsulates an Employye implementation and executes it.<br /> public class Company() {<br /> private Employee emp;<br /> // we set the strategy in the constructor<br /> public Company(Employee emp) {<br /> this.emp = emp;<br /> }</p> <p> public void completeTheWork() {<br /> this.emp.someWork();<br /> }<br /> }</p> <p>And let’s create two implementations for the Employee interface.</p> <p>public class Employee1 implements Employee {<br /> public void someWork() {<br /> System.out.println(“Work of Emoloyee 1”);<br /> }<br /> }</p> <p>public class Employee2 implements Employee {<br /> public void someWork() {<br /> System.out.println(“Work of Emoloyee 2”);<br /> }<br /> }</p> <p>Now lets use some dependency Injection to see how it works. We need to create one Perform class.</p> <p>public class Perform() {<br /> public static void main(String[] args) {<br /> Context context = new Company(new Employee1()); // we inject the Employee1<br /> context.completeTheWorky(); // it will print “Execute employee 1”;</p> <p> context = new Company(new Employee2()); // we inject the Employee2<br /> context.completeTheWork(); // it will print “Execute employee 2”<br /> }<br /> }</p> <p>So the Company is decoupled from a specific Employee class. You could implement many Employees it needed and no matter how they work and what you want them to do, you don’t need to modify the Company class. The Company class knows just that it must call someWork method and it is enough.</p> <p>After taking a closer look at the Single Responsibility Principle, we now discussed the Open/Closed Principle.<br /> It uses Interfaces to enable you the functionality of your application without changing the existing code.</p> ', 'created' => '2019-05-24 11:59:08', 'tags' => '' ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/Solid-part-2-28564-small.jpg', 'namemedium' => '/files/uploads/postimages/Solid-part-2-28564-medium.jpg' ), 'Tofriend' => array( (int) 0 => array( [maximum depth reached] ) ) ), (int) 2 => array( 'Post' => array( 'id' => '9', 'user_id' => '0', 'title' => 'SOLID Part-1 : Single Responsibility Principle - Software design', 'body' => '<p>S O L I D</p> <p>'S' represents Single Responsibility Principle</p> <p>Every class should have responsibility over a single part of the functionality provided by the software and that responsibility should be entirely encapsulated by the class. In other words there should never be more than one trigger or reason for a class to change. When a (functional) responsibility is divided over more than one class, all classes’ part of that responsibility has to change.</p> <p>The code must be maintainable. When we need to make a change in a class having more responsibilities the change might affect the other functionality related to the other responsibility of the class. The code, which cannot adapt to change requirements with ease, is not a well defined.</p> <p>When we design our classes, we should take care that one class at the most is responsible for doing only one task or single responsibility. Not only should the class, even operations or methods in the class defined in a way that it has only one responsibility to handle. To understand this let us take an example of Employee class. Class Employee is made with few of its attributes and operations.</p> <p>Class Employee{</p> <p> private String employeeId;</p> <p> private String name;</p> <p> private string address;</p> <p> private Date dateOfJoining;</p> <p> private Int DesignationId;</p> <p> </p> <p> public amtIncrement(){</p> <p> //increment logic implementation</p> <p> }</p> <p> public calDOR(){</p> <p> //Date of retirement logic implementation</p> <p> } </p> <p> public setDateOfJoining(){</p> <p> }</p> <p> public setEmployeeId(){</p> <p> }</p> <p> public getDateOfJoining(){</p> <p> }</p> <p> public getDesignationId(){ </p> <p> } </p> <p>}</p> <p>The above class is correctly structured and it has employee attributes declared. Also it has operations related to employee.</p> <p>Here Employee class should have only responsibility to maintain and manage the data of employee in formations. But this class is violating the principle of Single Responsibility. How?</p> <p><strong>First,</strong> the logic of calculating the Date of Retirement is not the employee's responsibility. This might be defined under the HR class and calculate by taking employee's Date of Joining in the organization which is an attribute of Employee class. So if any change happens in the HR policies, the Employee Class does not get updated. Just because HR policies updated this has nothing to do with the Employee entity.</p> <p><strong>Second,</strong> the logic of calculating the amount of increment is a responsibility of Finance class and it calculated by taking the level or designation of the employee in the organization. So if any change happens to the financial status, the Employee class doesn’t get affected with that.</p> <p>If the class has only one reason to change then it stays less fragile. More responsibilities lead to more dependencies and higher coupling. A test class for a ‘one responsibility class’ will have less test cases (branches). If a class has one purpose it will usually have less dependencies, thus less mocking and test preparing.</p> <p>The Single Responsibility Principle represents a good way of identifying classes during the design phase of an application and it reminds you to think of all the ways a class can evolve. Class and module design is highly affected by SRP and it leads to a low coupled design with less and lighter dependencies.</p> <p>Points to consider when you design the class.</p> <ul> <li>Define clearly what this class is going to do.</li> <li>Reduce the long procedures of the logic. Divide into multiple chunks.</li> <li>Write the code in the way that very small steps can be tested independently.</li> </ul> ', 'created' => '2017-07-12 16:42:05', 'tags' => '' ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/Solid-part-1-50472-small.jpg', 'namemedium' => '/files/uploads/postimages/Solid-part-1-50472-medium.jpg' ), 'Tofriend' => array( (int) 0 => array( [maximum depth reached] ), (int) 1 => array( [maximum depth reached] ), (int) 2 => array( [maximum depth reached] ) ) ), (int) 3 => array( 'Post' => array( 'id' => '8', 'user_id' => '0', 'title' => 'CSV files data into php array to store in MySql', 'body' => '<p><strong><em>What are CSV files?</em></strong></p> <p>A CSV (Comma Separated Values) files are text files, allows data to be saved in a structured format. CSV files can be used with Microsoft Excel, Google Spreadsheets or Open Office Calc kind of tools. These CSV files are saved with .csv extension. In CSV files data fields are usually separated by comma as delimiter, but can also use a tab or pipe symbol instead of comma. CSV files are used to import and export data from application to application. Mostly, the first record is a header containing a list of field names. Any programming language has technique to import and export data from and to database like MS-SQL, MySql, PostGres, etc..</p> <p>PHP is one of the best programming languages for import and export of the data with the database to and from flat files like CSV files.</p> <p><strong><em>Fetching the data from the CSV file</em></strong></p> <p>Open the file in the read mode and store the content into variable. We assume that the CSV file contains the information about the contacts having fields firstname, lastname, email, and phone exported and the file name is contacts.csv.</p> <p>$csvfilehandle = fopen("contacts.csv","r");</p> <p>Here $csvfilehandle is file pointer to a file "contacts.csv" successfully opened</p> <p>while (($line = fgetcsv($csvfilehandle,1000,',','"'))!==false){</p> <p> $data[] = $line;</p> <p>}</p> <p>Close the opened file handle with </p> <p>fclose($csvfilehandle);</p> <p>The first argument $csvfilehandle is the mandatory arguments and remaining are optional.</p> <p>1000 is a length of characters per line to be set. This should be greater than the longest line in the file. If you are not sure about the length then don`t specify it.</p> <p>',' comma is a delimiter you can set or according to the data in the file the delimiter is used.</p> <p>'"' is the enclosure in the file used for the field value</p> <p>Now you have all the data of the CSV file into the array $data. If you print this with print_r($data); you get values into array.</p> <p><strong><em>Importing data into MySQL table</em></strong></p> <p>Now to import the data into the MySQL table named contacts, we need to modify the above wile loop. Let`s do that now.</p> <p>while (($line = fgetcsv($csvfilehandle,1000,',','"'))!==false){ </p> <p> mysql_query("insert into contacts(</p> <p> firstname, lastname, email, telephone</p> <p> )VALUES(</p> <p> '".mysql_real_escape_string($line[0])."',</p> <p> '".mysql_real_escape_string($line[1])."',</p> <p> '".mysql_real_escape_string($line[2])."',</p> <p> '".mysql_real_escape_string($line[3])."'</p> <p> )")</p> <p>or die(mysql_error());</p> <p>}</p> <p>fclose($csvfilehandle);</p> <p>Write me back if you are working for such functionality and not getting through the code.</p> ', 'created' => '2016-11-03 07:17:48', 'tags' => '' ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/csv-files-data-into-88773-small.png', 'namemedium' => '/files/uploads/postimages/csv-files-data-into-88773-medium.png' ), 'Tofriend' => array() ), (int) 4 => array( 'Post' => array( 'id' => '7', 'user_id' => '0', 'title' => 'How the PHP script may report what is the total size of any web page browsed', 'body' => '<p>These days excellent work is being done to attract web site users by creating attractive and well managed web pages. While browsing any internet site or a web page as developer or designer of the web pages we might came across the thought, “how much size of this web page is? or how much costly to render this on my browser?”. Well today lets build a script which reports information of above questions. As usual we will be using PHP for scripting the code. This script includes two things in consideration. <strong>First,</strong> how many http/https requests are being used to render the page and <strong>Second,</strong> what is the total size of the rendered web page. We will create a script in a manner that it can be used from command line interface as well as from the browser. For this the cURL module is used. If it is not installed in your PHP set up then go to my previous article of installation and configuration of PHP.</p> <p>Ok. So now what is the meaning of <strong>First</strong> part, “how many http/https requests are”. When any web page is rendered or loaded in your browser, it is a combination of one or multiple CSS files, one or multiple javascripts or .js files, code of Html, multiple images, etc… we call them web page resources as all together they make a web page. While web page is loaded all these multiple files are being called from one or different locations with specific web address. These files are called one by one as it cannot called all once at a time. The separate calls for each of these files are known as http/https requests.</p> <p>Now let’s come to the Second part of the task – “what is the total size of the rendered web page” and that consist of file size of each of these resource we saw above. When http/https requests are responded uninterrupted then that response contains response header (developers and designers knows that). One of the headers is called “Content-Length” and that gives the size of that particular resource. We need to use built in API of PHP ie. get_headers and the argument would be the URL where the http/https request is sent. Bellow is the hint and good start of the code in PHP.</p> <p><strong><em>function file_size_rendered($url) { </em></strong></p> <p><strong><em>//where $url in the argument is the location where request is being sent.</em></strong></p> <p><strong><em> $headers = get_headers($url, 1);</em></strong> </p> <p><strong><em> if (isset($headers['Content-Length'])) </em></strong></p> <p><strong><em> return $headers['Content-Length'];</em></strong> </p> <p><strong><em>//Also check whether lower case of "L" is used in Content-length</em></strong></p> <p><strong><em> if (isset($headers['Content-length'])) </em></strong></p> <p><strong><em> return $headers['Content-length'];</em></strong></p> <p><strong><em>//if the content header is not found then use the curl request</em></strong></p> <p><strong><em> $c = curl_init();</em></strong></p> <p><strong><em> curl_setopt_array($c, array(</em></strong></p> <p><strong><em> CURLOPT_URL => $url,</em></strong></p> <p><strong><em> CURLOPT_RETURNTRANSFER => true,</em></strong></p> <p><strong><em> CURLOPT_HTTPHEADER => array('User-Agent: Mozilla/5.0 </em></strong></p> <p><strong><em> (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.3) </em></strong></p> <p><strong><em> Gecko/20090824 Firefox/3.5.3'),</em></strong></p> <p><strong><em> ));</em></strong></p> <p><strong><em> curl_exec($c);</em></strong> </p> <p><strong><em> $size = curl_getinfo($c, CURLINFO_SIZE_DOWNLOAD);</em></strong> </p> <p><strong><em> return $size;</em></strong> </p> <p><strong><em> curl_close($c);</em></strong></p> <p><strong><em>}</em></strong></p> <p>This article is just a good start to inspire for deeper understanding or the technique of coding. One can browse more or post questions to get answer on more specific tasks.</p> ', 'created' => '2015-12-28 10:52:20', 'tags' => '' ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/how-the-php-script-may-62903-small.jpg', 'namemedium' => '/files/uploads/postimages/how-the-php-script-may-62903-medium.jpg' ), 'Tofriend' => array() ) ) $regions = array() $appcountries = array( (int) 1 => 'Andorra', (int) 2 => 'United Arab Emirates', (int) 3 => 'Afghanistan', (int) 4 => 'Antigua and Barbuda', (int) 5 => 'Anguilla', (int) 6 => 'Albania', (int) 7 => 'Armenia', (int) 8 => 'Netherlands Antilles', (int) 9 => 'Angola', (int) 12 => 'Argentina', (int) 13 => 'American Samoa', (int) 14 => 'Austria', (int) 15 => 'Australia', (int) 16 => 'Aruba', (int) 17 => 'Azerbaijan', (int) 18 => 'Bosnia and Herzegovina', (int) 19 => 'Barbados', (int) 20 => 'Bangladesh', (int) 21 => 'Belgium', (int) 22 => 'Burkina Faso', (int) 23 => 'Bulgaria', (int) 24 => 'Bahrain', (int) 25 => 'Burundi', (int) 26 => 'Benin', (int) 27 => 'Bermuda', (int) 28 => 'Brunei Darussalam', (int) 29 => 'Bolivia', (int) 30 => 'Brazil', (int) 31 => 'Bahamas', (int) 32 => 'Bhutan', (int) 34 => 'Botswana', (int) 35 => 'Belarus', (int) 36 => 'Belize', (int) 37 => 'Canada', (int) 38 => 'Cocos (Keeling) Islands', (int) 40 => 'Central African Republic', (int) 41 => 'Congo', (int) 42 => 'Switzerland', (int) 43 => 'Cote D'Ivoire', (int) 44 => 'Cook Islands', (int) 45 => 'Chile', (int) 46 => 'Cameroon', (int) 47 => 'China', (int) 48 => 'Colombia', (int) 49 => 'Costa Rica', (int) 51 => 'Cuba', (int) 52 => 'Cape Verde', (int) 53 => 'Christmas Island', (int) 54 => 'Cyprus', (int) 55 => 'Czech Republic', (int) 56 => 'Germany', (int) 57 => 'Djibouti', (int) 58 => 'Denmark', (int) 59 => 'Dominica', (int) 60 => 'Dominican Republic', (int) 61 => 'Algeria', (int) 62 => 'Ecuador', (int) 63 => 'Estonia', (int) 64 => 'Egypt', (int) 65 => 'Western Sahara', (int) 66 => 'Eritrea', (int) 67 => 'Spain', (int) 68 => 'Ethiopia', (int) 70 => 'Finland', (int) 71 => 'Fiji', (int) 72 => 'Falkland Islands (Malvinas)', (int) 73 => 'Micronesia, Federated States of', (int) 74 => 'Faroe Islands', (int) 75 => 'France', (int) 77 => 'Gabon', (int) 78 => 'United Kingdom', (int) 79 => 'Grenada', (int) 80 => 'Georgia', (int) 81 => 'French Guiana', (int) 82 => 'Ghana', (int) 83 => 'Gibraltar', (int) 84 => 'Greenland', (int) 85 => 'Gambia', (int) 86 => 'Guinea', (int) 87 => 'Guadeloupe', (int) 88 => 'Equatorial Guinea', (int) 89 => 'Greece', (int) 90 => 'South Georgia and Sandwich Island', (int) 91 => 'Guatemala', (int) 93 => 'Guinea-Bissau', (int) 94 => 'Guyana', (int) 95 => 'Hong Kong', (int) 97 => 'Honduras', (int) 98 => 'Croatia', (int) 99 => 'Haiti', (int) 100 => 'Hungary', (int) 101 => 'Indonesia', (int) 102 => 'Ireland', (int) 103 => 'Israel', (int) 104 => 'India', (int) 106 => 'Iraq', (int) 107 => 'Iran, Islamic Republic of', (int) 108 => 'Iceland', (int) 109 => 'Italy', (int) 110 => 'Jamaica', (int) 111 => 'Jordan', (int) 112 => 'Japan', (int) 113 => 'Kenya', (int) 114 => 'Kyrgyzstan', (int) 115 => 'Cambodia', (int) 116 => 'Kiribati', (int) 117 => 'Comoros', (int) 118 => 'Saint Kitts and Nevis', (int) 119 => 'Korea, Democratic', (int) 120 => 'Korea, Republic of', (int) 121 => 'Kuwait', (int) 122 => 'Cayman Islands', (int) 123 => 'Kazakhstan', (int) 124 => 'Laos', (int) 125 => 'Lebanon', (int) 126 => 'Saint Lucia', (int) 127 => 'Liechtenstein', (int) 128 => 'Sri Lanka', (int) 129 => 'Liberia', (int) 130 => 'Lesotho', (int) 131 => 'Lithuania', (int) 132 => 'Luxembourg', (int) 133 => 'Latvia', (int) 134 => 'Libya', (int) 135 => 'Morocco', (int) 136 => 'Monaco', (int) 137 => 'Moldova', (int) 138 => 'Madagascar', (int) 139 => 'Marshall Islands', (int) 140 => 'Macedonia', (int) 141 => 'Mali', (int) 142 => 'Myanmar', (int) 143 => 'Mongolia', (int) 144 => 'Macau', (int) 145 => 'Northern Mariana Islands', (int) 146 => 'Martinique', (int) 147 => 'Mauritania', (int) 148 => 'Montserrat', (int) 149 => 'Malta', (int) 150 => 'Mauritius', (int) 151 => 'Maldives', (int) 152 => 'Malawi', (int) 153 => 'Mexico', (int) 154 => 'Malaysia', (int) 155 => 'Mozambique', (int) 156 => 'Namibia', (int) 157 => 'New Caledonia', (int) 158 => 'Niger', (int) 159 => 'Norfolk Island', (int) 160 => 'Nigeria', (int) 161 => 'Nicaragua', (int) 162 => 'Netherlands', (int) 163 => 'Norway', (int) 164 => 'Nepal', (int) 165 => 'Nauru', (int) 166 => 'Niue', (int) 167 => 'New Zealand', (int) 168 => 'Oman', (int) 169 => 'Panama', (int) 170 => 'Peru', (int) 171 => 'French Polynesia', (int) 172 => 'Papua New Guinea', (int) 173 => 'Philippines', (int) 174 => 'Pakistan', (int) 175 => 'Poland', (int) 176 => 'Saint Pierre and Miquelon', (int) 177 => 'Pitcairn', (int) 180 => 'Portugal', (int) 181 => 'Palau', (int) 182 => 'Paraguay', (int) 183 => 'Qatar', (int) 184 => 'Reunion', (int) 185 => 'Romania', (int) 186 => 'Russian Federation', (int) 187 => 'Rwanda', (int) 188 => 'Saudi Arabia', (int) 189 => 'Solomon Islands', (int) 190 => 'Seychelles', (int) 191 => 'Sudan', (int) 192 => 'Sweden', (int) 193 => 'Singapore', (int) 194 => 'Saint Helena', (int) 195 => 'Slovenia', (int) 196 => 'Svalbard and Jan Mayen', (int) 197 => 'Slovakia', (int) 198 => 'Sierra Leone', (int) 199 => 'San Marino', (int) 200 => 'Senegal', (int) 201 => 'Somalia', (int) 202 => 'Suriname', (int) 203 => 'Sao Tome and Principe', (int) 204 => 'El Salvador', (int) 205 => 'Syrian Arab Republic', (int) 206 => 'Swaziland', (int) 207 => 'Turks and Caicos Islands', (int) 208 => 'Chad', (int) 209 => 'French Southern Territories', (int) 210 => 'Togo', (int) 211 => 'Thailand', (int) 212 => 'Tajikistan', (int) 213 => 'Tokelau', (int) 215 => 'Turkmenistan', (int) 216 => 'Tunisia', (int) 217 => 'Tonga', (int) 218 => 'Turkey', (int) 219 => 'Trinidad and Tobago', (int) 220 => 'Tuvalu', (int) 221 => 'Taiwan', (int) 222 => 'Tanzania, United Republic', (int) 223 => 'Ukraine', (int) 224 => 'Uganda', (int) 226 => 'United States', (int) 227 => 'Uruguay', (int) 228 => 'Uzbekistan', (int) 230 => 'Saint Vincent and the Grenadines', (int) 231 => 'Venezuela', (int) 232 => 'Virgin Islands, British', (int) 233 => 'Virgin Islands, U.S.', (int) 234 => 'Vietnam', (int) 235 => 'Vanuatu', (int) 236 => 'Wallis and Futuna', (int) 237 => 'Samoa', (int) 238 => 'Yemen', (int) 239 => 'Mayotte', (int) 240 => 'South Africa', (int) 241 => 'Zambia', (int) 242 => 'Zaire', (int) 243 => 'Zimbabwe' ) $data = array( 'Post' => array( 'id' => '6', 'postcategory_id' => '8', 'user_id' => '1', 'title' => 'Developing secured web application with PHP', 'body' => '<p>Your PHP web application is deployed on the secured platform is great but it is not just enough to consider your application is secured. It is equally or more important that your source code is also developed in the same intensity of security and passed through security testing. I would like to propose certain check list to consider before you go live with your site. PHP is considered one of the easiest languages for developing web applications and this gives chance to startup developers to leave common PHP security pitfalls in development.</p> <p>Listed out bellow are few points which can be used as a check list before you publish your web application.</p> <ul> <li><strong><em>Character encoding:</em></strong> The thumb rule is always create a valid output and use UTF-8 for the encoding like in Html, Database, Html, JS, URLs, Emails and wherever it is possible.</li> <li><strong><em>User Input Data Validation:</em></strong> Validate the user input data according to which purpose it is collected from them. It is always a good idea to validate the user input data at the PHP logic even if your JavaScript validate it at the browser itself. Type-casting is also helpful in most of the cases.</li> <li><strong><em>CSRF or XSRF – Cross Site Request Forgeries: </em></strong>a request from the different site which misuses users authenticated stat data to hack or perform unwanted operations. While user is logged in, his session data is shared across all tabs in the same browser. Code the PHP script that way it uses minimum time of GET requests or probably only to access the information rather than transactions. Avoid using $_REQUEST as much possible instead use $_GET or $_POST accordingly wherever you retrieve variables.</li> </ul> <p>Another way is to generate a random value known as token while user successfully log in at the application. Store this token value in the session and check in application logic whenever user requests or post any information.</p> <ul> <li><strong><em>XSS – Cross site scripting: </em></strong>always validate HTML inputs from user’s submitted data in case like accepting comments on the posts, or collecting reviews and display them on the site. It may use to steal session an cookie data and run kind of JS script on the browser. Use strip_tags() and /or htmlspecialchars() functions which encode and prevent users data to create an HTML tags.</li> <li><strong><em>Non-disclose of file system</em></strong>: If your website allows to download any file to its users, always use some functions which takes file path as an internal system input and use respective header() arguments to download the file. Do not create a like for the file which displays whole folder structure in the link itself to download the file.</li> <li><strong><em>Restrict the file uploads</em></strong>: a user could upload a .php extension file or any other executable file through your file upload feature on site. Check the MIME type of the uploaded file with the function like finfo_file() or any similar to validate the type of file. Create an array of allowable file extensions and keep checking with the uploaded file extension is present in the allowable array or not.</li> <li><strong><em>SQL injection</em></strong>: any input which is concatenated into a string as an SQL query is called the SQL injection. Characters like semicolon, single quote, double quote, hyphens, etc which are used in the SQL queries or statements, should be escaped. This compromise the database and it allowed to be accessed by unauthorized way. Developer can use the pair of prepare () and execute () statement to execute the query rather than simply write a row query to fire on database. Most of the new generation frameworks for PHP take care of this.</li> <li>Other security measures includes <ul style="list-style-type:circle"> <li>Use a proper error handling.</li> <li>Always use .php extensions to included files.</li> <li>Filter values of “From” header before you create that in the Email function.</li> <li>Use strong password hashing algorithm while storing the passwords.</li> <li>Encrypt the session data before you store.</li> <li>Strong cipher code to encrypt data is also a good measure.</li> </ul> </li> </ul> <p style="margin-left:.25in">Web application security measures are taken at the time of designing its architecture. Also it should not happen that steps taken from the security point of view decreases the scope of usability. Security must be implemented keeping in the mind of your website users and must be included in the development budget.</p> <p style="margin-left:.25in">This is a short tutorial for PHP developers and has just stretched the surface of the development techniques. It is up to the developer who understands the depth of vulnerabilities and possible attacks on applications over the web. Developers are required to drill more on each points which are listed and /or which are left from discussion here.</p> ', 'comment_count' => '0', 'postview_count' => '1740', 'active' => '1', 'created' => '2015-07-17 13:54:47', 'modified' => '2019-11-21 06:01:23', 'tags' => 'PHP, Web Developement, Security' ), 'User' => array( 'id' => '1', 'firstname' => 'Chirayu' ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/developing-secured-web-application-65142-small.jpg', 'namemedium' => '/files/uploads/postimages/developing-secured-web-application-65142-medium.jpg' ), 'Rating' => array( (int) 0 => array( 'id' => '3', 'foreign_model' => 'Post', 'foreign_id' => '6', 'author_ip' => '123.239.58.58', 'rating' => '3.5', 'created' => '2015-07-17 16:15:56' ), (int) 1 => array( 'id' => '12', 'foreign_model' => 'Post', 'foreign_id' => '6', 'author_ip' => '103.241.226.4', 'rating' => '4.5', 'created' => '2020-07-12 15:43:47' ) ), 'Tag' => array( (int) 0 => array( 'id' => '4', 'name' => 'PHP', 'keyname' => 'php', 'Tagged' => array( [maximum depth reached] ) ), (int) 1 => array( 'id' => '14', 'name' => 'Web Developement', 'keyname' => 'webdevelopement', 'Tagged' => array( [maximum depth reached] ) ), (int) 2 => array( 'id' => '15', 'name' => 'Security', 'keyname' => 'security', 'Tagged' => array( [maximum depth reached] ) ) ), 'RatingSummary' => array( 'total_votes' => (int) 2, 'total_rating' => (float) 4 ) ) $model = null $modelClass = null $submit_url = '/feedback/ratings/add' $element_id = 'rating-1279000763' $message_id = 'message-1279000763' $values_id = 'values-1279000763' $readonly = 'false' $value = (float) 4 $votes = (float) 2 $user_vote = (int) 0 $user_vote_message = 'Your vote: 0.0' $submitting_message = 'Sending vote...' $error_message = 'There was an error while saving your vote'include - APP/Plugin/Feedback/View/Elements/rating.ctp, line 59 View::_evaluate() - CORE/Cake/View/View.php, line 971 View::_render() - CORE/Cake/View/View.php, line 933 View::_renderElement() - CORE/Cake/View/View.php, line 1224 View::element() - CORE/Cake/View/View.php, line 418 RatingsHelper::display_for() - APP/Plugin/Feedback/View/Helper/RatingsHelper.php, line 53 include - APP/View/Posts/filter.ctp, line 30 View::_evaluate() - CORE/Cake/View/View.php, line 971 View::_render() - CORE/Cake/View/View.php, line 933 View::render() - CORE/Cake/View/View.php, line 473 Controller::render() - CORE/Cake/Controller/Controller.php, line 963 Dispatcher::_invoke() - CORE/Cake/Routing/Dispatcher.php, line 200 Dispatcher::dispatch() - CORE/Cake/Routing/Dispatcher.php, line 167 [main] - APP/webroot/index.php, line 109
Social website login for your site is Open source standards for aut...
Warning (2): key() expects parameter 1 to be array, null given [APP/Plugin/Feedback/View/Helper/RatingsHelper.php, line 73]Code Contextif (empty($model) && empty($modelClass))
{
$modelClass = key($this->models);
$data = array( 'Post' => array( 'id' => '5', 'postcategory_id' => '7', 'user_id' => '1', 'title' => 'Social website login for your site is Open source standards for authorization', 'body' => '<p>You might have seen many of sites now showing links or buttons of Facebook, Twitter, Google + or other social network sites on their sign up and sign in page. This is to make users life bit easier for the login or sign up process on various websites. What happens when you click on any of that link? Have you tried anytime?</p> <p>Let’s see how you as a developer can develop this feature for your website. For this we consider a use case.</p> <p><em>User came to the sign in page of your site and he looked at the login with “facebook” or “twitter” or “google” (or any of the site) link. He has a separate account of any of these listed social network sites which you have integrated in your website. He clicks on any of the link and now he is redirected to the respective site for authentication. He provides correct credential for that social network site. He is now authenticated by that social network site and if it is for the first time he is using this authentication system, he has to agree to share his profile data with the other site from where he is coming for the authentication.</em></p> <p>When user agrees to share his profile data on successful login, that social network site redirect him to your site with user’s profile information. Of course password would not be sent to your site. This authenticating social network site will generate one token for this session and send along with the user’s profile data. This token is unique to user and your site. Now all communication and data exchange between your site and the authenticating social network site happens with this token generated by the authenticated site. Give essential profile data to your website login system and create a successful login session at your website and treat him as a logged in user.</p> <p> You can store this user information into your database and send an email to him with the new login credentials to login in your site directly in future. If he doesn’t want to login from your site directly, he still has an option to login again from the social network site which he chooses. Check every time while login weather he is the stored user with his unique field value like email address or username and if not found in your database store it and or otherwise directly give an authentication to the logged in section of your site.</p> <p>All of these redirections and authentications are made through APIs provided by these authenticating sites. Most of these sites do provide a sign in APIs but do not have the APIs for sign off from the authenticated site (There are few exceptions in this). Once user is logged in to your website through open authentication system via a different web site, he has to actually login into that website. Now when he clicks on the logout link of your site, he logs out from your site not from the site from where he was authenticated. This is risk if any user is accessing your site from the public computer and forgets to log off from the authenticated site. His account would be compromised.</p> <p>You as a developer of your site must provide information about the risk factors to your users before they use separate authentication system for your site. Developers need to create an account on these sites and get secret API key to use their APIs and use this secret key into data transactions with the site.</p> <p>Here are few providers of open authentication services are also called resource owners to authorize other web service or web site to their resources without sharing their users’ credentials.</p> <p>Amazon, Dropbox, Facebook, Flickr, GitHub, Instagram, LinkedIn, Twitter, Tumblrand …..And many of others.</p> ', 'comment_count' => '0', 'postview_count' => '2059', 'active' => '1', 'created' => '2015-06-15 08:15:29', 'modified' => '2019-11-21 06:01:51', 'tags' => 'Open Authentication, Social Network Login, oAuth' ), 'User' => array( 'id' => '1', 'firstname' => 'Chirayu' ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/social-website-login-for-65938-small.jpg', 'namemedium' => '/files/uploads/postimages/social-website-login-for-65938-medium.jpg' ), 'Rating' => array( (int) 0 => array( 'id' => '2', 'foreign_model' => 'Post', 'foreign_id' => '5', 'author_ip' => '101.56.103.146', 'rating' => '5', 'created' => '2015-06-15 16:13:35' ) ), 'Tag' => array( (int) 0 => array( 'id' => '11', 'name' => 'Open Authentication', 'keyname' => 'openauthentication', 'Tagged' => array( [maximum depth reached] ) ), (int) 1 => array( 'id' => '12', 'name' => 'Social Network Login', 'keyname' => 'socialnetworklogin', 'Tagged' => array( [maximum depth reached] ) ), (int) 2 => array( 'id' => '13', 'name' => 'oAuth', 'keyname' => 'oauth', 'Tagged' => array( [maximum depth reached] ) ) ), 'RatingSummary' => array( 'total_votes' => (int) 1, 'total_rating' => (float) 5 ) ) $options = array() $model = null $modelClass = nullkey - [internal], line ?? RatingsHelper::prepareParams() - APP/Plugin/Feedback/View/Helper/RatingsHelper.php, line 73 RatingsHelper::display_for() - APP/Plugin/Feedback/View/Helper/RatingsHelper.php, line 48 include - APP/View/Posts/filter.ctp, line 30 View::_evaluate() - CORE/Cake/View/View.php, line 971 View::_render() - CORE/Cake/View/View.php, line 933 View::render() - CORE/Cake/View/View.php, line 473 Controller::render() - CORE/Cake/Controller/Controller.php, line 963 Dispatcher::_invoke() - CORE/Cake/Routing/Dispatcher.php, line 200 Dispatcher::dispatch() - CORE/Cake/Routing/Dispatcher.php, line 167 [main] - APP/webroot/index.php, line 109
Warning (2): current() expects parameter 1 to be array, null given [APP/Plugin/Feedback/View/Helper/RatingsHelper.php, line 74]Code Context{
$modelClass = key($this->models);
$model = current($this->models);
$data = array( 'Post' => array( 'id' => '5', 'postcategory_id' => '7', 'user_id' => '1', 'title' => 'Social website login for your site is Open source standards for authorization', 'body' => '<p>You might have seen many of sites now showing links or buttons of Facebook, Twitter, Google + or other social network sites on their sign up and sign in page. This is to make users life bit easier for the login or sign up process on various websites. What happens when you click on any of that link? Have you tried anytime?</p> <p>Let’s see how you as a developer can develop this feature for your website. For this we consider a use case.</p> <p><em>User came to the sign in page of your site and he looked at the login with “facebook” or “twitter” or “google” (or any of the site) link. He has a separate account of any of these listed social network sites which you have integrated in your website. He clicks on any of the link and now he is redirected to the respective site for authentication. He provides correct credential for that social network site. He is now authenticated by that social network site and if it is for the first time he is using this authentication system, he has to agree to share his profile data with the other site from where he is coming for the authentication.</em></p> <p>When user agrees to share his profile data on successful login, that social network site redirect him to your site with user’s profile information. Of course password would not be sent to your site. This authenticating social network site will generate one token for this session and send along with the user’s profile data. This token is unique to user and your site. Now all communication and data exchange between your site and the authenticating social network site happens with this token generated by the authenticated site. Give essential profile data to your website login system and create a successful login session at your website and treat him as a logged in user.</p> <p> You can store this user information into your database and send an email to him with the new login credentials to login in your site directly in future. If he doesn’t want to login from your site directly, he still has an option to login again from the social network site which he chooses. Check every time while login weather he is the stored user with his unique field value like email address or username and if not found in your database store it and or otherwise directly give an authentication to the logged in section of your site.</p> <p>All of these redirections and authentications are made through APIs provided by these authenticating sites. Most of these sites do provide a sign in APIs but do not have the APIs for sign off from the authenticated site (There are few exceptions in this). Once user is logged in to your website through open authentication system via a different web site, he has to actually login into that website. Now when he clicks on the logout link of your site, he logs out from your site not from the site from where he was authenticated. This is risk if any user is accessing your site from the public computer and forgets to log off from the authenticated site. His account would be compromised.</p> <p>You as a developer of your site must provide information about the risk factors to your users before they use separate authentication system for your site. Developers need to create an account on these sites and get secret API key to use their APIs and use this secret key into data transactions with the site.</p> <p>Here are few providers of open authentication services are also called resource owners to authorize other web service or web site to their resources without sharing their users’ credentials.</p> <p>Amazon, Dropbox, Facebook, Flickr, GitHub, Instagram, LinkedIn, Twitter, Tumblrand …..And many of others.</p> ', 'comment_count' => '0', 'postview_count' => '2059', 'active' => '1', 'created' => '2015-06-15 08:15:29', 'modified' => '2019-11-21 06:01:51', 'tags' => 'Open Authentication, Social Network Login, oAuth' ), 'User' => array( 'id' => '1', 'firstname' => 'Chirayu' ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/social-website-login-for-65938-small.jpg', 'namemedium' => '/files/uploads/postimages/social-website-login-for-65938-medium.jpg' ), 'Rating' => array( (int) 0 => array( 'id' => '2', 'foreign_model' => 'Post', 'foreign_id' => '5', 'author_ip' => '101.56.103.146', 'rating' => '5', 'created' => '2015-06-15 16:13:35' ) ), 'Tag' => array( (int) 0 => array( 'id' => '11', 'name' => 'Open Authentication', 'keyname' => 'openauthentication', 'Tagged' => array( [maximum depth reached] ) ), (int) 1 => array( 'id' => '12', 'name' => 'Social Network Login', 'keyname' => 'socialnetworklogin', 'Tagged' => array( [maximum depth reached] ) ), (int) 2 => array( 'id' => '13', 'name' => 'oAuth', 'keyname' => 'oauth', 'Tagged' => array( [maximum depth reached] ) ) ), 'RatingSummary' => array( 'total_votes' => (int) 1, 'total_rating' => (float) 5 ) ) $options = array() $model = null $modelClass = nullcurrent - [internal], line ?? RatingsHelper::prepareParams() - APP/Plugin/Feedback/View/Helper/RatingsHelper.php, line 74 RatingsHelper::display_for() - APP/Plugin/Feedback/View/Helper/RatingsHelper.php, line 48 include - APP/View/Posts/filter.ctp, line 30 View::_evaluate() - CORE/Cake/View/View.php, line 971 View::_render() - CORE/Cake/View/View.php, line 933 View::render() - CORE/Cake/View/View.php, line 473 Controller::render() - CORE/Cake/Controller/Controller.php, line 963 Dispatcher::_invoke() - CORE/Cake/Routing/Dispatcher.php, line 200 Dispatcher::dispatch() - CORE/Cake/Routing/Dispatcher.php, line 167 [main] - APP/webroot/index.php, line 109
Notice (8): Undefined index: [APP/Plugin/Feedback/View/Helper/RatingsHelper.php, line 81]Code Context$message_id = 'message-'.$random_id;
$values_id = 'values-'.$random_id;
$id = $data[$modelClass]['id'];
$data = array( 'Post' => array( 'id' => '5', 'postcategory_id' => '7', 'user_id' => '1', 'title' => 'Social website login for your site is Open source standards for authorization', 'body' => '<p>You might have seen many of sites now showing links or buttons of Facebook, Twitter, Google + or other social network sites on their sign up and sign in page. This is to make users life bit easier for the login or sign up process on various websites. What happens when you click on any of that link? Have you tried anytime?</p> <p>Let’s see how you as a developer can develop this feature for your website. For this we consider a use case.</p> <p><em>User came to the sign in page of your site and he looked at the login with “facebook” or “twitter” or “google” (or any of the site) link. He has a separate account of any of these listed social network sites which you have integrated in your website. He clicks on any of the link and now he is redirected to the respective site for authentication. He provides correct credential for that social network site. He is now authenticated by that social network site and if it is for the first time he is using this authentication system, he has to agree to share his profile data with the other site from where he is coming for the authentication.</em></p> <p>When user agrees to share his profile data on successful login, that social network site redirect him to your site with user’s profile information. Of course password would not be sent to your site. This authenticating social network site will generate one token for this session and send along with the user’s profile data. This token is unique to user and your site. Now all communication and data exchange between your site and the authenticating social network site happens with this token generated by the authenticated site. Give essential profile data to your website login system and create a successful login session at your website and treat him as a logged in user.</p> <p> You can store this user information into your database and send an email to him with the new login credentials to login in your site directly in future. If he doesn’t want to login from your site directly, he still has an option to login again from the social network site which he chooses. Check every time while login weather he is the stored user with his unique field value like email address or username and if not found in your database store it and or otherwise directly give an authentication to the logged in section of your site.</p> <p>All of these redirections and authentications are made through APIs provided by these authenticating sites. Most of these sites do provide a sign in APIs but do not have the APIs for sign off from the authenticated site (There are few exceptions in this). Once user is logged in to your website through open authentication system via a different web site, he has to actually login into that website. Now when he clicks on the logout link of your site, he logs out from your site not from the site from where he was authenticated. This is risk if any user is accessing your site from the public computer and forgets to log off from the authenticated site. His account would be compromised.</p> <p>You as a developer of your site must provide information about the risk factors to your users before they use separate authentication system for your site. Developers need to create an account on these sites and get secret API key to use their APIs and use this secret key into data transactions with the site.</p> <p>Here are few providers of open authentication services are also called resource owners to authorize other web service or web site to their resources without sharing their users’ credentials.</p> <p>Amazon, Dropbox, Facebook, Flickr, GitHub, Instagram, LinkedIn, Twitter, Tumblrand …..And many of others.</p> ', 'comment_count' => '0', 'postview_count' => '2059', 'active' => '1', 'created' => '2015-06-15 08:15:29', 'modified' => '2019-11-21 06:01:51', 'tags' => 'Open Authentication, Social Network Login, oAuth' ), 'User' => array( 'id' => '1', 'firstname' => 'Chirayu' ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/social-website-login-for-65938-small.jpg', 'namemedium' => '/files/uploads/postimages/social-website-login-for-65938-medium.jpg' ), 'Rating' => array( (int) 0 => array( 'id' => '2', 'foreign_model' => 'Post', 'foreign_id' => '5', 'author_ip' => '101.56.103.146', 'rating' => '5', 'created' => '2015-06-15 16:13:35' ) ), 'Tag' => array( (int) 0 => array( 'id' => '11', 'name' => 'Open Authentication', 'keyname' => 'openauthentication', 'Tagged' => array( [maximum depth reached] ) ), (int) 1 => array( 'id' => '12', 'name' => 'Social Network Login', 'keyname' => 'socialnetworklogin', 'Tagged' => array( [maximum depth reached] ) ), (int) 2 => array( 'id' => '13', 'name' => 'oAuth', 'keyname' => 'oauth', 'Tagged' => array( [maximum depth reached] ) ) ), 'RatingSummary' => array( 'total_votes' => (int) 1, 'total_rating' => (float) 5 ) ) $options = array() $model = null $modelClass = null $random_id = (int) 789843234 $element_id = 'rating-789843234' $message_id = 'message-789843234' $values_id = 'values-789843234'RatingsHelper::prepareParams() - APP/Plugin/Feedback/View/Helper/RatingsHelper.php, line 81 RatingsHelper::display_for() - APP/Plugin/Feedback/View/Helper/RatingsHelper.php, line 48 include - APP/View/Posts/filter.ctp, line 30 View::_evaluate() - CORE/Cake/View/View.php, line 971 View::_render() - CORE/Cake/View/View.php, line 933 View::render() - CORE/Cake/View/View.php, line 473 Controller::render() - CORE/Cake/Controller/Controller.php, line 963 Dispatcher::_invoke() - CORE/Cake/Routing/Dispatcher.php, line 200 Dispatcher::dispatch() - CORE/Cake/Routing/Dispatcher.php, line 167 [main] - APP/webroot/index.php, line 109
Notice (8): Undefined index: [APP/Plugin/Feedback/View/Elements/rating.ctp, line 59]Code ContextRating: {
foreign_model: '{$modelClass}',
foreign_id: '{$data[$modelClass]['id']}',
$viewFile = '/var/www/html/chirayuim/app/Plugin/Feedback/View/Elements/rating.ctp' $dataForView = array( 'tags' => array( (int) 0 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 1 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 2 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 3 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 4 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 5 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 6 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 7 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 8 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 9 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 10 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 11 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 12 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 13 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 14 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 15 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 16 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 17 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 18 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ), (int) 19 => array( 'Tagged' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), (int) 0 => array( [maximum depth reached] ) ) ), 'postcategories' => array( (int) 0 => array( 'Postcategory' => array( [maximum depth reached] ), 'ParentPostcategory' => array( [maximum depth reached] ), 'ChildPostcategory' => array([maximum depth reached]), 'Post' => array( [maximum depth reached] ), 'children' => array([maximum depth reached]) ), (int) 1 => array( 'Postcategory' => array( [maximum depth reached] ), 'ParentPostcategory' => array( [maximum depth reached] ), 'ChildPostcategory' => array([maximum depth reached]), 'Post' => array( [maximum depth reached] ), 'children' => array([maximum depth reached]) ), (int) 2 => array( 'Postcategory' => array( [maximum depth reached] ), 'ParentPostcategory' => array( [maximum depth reached] ), 'ChildPostcategory' => array( [maximum depth reached] ), 'Post' => array( [maximum depth reached] ), 'children' => array( [maximum depth reached] ) ), (int) 3 => array( 'Postcategory' => array( [maximum depth reached] ), 'ParentPostcategory' => array( [maximum depth reached] ), 'ChildPostcategory' => array([maximum depth reached]), 'Post' => array( [maximum depth reached] ), 'children' => array([maximum depth reached]) ) ), 'posts' => array( (int) 0 => array( 'Post' => array( [maximum depth reached] ), 'User' => array( [maximum depth reached] ), 'Postcoverimage' => array( [maximum depth reached] ), 'Rating' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), 'RatingSummary' => array( [maximum depth reached] ) ), (int) 1 => array( 'Post' => array( [maximum depth reached] ), 'User' => array( [maximum depth reached] ), 'Postcoverimage' => array( [maximum depth reached] ), 'Rating' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), 'RatingSummary' => array( [maximum depth reached] ) ), (int) 2 => array( 'Post' => array( [maximum depth reached] ), 'User' => array( [maximum depth reached] ), 'Postcoverimage' => array( [maximum depth reached] ), 'Rating' => array([maximum depth reached]), 'Tag' => array( [maximum depth reached] ) ), (int) 3 => array( 'Post' => array( [maximum depth reached] ), 'User' => array( [maximum depth reached] ), 'Postcoverimage' => array( [maximum depth reached] ), 'Rating' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), 'RatingSummary' => array( [maximum depth reached] ) ), (int) 4 => array( 'Post' => array( [maximum depth reached] ), 'User' => array( [maximum depth reached] ), 'Postcoverimage' => array( [maximum depth reached] ), 'Rating' => array( [maximum depth reached] ), 'Tag' => array( [maximum depth reached] ), 'RatingSummary' => array( [maximum depth reached] ) ) ), 'masterclass' => '', 'appposts' => array( (int) 0 => array( 'Post' => array( [maximum depth reached] ), 'Postcoverimage' => array( [maximum depth reached] ), 'Tofriend' => array([maximum depth reached]) ), (int) 1 => array( 'Post' => array( [maximum depth reached] ), 'Postcoverimage' => array( [maximum depth reached] ), 'Tofriend' => array( [maximum depth reached] ) ), (int) 2 => array( 'Post' => array( [maximum depth reached] ), 'Postcoverimage' => array( [maximum depth reached] ), 'Tofriend' => array( [maximum depth reached] ) ), (int) 3 => array( 'Post' => array( [maximum depth reached] ), 'Postcoverimage' => array( [maximum depth reached] ), 'Tofriend' => array([maximum depth reached]) ), (int) 4 => array( 'Post' => array( [maximum depth reached] ), 'Postcoverimage' => array( [maximum depth reached] ), 'Tofriend' => array([maximum depth reached]) ) ), 'regions' => array(), 'appcountries' => array( (int) 1 => 'Andorra', (int) 2 => 'United Arab Emirates', (int) 3 => 'Afghanistan', (int) 4 => 'Antigua and Barbuda', (int) 5 => 'Anguilla', (int) 6 => 'Albania', (int) 7 => 'Armenia', (int) 8 => 'Netherlands Antilles', (int) 9 => 'Angola', (int) 12 => 'Argentina', (int) 13 => 'American Samoa', (int) 14 => 'Austria', (int) 15 => 'Australia', (int) 16 => 'Aruba', (int) 17 => 'Azerbaijan', (int) 18 => 'Bosnia and Herzegovina', (int) 19 => 'Barbados', (int) 20 => 'Bangladesh', (int) 21 => 'Belgium', (int) 22 => 'Burkina Faso', (int) 23 => 'Bulgaria', (int) 24 => 'Bahrain', (int) 25 => 'Burundi', (int) 26 => 'Benin', (int) 27 => 'Bermuda', (int) 28 => 'Brunei Darussalam', (int) 29 => 'Bolivia', (int) 30 => 'Brazil', (int) 31 => 'Bahamas', (int) 32 => 'Bhutan', (int) 34 => 'Botswana', (int) 35 => 'Belarus', (int) 36 => 'Belize', (int) 37 => 'Canada', (int) 38 => 'Cocos (Keeling) Islands', (int) 40 => 'Central African Republic', (int) 41 => 'Congo', (int) 42 => 'Switzerland', (int) 43 => 'Cote D'Ivoire', (int) 44 => 'Cook Islands', (int) 45 => 'Chile', (int) 46 => 'Cameroon', (int) 47 => 'China', (int) 48 => 'Colombia', (int) 49 => 'Costa Rica', (int) 51 => 'Cuba', (int) 52 => 'Cape Verde', (int) 53 => 'Christmas Island', (int) 54 => 'Cyprus', (int) 55 => 'Czech Republic', (int) 56 => 'Germany', (int) 57 => 'Djibouti', (int) 58 => 'Denmark', (int) 59 => 'Dominica', (int) 60 => 'Dominican Republic', (int) 61 => 'Algeria', (int) 62 => 'Ecuador', (int) 63 => 'Estonia', (int) 64 => 'Egypt', (int) 65 => 'Western Sahara', (int) 66 => 'Eritrea', (int) 67 => 'Spain', (int) 68 => 'Ethiopia', (int) 70 => 'Finland', (int) 71 => 'Fiji', (int) 72 => 'Falkland Islands (Malvinas)', (int) 73 => 'Micronesia, Federated States of', (int) 74 => 'Faroe Islands', (int) 75 => 'France', (int) 77 => 'Gabon', (int) 78 => 'United Kingdom', (int) 79 => 'Grenada', (int) 80 => 'Georgia', (int) 81 => 'French Guiana', (int) 82 => 'Ghana', (int) 83 => 'Gibraltar', (int) 84 => 'Greenland', (int) 85 => 'Gambia', (int) 86 => 'Guinea', (int) 87 => 'Guadeloupe', (int) 88 => 'Equatorial Guinea', (int) 89 => 'Greece', (int) 90 => 'South Georgia and Sandwich Island', (int) 91 => 'Guatemala', (int) 93 => 'Guinea-Bissau', (int) 94 => 'Guyana', (int) 95 => 'Hong Kong', (int) 97 => 'Honduras', (int) 98 => 'Croatia', (int) 99 => 'Haiti', (int) 100 => 'Hungary', (int) 101 => 'Indonesia', (int) 102 => 'Ireland', (int) 103 => 'Israel', (int) 104 => 'India', (int) 106 => 'Iraq', (int) 107 => 'Iran, Islamic Republic of', (int) 108 => 'Iceland', (int) 109 => 'Italy', (int) 110 => 'Jamaica', (int) 111 => 'Jordan', (int) 112 => 'Japan', (int) 113 => 'Kenya', (int) 114 => 'Kyrgyzstan', (int) 115 => 'Cambodia', (int) 116 => 'Kiribati', (int) 117 => 'Comoros', (int) 118 => 'Saint Kitts and Nevis', (int) 119 => 'Korea, Democratic', (int) 120 => 'Korea, Republic of', (int) 121 => 'Kuwait', (int) 122 => 'Cayman Islands', (int) 123 => 'Kazakhstan', (int) 124 => 'Laos', (int) 125 => 'Lebanon', (int) 126 => 'Saint Lucia', (int) 127 => 'Liechtenstein', (int) 128 => 'Sri Lanka', (int) 129 => 'Liberia', (int) 130 => 'Lesotho', (int) 131 => 'Lithuania', (int) 132 => 'Luxembourg', (int) 133 => 'Latvia', (int) 134 => 'Libya', (int) 135 => 'Morocco', (int) 136 => 'Monaco', (int) 137 => 'Moldova', (int) 138 => 'Madagascar', (int) 139 => 'Marshall Islands', (int) 140 => 'Macedonia', (int) 141 => 'Mali', (int) 142 => 'Myanmar', (int) 143 => 'Mongolia', (int) 144 => 'Macau', (int) 145 => 'Northern Mariana Islands', (int) 146 => 'Martinique', (int) 147 => 'Mauritania', (int) 148 => 'Montserrat', (int) 149 => 'Malta', (int) 150 => 'Mauritius', (int) 151 => 'Maldives', (int) 152 => 'Malawi', (int) 153 => 'Mexico', (int) 154 => 'Malaysia', (int) 155 => 'Mozambique', (int) 156 => 'Namibia', (int) 157 => 'New Caledonia', (int) 158 => 'Niger', (int) 159 => 'Norfolk Island', (int) 160 => 'Nigeria', (int) 161 => 'Nicaragua', (int) 162 => 'Netherlands', (int) 163 => 'Norway', (int) 164 => 'Nepal', (int) 165 => 'Nauru', (int) 166 => 'Niue', (int) 167 => 'New Zealand', (int) 168 => 'Oman', (int) 169 => 'Panama', (int) 170 => 'Peru', (int) 171 => 'French Polynesia', (int) 172 => 'Papua New Guinea', (int) 173 => 'Philippines', (int) 174 => 'Pakistan', (int) 175 => 'Poland', (int) 176 => 'Saint Pierre and Miquelon', (int) 177 => 'Pitcairn', (int) 180 => 'Portugal', (int) 181 => 'Palau', (int) 182 => 'Paraguay', (int) 183 => 'Qatar', (int) 184 => 'Reunion', (int) 185 => 'Romania', (int) 186 => 'Russian Federation', (int) 187 => 'Rwanda', (int) 188 => 'Saudi Arabia', (int) 189 => 'Solomon Islands', (int) 190 => 'Seychelles', (int) 191 => 'Sudan', (int) 192 => 'Sweden', (int) 193 => 'Singapore', (int) 194 => 'Saint Helena', (int) 195 => 'Slovenia', (int) 196 => 'Svalbard and Jan Mayen', (int) 197 => 'Slovakia', (int) 198 => 'Sierra Leone', (int) 199 => 'San Marino', (int) 200 => 'Senegal', (int) 201 => 'Somalia', (int) 202 => 'Suriname', (int) 203 => 'Sao Tome and Principe', (int) 204 => 'El Salvador', (int) 205 => 'Syrian Arab Republic', (int) 206 => 'Swaziland', (int) 207 => 'Turks and Caicos Islands', (int) 208 => 'Chad', (int) 209 => 'French Southern Territories', (int) 210 => 'Togo', (int) 211 => 'Thailand', (int) 212 => 'Tajikistan', (int) 213 => 'Tokelau', (int) 215 => 'Turkmenistan', (int) 216 => 'Tunisia', (int) 217 => 'Tonga', (int) 218 => 'Turkey', (int) 219 => 'Trinidad and Tobago', (int) 220 => 'Tuvalu', (int) 221 => 'Taiwan', (int) 222 => 'Tanzania, United Republic', (int) 223 => 'Ukraine', (int) 224 => 'Uganda', (int) 226 => 'United States', (int) 227 => 'Uruguay', (int) 228 => 'Uzbekistan', (int) 230 => 'Saint Vincent and the Grenadines', (int) 231 => 'Venezuela', (int) 232 => 'Virgin Islands, British', (int) 233 => 'Virgin Islands, U.S.', (int) 234 => 'Vietnam', (int) 235 => 'Vanuatu', (int) 236 => 'Wallis and Futuna', (int) 237 => 'Samoa', (int) 238 => 'Yemen', (int) 239 => 'Mayotte', (int) 240 => 'South Africa', (int) 241 => 'Zambia', (int) 242 => 'Zaire', (int) 243 => 'Zimbabwe' ), 'data' => array( 'Post' => array( 'id' => '5', 'postcategory_id' => '7', 'user_id' => '1', 'title' => 'Social website login for your site is Open source standards for authorization', 'body' => '<p>You might have seen many of sites now showing links or buttons of Facebook, Twitter, Google + or other social network sites on their sign up and sign in page. This is to make users life bit easier for the login or sign up process on various websites. What happens when you click on any of that link? Have you tried anytime?</p> <p>Let’s see how you as a developer can develop this feature for your website. For this we consider a use case.</p> <p><em>User came to the sign in page of your site and he looked at the login with “facebook” or “twitter” or “google” (or any of the site) link. He has a separate account of any of these listed social network sites which you have integrated in your website. He clicks on any of the link and now he is redirected to the respective site for authentication. He provides correct credential for that social network site. He is now authenticated by that social network site and if it is for the first time he is using this authentication system, he has to agree to share his profile data with the other site from where he is coming for the authentication.</em></p> <p>When user agrees to share his profile data on successful login, that social network site redirect him to your site with user’s profile information. Of course password would not be sent to your site. This authenticating social network site will generate one token for this session and send along with the user’s profile data. This token is unique to user and your site. Now all communication and data exchange between your site and the authenticating social network site happens with this token generated by the authenticated site. Give essential profile data to your website login system and create a successful login session at your website and treat him as a logged in user.</p> <p> You can store this user information into your database and send an email to him with the new login credentials to login in your site directly in future. If he doesn’t want to login from your site directly, he still has an option to login again from the social network site which he chooses. Check every time while login weather he is the stored user with his unique field value like email address or username and if not found in your database store it and or otherwise directly give an authentication to the logged in section of your site.</p> <p>All of these redirections and authentications are made through APIs provided by these authenticating sites. Most of these sites do provide a sign in APIs but do not have the APIs for sign off from the authenticated site (There are few exceptions in this). Once user is logged in to your website through open authentication system via a different web site, he has to actually login into that website. Now when he clicks on the logout link of your site, he logs out from your site not from the site from where he was authenticated. This is risk if any user is accessing your site from the public computer and forgets to log off from the authenticated site. His account would be compromised.</p> <p>You as a developer of your site must provide information about the risk factors to your users before they use separate authentication system for your site. Developers need to create an account on these sites and get secret API key to use their APIs and use this secret key into data transactions with the site.</p> <p>Here are few providers of open authentication services are also called resource owners to authorize other web service or web site to their resources without sharing their users’ credentials.</p> <p>Amazon, Dropbox, Facebook, Flickr, GitHub, Instagram, LinkedIn, Twitter, Tumblrand …..And many of others.</p> ', 'comment_count' => '0', 'postview_count' => '2059', 'active' => '1', 'created' => '2015-06-15 08:15:29', 'modified' => '2019-11-21 06:01:51', 'tags' => 'Open Authentication, Social Network Login, oAuth' ), 'User' => array( 'id' => '1', 'firstname' => 'Chirayu' ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/social-website-login-for-65938-small.jpg', 'namemedium' => '/files/uploads/postimages/social-website-login-for-65938-medium.jpg' ), 'Rating' => array( (int) 0 => array( [maximum depth reached] ) ), 'Tag' => array( (int) 0 => array( [maximum depth reached] ), (int) 1 => array( [maximum depth reached] ), (int) 2 => array( [maximum depth reached] ) ), 'RatingSummary' => array( 'total_votes' => (int) 1, 'total_rating' => (float) 5 ) ), 'model' => null, 'modelClass' => null, 'submit_url' => '/feedback/ratings/add', 'element_id' => 'rating-789843234', 'message_id' => 'message-789843234', 'values_id' => 'values-789843234', 'readonly' => 'false', 'value' => (float) 5, 'votes' => (float) 1, 'user_vote' => (int) 0 ) $tags = array( (int) 0 => array( 'Tagged' => array( 'tag_id' => '1' ), 'Tag' => array( 'id' => '1', 'identifier' => null, 'name' => 'Configuration', 'keyname' => 'configuration', 'weight' => (float) 12, 'occurrence' => '2' ), (int) 0 => array( 'occurrence' => '2' ) ), (int) 1 => array( 'Tagged' => array( 'tag_id' => '2' ), 'Tag' => array( 'id' => '2', 'identifier' => null, 'name' => 'PHP5', 'keyname' => 'php5', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 2 => array( 'Tagged' => array( 'tag_id' => '3' ), 'Tag' => array( 'id' => '3', 'identifier' => null, 'name' => 'Apache2', 'keyname' => 'apache2', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 3 => array( 'Tagged' => array( 'tag_id' => '4' ), 'Tag' => array( 'id' => '4', 'identifier' => null, 'name' => 'PHP', 'keyname' => 'php', 'weight' => (float) 20, 'occurrence' => '6' ), (int) 0 => array( 'occurrence' => '6' ) ), (int) 4 => array( 'Tagged' => array( 'tag_id' => '5' ), 'Tag' => array( 'id' => '5', 'identifier' => null, 'name' => 'Sourcecode', 'keyname' => 'sourcecode', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 5 => array( 'Tagged' => array( 'tag_id' => '6' ), 'Tag' => array( 'id' => '6', 'identifier' => null, 'name' => 'Warnings', 'keyname' => 'warnings', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 6 => array( 'Tagged' => array( 'tag_id' => '7' ), 'Tag' => array( 'id' => '7', 'identifier' => null, 'name' => 'Timezone', 'keyname' => 'timezone', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 7 => array( 'Tagged' => array( 'tag_id' => '8' ), 'Tag' => array( 'id' => '8', 'identifier' => null, 'name' => 'Linux', 'keyname' => 'linux', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 8 => array( 'Tagged' => array( 'tag_id' => '9' ), 'Tag' => array( 'id' => '9', 'identifier' => null, 'name' => 'Apache', 'keyname' => 'apache', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 9 => array( 'Tagged' => array( 'tag_id' => '10' ), 'Tag' => array( 'id' => '10', 'identifier' => null, 'name' => 'Installation', 'keyname' => 'installation', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 10 => array( 'Tagged' => array( 'tag_id' => '11' ), 'Tag' => array( 'id' => '11', 'identifier' => null, 'name' => 'Open Authentication', 'keyname' => 'openauthentication', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 11 => array( 'Tagged' => array( 'tag_id' => '12' ), 'Tag' => array( 'id' => '12', 'identifier' => null, 'name' => 'Social Network Login', 'keyname' => 'socialnetworklogin', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 12 => array( 'Tagged' => array( 'tag_id' => '13' ), 'Tag' => array( 'id' => '13', 'identifier' => null, 'name' => 'oAuth', 'keyname' => 'oauth', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 13 => array( 'Tagged' => array( 'tag_id' => '14' ), 'Tag' => array( 'id' => '14', 'identifier' => null, 'name' => 'Web Developement', 'keyname' => 'webdevelopement', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 14 => array( 'Tagged' => array( 'tag_id' => '15' ), 'Tag' => array( 'id' => '15', 'identifier' => null, 'name' => 'Security', 'keyname' => 'security', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 15 => array( 'Tagged' => array( 'tag_id' => '16' ), 'Tag' => array( 'id' => '16', 'identifier' => null, 'name' => 'Code', 'keyname' => 'code', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 16 => array( 'Tagged' => array( 'tag_id' => '17' ), 'Tag' => array( 'id' => '17', 'identifier' => null, 'name' => 'Tips', 'keyname' => 'tips', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 17 => array( 'Tagged' => array( 'tag_id' => '18' ), 'Tag' => array( 'id' => '18', 'identifier' => null, 'name' => 'CSV files', 'keyname' => 'csvfiles', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 18 => array( 'Tagged' => array( 'tag_id' => '19' ), 'Tag' => array( 'id' => '19', 'identifier' => null, 'name' => 'File content', 'keyname' => 'filecontent', 'weight' => (float) 10, 'occurrence' => '1' ), (int) 0 => array( 'occurrence' => '1' ) ), (int) 19 => array( 'Tagged' => array( 'tag_id' => '20' ), 'Tag' => array( 'id' => '20', 'identifier' => null, 'name' => 'Software Design', 'keyname' => 'softwaredesign', 'weight' => (float) 12, 'occurrence' => '2' ), (int) 0 => array( 'occurrence' => '2' ) ) ) $postcategories = array( (int) 0 => array( 'Postcategory' => array( 'id' => '5', 'parent_id' => null, 'name' => 'PHP Configuration', 'active' => '1', 'lft' => '1', 'rght' => '2', 'created' => '2015-05-06 13:24:33', 'modified' => '2015-05-06 13:24:33' ), 'ParentPostcategory' => array( 'id' => null, 'parent_id' => null, 'name' => null, 'active' => null, 'lft' => null, 'rght' => null, 'created' => null, 'modified' => null ), 'ChildPostcategory' => array(), 'Post' => array( (int) 0 => array( [maximum depth reached] ), (int) 1 => array( [maximum depth reached] ), (int) 2 => array( [maximum depth reached] ) ), 'children' => array() ), (int) 1 => array( 'Postcategory' => array( 'id' => '6', 'parent_id' => null, 'name' => 'PHP installation', 'active' => '1', 'lft' => '3', 'rght' => '4', 'created' => '2015-05-06 13:36:53', 'modified' => '2015-05-06 13:36:53' ), 'ParentPostcategory' => array( 'id' => null, 'parent_id' => null, 'name' => null, 'active' => null, 'lft' => null, 'rght' => null, 'created' => null, 'modified' => null ), 'ChildPostcategory' => array(), 'Post' => array( (int) 0 => array( [maximum depth reached] ) ), 'children' => array() ), (int) 2 => array( 'Postcategory' => array( 'id' => '7', 'parent_id' => null, 'name' => 'Web development', 'active' => '1', 'lft' => '5', 'rght' => '8', 'created' => '2015-06-06 05:44:15', 'modified' => '2015-06-06 05:44:15' ), 'ParentPostcategory' => array( 'id' => null, 'parent_id' => null, 'name' => null, 'active' => null, 'lft' => null, 'rght' => null, 'created' => null, 'modified' => null ), 'ChildPostcategory' => array( (int) 0 => array( [maximum depth reached] ) ), 'Post' => array( (int) 0 => array( [maximum depth reached] ), (int) 1 => array( [maximum depth reached] ), (int) 2 => array( [maximum depth reached] ) ), 'children' => array( (int) 0 => array( [maximum depth reached] ) ) ), (int) 3 => array( 'Postcategory' => array( 'id' => '9', 'parent_id' => null, 'name' => 'Software Design', 'active' => '1', 'lft' => '9', 'rght' => '10', 'created' => '2017-07-12 16:27:21', 'modified' => '2017-07-12 16:27:21' ), 'ParentPostcategory' => array( 'id' => null, 'parent_id' => null, 'name' => null, 'active' => null, 'lft' => null, 'rght' => null, 'created' => null, 'modified' => null ), 'ChildPostcategory' => array(), 'Post' => array( (int) 0 => array( [maximum depth reached] ), (int) 1 => array( [maximum depth reached] ) ), 'children' => array() ) ) $posts = array( (int) 0 => array( 'Post' => array( 'id' => '11', 'postcategory_id' => '8', 'user_id' => '1', 'title' => 'Connecting remote server using SSH', 'body' => '<p>SSH stands for secured shall - a secured network service over an unsecured network. It is a network protocol. It provides an encrypted data communication between two computers. SSH can be used interactively to enable terminal sessions. SSH is also used in scripts to remotely and securely access data and other resources. In order to connect to remote server with SSH, you need:</p> <p>1) Server IP or domain name</p> <p>2) Username</p> <p>3) Password</p> <p>4) SSH client - I recommend PuTTY (you can easily download from internet) for windows operating system while Linux and MAC users can use OpenSSH which is mostly installed in their OS.</p> <p><strong>Useful SSH commands frequently used by developers:</strong></p> <p><em>>_ ssh <remote_host></em></p> <p><remote_host> is an IP address or domain name that you are trying to connect to. This command assumes that your username on the remote system is the same as your username on your local system.</p> <p> <em>>_ ssh remote_username@<remote_host></em></p> <p>If your username is different on the remote system. You can specify by using this syntax.</p> <p>Once you are connected to the server, you will be asked to provide a password. SSH works by connecting a client program to an SSH server. In above commands, SSH is the client program. The SSH server is at the <em>remote_host</em> that is specified.</p> <p><strong>How to configure SSH</strong></p> <p>When you change the configuration of SSH, you are changing the settings of the sshd server. In Ubuntu, the main sshd configuration file is located at <em>/etc/ssh/sshd_config</em>.</p> <p>While it is helpful to be able to log in to a remote system using passwords, it is much better idea to set up Key-based authentication.</p> <p>Key based authentication works by creating a pair of keys: <strong>a private key</strong> and <strong>a public key.</strong></p> <p>The private key is located on the client machine. The public key is placed on any server you wish to access. Please check how to generate public and private keys with PuTTY for windows and with ssh-keygen for linux and mac OS. The folder in which the private key is placed default in the windows is c:\users\<username>\.ssh while in unix based system it is under /home/<username>/.ssh</p> <p>The public key is added to a special file within the user account you will be logging into called ~/.ssh/authorized_keys</p> <p>When you attempt to connect using a key pair, the server will use the public key to create a message for the client computer that can only be read with private key.</p> <p>The client computer then sends the appropriate response back to the server and the server will know that the client is legitimate. This entire process is done in the background after keys are correctly setup.</p> <p>SSH operates on TCP port 22 by default. The server listens on port 22 though this can be changed through custom port number in <em>sshd_config</em> file.</p> <p><em>>_ ssh -p</em> <em>7322 remote_username@<remote_host></em></p> <p>If you are not connecting <em>remote host</em> at the default port 22, then you need to specify the custom port number in the command. The above command shows remote host is being connected at the port number 7322.</p> ', 'comment_count' => '0', 'postview_count' => '1161', 'active' => '1', 'created' => '2019-11-29 13:06:49', 'modified' => '2019-11-29 13:06:49', 'tags' => 'SSH, Network, Secure' ), 'User' => array( 'id' => '1', 'firstname' => 'Chirayu' ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/ssh-connect-16148-small.jpg', 'namemedium' => '/files/uploads/postimages/ssh-connect-16148-medium.jpg' ), 'Rating' => array( (int) 0 => array( [maximum depth reached] ) ), 'Tag' => array( (int) 0 => array( [maximum depth reached] ), (int) 1 => array( [maximum depth reached] ), (int) 2 => array( [maximum depth reached] ) ), 'RatingSummary' => array( 'total_votes' => (int) 1, 'total_rating' => (float) 3.5 ) ), (int) 1 => array( 'Post' => array( 'id' => '8', 'postcategory_id' => '7', 'user_id' => '0', 'title' => 'CSV files data into php array to store in MySql', 'body' => '<p><strong><em>What are CSV files?</em></strong></p> <p>A CSV (Comma Separated Values) files are text files, allows data to be saved in a structured format. CSV files can be used with Microsoft Excel, Google Spreadsheets or Open Office Calc kind of tools. These CSV files are saved with .csv extension. In CSV files data fields are usually separated by comma as delimiter, but can also use a tab or pipe symbol instead of comma. CSV files are used to import and export data from application to application. Mostly, the first record is a header containing a list of field names. Any programming language has technique to import and export data from and to database like MS-SQL, MySql, PostGres, etc..</p> <p>PHP is one of the best programming languages for import and export of the data with the database to and from flat files like CSV files.</p> <p><strong><em>Fetching the data from the CSV file</em></strong></p> <p>Open the file in the read mode and store the content into variable. We assume that the CSV file contains the information about the contacts having fields firstname, lastname, email, and phone exported and the file name is contacts.csv.</p> <p>$csvfilehandle = fopen("contacts.csv","r");</p> <p>Here $csvfilehandle is file pointer to a file "contacts.csv" successfully opened</p> <p>while (($line = fgetcsv($csvfilehandle,1000,',','"'))!==false){</p> <p> $data[] = $line;</p> <p>}</p> <p>Close the opened file handle with </p> <p>fclose($csvfilehandle);</p> <p>The first argument $csvfilehandle is the mandatory arguments and remaining are optional.</p> <p>1000 is a length of characters per line to be set. This should be greater than the longest line in the file. If you are not sure about the length then don`t specify it.</p> <p>',' comma is a delimiter you can set or according to the data in the file the delimiter is used.</p> <p>'"' is the enclosure in the file used for the field value</p> <p>Now you have all the data of the CSV file into the array $data. If you print this with print_r($data); you get values into array.</p> <p><strong><em>Importing data into MySQL table</em></strong></p> <p>Now to import the data into the MySQL table named contacts, we need to modify the above wile loop. Let`s do that now.</p> <p>while (($line = fgetcsv($csvfilehandle,1000,',','"'))!==false){ </p> <p> mysql_query("insert into contacts(</p> <p> firstname, lastname, email, telephone</p> <p> )VALUES(</p> <p> '".mysql_real_escape_string($line[0])."',</p> <p> '".mysql_real_escape_string($line[1])."',</p> <p> '".mysql_real_escape_string($line[2])."',</p> <p> '".mysql_real_escape_string($line[3])."'</p> <p> )")</p> <p>or die(mysql_error());</p> <p>}</p> <p>fclose($csvfilehandle);</p> <p>Write me back if you are working for such functionality and not getting through the code.</p> ', 'comment_count' => '1', 'postview_count' => '1540', 'active' => '1', 'created' => '2016-11-03 07:17:48', 'modified' => '2019-11-21 06:00:03', 'tags' => 'PHP, CSV files, File content' ), 'User' => array( 'id' => null, 'firstname' => null ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/csv-files-data-into-88773-small.png', 'namemedium' => '/files/uploads/postimages/csv-files-data-into-88773-medium.png' ), 'Rating' => array( (int) 0 => array( [maximum depth reached] ) ), 'Tag' => array( (int) 0 => array( [maximum depth reached] ), (int) 1 => array( [maximum depth reached] ), (int) 2 => array( [maximum depth reached] ) ), 'RatingSummary' => array( 'total_votes' => (int) 1, 'total_rating' => (float) 2.5 ) ), (int) 2 => array( 'Post' => array( 'id' => '7', 'postcategory_id' => '7', 'user_id' => '0', 'title' => 'How the PHP script may report what is the total size of any web page browsed', 'body' => '<p>These days excellent work is being done to attract web site users by creating attractive and well managed web pages. While browsing any internet site or a web page as developer or designer of the web pages we might came across the thought, “how much size of this web page is? or how much costly to render this on my browser?”. Well today lets build a script which reports information of above questions. As usual we will be using PHP for scripting the code. This script includes two things in consideration. <strong>First,</strong> how many http/https requests are being used to render the page and <strong>Second,</strong> what is the total size of the rendered web page. We will create a script in a manner that it can be used from command line interface as well as from the browser. For this the cURL module is used. If it is not installed in your PHP set up then go to my previous article of installation and configuration of PHP.</p> <p>Ok. So now what is the meaning of <strong>First</strong> part, “how many http/https requests are”. When any web page is rendered or loaded in your browser, it is a combination of one or multiple CSS files, one or multiple javascripts or .js files, code of Html, multiple images, etc… we call them web page resources as all together they make a web page. While web page is loaded all these multiple files are being called from one or different locations with specific web address. These files are called one by one as it cannot called all once at a time. The separate calls for each of these files are known as http/https requests.</p> <p>Now let’s come to the Second part of the task – “what is the total size of the rendered web page” and that consist of file size of each of these resource we saw above. When http/https requests are responded uninterrupted then that response contains response header (developers and designers knows that). One of the headers is called “Content-Length” and that gives the size of that particular resource. We need to use built in API of PHP ie. get_headers and the argument would be the URL where the http/https request is sent. Bellow is the hint and good start of the code in PHP.</p> <p><strong><em>function file_size_rendered($url) { </em></strong></p> <p><strong><em>//where $url in the argument is the location where request is being sent.</em></strong></p> <p><strong><em> $headers = get_headers($url, 1);</em></strong> </p> <p><strong><em> if (isset($headers['Content-Length'])) </em></strong></p> <p><strong><em> return $headers['Content-Length'];</em></strong> </p> <p><strong><em>//Also check whether lower case of "L" is used in Content-length</em></strong></p> <p><strong><em> if (isset($headers['Content-length'])) </em></strong></p> <p><strong><em> return $headers['Content-length'];</em></strong></p> <p><strong><em>//if the content header is not found then use the curl request</em></strong></p> <p><strong><em> $c = curl_init();</em></strong></p> <p><strong><em> curl_setopt_array($c, array(</em></strong></p> <p><strong><em> CURLOPT_URL => $url,</em></strong></p> <p><strong><em> CURLOPT_RETURNTRANSFER => true,</em></strong></p> <p><strong><em> CURLOPT_HTTPHEADER => array('User-Agent: Mozilla/5.0 </em></strong></p> <p><strong><em> (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.3) </em></strong></p> <p><strong><em> Gecko/20090824 Firefox/3.5.3'),</em></strong></p> <p><strong><em> ));</em></strong></p> <p><strong><em> curl_exec($c);</em></strong> </p> <p><strong><em> $size = curl_getinfo($c, CURLINFO_SIZE_DOWNLOAD);</em></strong> </p> <p><strong><em> return $size;</em></strong> </p> <p><strong><em> curl_close($c);</em></strong></p> <p><strong><em>}</em></strong></p> <p>This article is just a good start to inspire for deeper understanding or the technique of coding. One can browse more or post questions to get answer on more specific tasks.</p> ', 'comment_count' => '0', 'postview_count' => '1768', 'active' => '1', 'created' => '2015-12-28 10:52:20', 'modified' => '2019-11-21 06:00:37', 'tags' => 'PHP, Code, Tips' ), 'User' => array( 'id' => null, 'firstname' => null ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/how-the-php-script-may-62903-small.jpg', 'namemedium' => '/files/uploads/postimages/how-the-php-script-may-62903-medium.jpg' ), 'Rating' => array(), 'Tag' => array( (int) 0 => array( [maximum depth reached] ), (int) 1 => array( [maximum depth reached] ), (int) 2 => array( [maximum depth reached] ) ) ), (int) 3 => array( 'Post' => array( 'id' => '6', 'postcategory_id' => '8', 'user_id' => '1', 'title' => 'Developing secured web application with PHP', 'body' => '<p>Your PHP web application is deployed on the secured platform is great but it is not just enough to consider your application is secured. It is equally or more important that your source code is also developed in the same intensity of security and passed through security testing. I would like to propose certain check list to consider before you go live with your site. PHP is considered one of the easiest languages for developing web applications and this gives chance to startup developers to leave common PHP security pitfalls in development.</p> <p>Listed out bellow are few points which can be used as a check list before you publish your web application.</p> <ul> <li><strong><em>Character encoding:</em></strong> The thumb rule is always create a valid output and use UTF-8 for the encoding like in Html, Database, Html, JS, URLs, Emails and wherever it is possible.</li> <li><strong><em>User Input Data Validation:</em></strong> Validate the user input data according to which purpose it is collected from them. It is always a good idea to validate the user input data at the PHP logic even if your JavaScript validate it at the browser itself. Type-casting is also helpful in most of the cases.</li> <li><strong><em>CSRF or XSRF – Cross Site Request Forgeries: </em></strong>a request from the different site which misuses users authenticated stat data to hack or perform unwanted operations. While user is logged in, his session data is shared across all tabs in the same browser. Code the PHP script that way it uses minimum time of GET requests or probably only to access the information rather than transactions. Avoid using $_REQUEST as much possible instead use $_GET or $_POST accordingly wherever you retrieve variables.</li> </ul> <p>Another way is to generate a random value known as token while user successfully log in at the application. Store this token value in the session and check in application logic whenever user requests or post any information.</p> <ul> <li><strong><em>XSS – Cross site scripting: </em></strong>always validate HTML inputs from user’s submitted data in case like accepting comments on the posts, or collecting reviews and display them on the site. It may use to steal session an cookie data and run kind of JS script on the browser. Use strip_tags() and /or htmlspecialchars() functions which encode and prevent users data to create an HTML tags.</li> <li><strong><em>Non-disclose of file system</em></strong>: If your website allows to download any file to its users, always use some functions which takes file path as an internal system input and use respective header() arguments to download the file. Do not create a like for the file which displays whole folder structure in the link itself to download the file.</li> <li><strong><em>Restrict the file uploads</em></strong>: a user could upload a .php extension file or any other executable file through your file upload feature on site. Check the MIME type of the uploaded file with the function like finfo_file() or any similar to validate the type of file. Create an array of allowable file extensions and keep checking with the uploaded file extension is present in the allowable array or not.</li> <li><strong><em>SQL injection</em></strong>: any input which is concatenated into a string as an SQL query is called the SQL injection. Characters like semicolon, single quote, double quote, hyphens, etc which are used in the SQL queries or statements, should be escaped. This compromise the database and it allowed to be accessed by unauthorized way. Developer can use the pair of prepare () and execute () statement to execute the query rather than simply write a row query to fire on database. Most of the new generation frameworks for PHP take care of this.</li> <li>Other security measures includes <ul style="list-style-type:circle"> <li>Use a proper error handling.</li> <li>Always use .php extensions to included files.</li> <li>Filter values of “From” header before you create that in the Email function.</li> <li>Use strong password hashing algorithm while storing the passwords.</li> <li>Encrypt the session data before you store.</li> <li>Strong cipher code to encrypt data is also a good measure.</li> </ul> </li> </ul> <p style="margin-left:.25in">Web application security measures are taken at the time of designing its architecture. Also it should not happen that steps taken from the security point of view decreases the scope of usability. Security must be implemented keeping in the mind of your website users and must be included in the development budget.</p> <p style="margin-left:.25in">This is a short tutorial for PHP developers and has just stretched the surface of the development techniques. It is up to the developer who understands the depth of vulnerabilities and possible attacks on applications over the web. Developers are required to drill more on each points which are listed and /or which are left from discussion here.</p> ', 'comment_count' => '0', 'postview_count' => '1740', 'active' => '1', 'created' => '2015-07-17 13:54:47', 'modified' => '2019-11-21 06:01:23', 'tags' => 'PHP, Web Developement, Security' ), 'User' => array( 'id' => '1', 'firstname' => 'Chirayu' ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/developing-secured-web-application-65142-small.jpg', 'namemedium' => '/files/uploads/postimages/developing-secured-web-application-65142-medium.jpg' ), 'Rating' => array( (int) 0 => array( [maximum depth reached] ), (int) 1 => array( [maximum depth reached] ) ), 'Tag' => array( (int) 0 => array( [maximum depth reached] ), (int) 1 => array( [maximum depth reached] ), (int) 2 => array( [maximum depth reached] ) ), 'RatingSummary' => array( 'total_votes' => (int) 2, 'total_rating' => (float) 4 ) ), (int) 4 => array( 'Post' => array( 'id' => '5', 'postcategory_id' => '7', 'user_id' => '1', 'title' => 'Social website login for your site is Open source standards for authorization', 'body' => '<p>You might have seen many of sites now showing links or buttons of Facebook, Twitter, Google + or other social network sites on their sign up and sign in page. This is to make users life bit easier for the login or sign up process on various websites. What happens when you click on any of that link? Have you tried anytime?</p> <p>Let’s see how you as a developer can develop this feature for your website. For this we consider a use case.</p> <p><em>User came to the sign in page of your site and he looked at the login with “facebook” or “twitter” or “google” (or any of the site) link. He has a separate account of any of these listed social network sites which you have integrated in your website. He clicks on any of the link and now he is redirected to the respective site for authentication. He provides correct credential for that social network site. He is now authenticated by that social network site and if it is for the first time he is using this authentication system, he has to agree to share his profile data with the other site from where he is coming for the authentication.</em></p> <p>When user agrees to share his profile data on successful login, that social network site redirect him to your site with user’s profile information. Of course password would not be sent to your site. This authenticating social network site will generate one token for this session and send along with the user’s profile data. This token is unique to user and your site. Now all communication and data exchange between your site and the authenticating social network site happens with this token generated by the authenticated site. Give essential profile data to your website login system and create a successful login session at your website and treat him as a logged in user.</p> <p> You can store this user information into your database and send an email to him with the new login credentials to login in your site directly in future. If he doesn’t want to login from your site directly, he still has an option to login again from the social network site which he chooses. Check every time while login weather he is the stored user with his unique field value like email address or username and if not found in your database store it and or otherwise directly give an authentication to the logged in section of your site.</p> <p>All of these redirections and authentications are made through APIs provided by these authenticating sites. Most of these sites do provide a sign in APIs but do not have the APIs for sign off from the authenticated site (There are few exceptions in this). Once user is logged in to your website through open authentication system via a different web site, he has to actually login into that website. Now when he clicks on the logout link of your site, he logs out from your site not from the site from where he was authenticated. This is risk if any user is accessing your site from the public computer and forgets to log off from the authenticated site. His account would be compromised.</p> <p>You as a developer of your site must provide information about the risk factors to your users before they use separate authentication system for your site. Developers need to create an account on these sites and get secret API key to use their APIs and use this secret key into data transactions with the site.</p> <p>Here are few providers of open authentication services are also called resource owners to authorize other web service or web site to their resources without sharing their users’ credentials.</p> <p>Amazon, Dropbox, Facebook, Flickr, GitHub, Instagram, LinkedIn, Twitter, Tumblrand …..And many of others.</p> ', 'comment_count' => '0', 'postview_count' => '2059', 'active' => '1', 'created' => '2015-06-15 08:15:29', 'modified' => '2019-11-21 06:01:51', 'tags' => 'Open Authentication, Social Network Login, oAuth' ), 'User' => array( 'id' => '1', 'firstname' => 'Chirayu' ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/social-website-login-for-65938-small.jpg', 'namemedium' => '/files/uploads/postimages/social-website-login-for-65938-medium.jpg' ), 'Rating' => array( (int) 0 => array( [maximum depth reached] ) ), 'Tag' => array( (int) 0 => array( [maximum depth reached] ), (int) 1 => array( [maximum depth reached] ), (int) 2 => array( [maximum depth reached] ) ), 'RatingSummary' => array( 'total_votes' => (int) 1, 'total_rating' => (float) 5 ) ) ) $masterclass = '' $appposts = array( (int) 0 => array( 'Post' => array( 'id' => '11', 'user_id' => '1', 'title' => 'Connecting remote server using SSH', 'body' => '<p>SSH stands for secured shall - a secured network service over an unsecured network. It is a network protocol. It provides an encrypted data communication between two computers. SSH can be used interactively to enable terminal sessions. SSH is also used in scripts to remotely and securely access data and other resources. In order to connect to remote server with SSH, you need:</p> <p>1) Server IP or domain name</p> <p>2) Username</p> <p>3) Password</p> <p>4) SSH client - I recommend PuTTY (you can easily download from internet) for windows operating system while Linux and MAC users can use OpenSSH which is mostly installed in their OS.</p> <p><strong>Useful SSH commands frequently used by developers:</strong></p> <p><em>>_ ssh <remote_host></em></p> <p><remote_host> is an IP address or domain name that you are trying to connect to. This command assumes that your username on the remote system is the same as your username on your local system.</p> <p> <em>>_ ssh remote_username@<remote_host></em></p> <p>If your username is different on the remote system. You can specify by using this syntax.</p> <p>Once you are connected to the server, you will be asked to provide a password. SSH works by connecting a client program to an SSH server. In above commands, SSH is the client program. The SSH server is at the <em>remote_host</em> that is specified.</p> <p><strong>How to configure SSH</strong></p> <p>When you change the configuration of SSH, you are changing the settings of the sshd server. In Ubuntu, the main sshd configuration file is located at <em>/etc/ssh/sshd_config</em>.</p> <p>While it is helpful to be able to log in to a remote system using passwords, it is much better idea to set up Key-based authentication.</p> <p>Key based authentication works by creating a pair of keys: <strong>a private key</strong> and <strong>a public key.</strong></p> <p>The private key is located on the client machine. The public key is placed on any server you wish to access. Please check how to generate public and private keys with PuTTY for windows and with ssh-keygen for linux and mac OS. The folder in which the private key is placed default in the windows is c:\users\<username>\.ssh while in unix based system it is under /home/<username>/.ssh</p> <p>The public key is added to a special file within the user account you will be logging into called ~/.ssh/authorized_keys</p> <p>When you attempt to connect using a key pair, the server will use the public key to create a message for the client computer that can only be read with private key.</p> <p>The client computer then sends the appropriate response back to the server and the server will know that the client is legitimate. This entire process is done in the background after keys are correctly setup.</p> <p>SSH operates on TCP port 22 by default. The server listens on port 22 though this can be changed through custom port number in <em>sshd_config</em> file.</p> <p><em>>_ ssh -p</em> <em>7322 remote_username@<remote_host></em></p> <p>If you are not connecting <em>remote host</em> at the default port 22, then you need to specify the custom port number in the command. The above command shows remote host is being connected at the port number 7322.</p> ', 'created' => '2019-11-29 13:06:49', 'tags' => '' ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/ssh-connect-16148-small.jpg', 'namemedium' => '/files/uploads/postimages/ssh-connect-16148-medium.jpg' ), 'Tofriend' => array() ), (int) 1 => array( 'Post' => array( 'id' => '10', 'user_id' => '0', 'title' => 'SOLID Part-2 : Principle of Open and Closed', 'body' => '<p>Any project has a scope of changes in terms of features, functionalities and workflows. Practically, to design application prefactly from begining is almost impossible even in the agile development. Classes and interfaces are pillers of application designs.</p> <p>SOLID is one of the proven set of design principles that are meant to guide developers to design and build robust, easily maintainable and scalable software.<br /> This article is focused ont he second principle of SOLID : The principle of Open / Closed.<br /> It satates that : Software entities (ie. classes, interfaces, functions etc) should be Open to extended but closed for modifications.<br /> Lets Check first what does it mean by this principle.</p> <p>A class is closed since it may be compiled, stored in the library, baselined and used by client classes. But it is also open, since any new class may use it as parent and adding new features.</p> <p>Fortunately we have a concept of Inheritance to achieve this goal. But, inheritance introduces tight coupling if the subclasses depend on implementation details of their parent class.</p> <p>my recomandation is to start designe inheritance with interfaces instead of superclasses. The interfaces are closed for modifications, you can provide new implementations to extend the functionality of your software.</p> <p>Let’s see an example that uses the Open/Closed Principle.</p> <p>We will need a Employee interface, the Company class, which uses the Employees, and some implementation of the Employee interface.<br /> The Company class should know just one thing about the Employees — what methods to call. This is what all the Employees have in common, so we will have a Employee interface with just the common methods(ie. someWork).</p> <p>public interface Employee{<br /> public void someWork();<br /> }</p> <p>And a Company class that encapsulates an Employye implementation and executes it.<br /> public class Company() {<br /> private Employee emp;<br /> // we set the strategy in the constructor<br /> public Company(Employee emp) {<br /> this.emp = emp;<br /> }</p> <p> public void completeTheWork() {<br /> this.emp.someWork();<br /> }<br /> }</p> <p>And let’s create two implementations for the Employee interface.</p> <p>public class Employee1 implements Employee {<br /> public void someWork() {<br /> System.out.println(“Work of Emoloyee 1”);<br /> }<br /> }</p> <p>public class Employee2 implements Employee {<br /> public void someWork() {<br /> System.out.println(“Work of Emoloyee 2”);<br /> }<br /> }</p> <p>Now lets use some dependency Injection to see how it works. We need to create one Perform class.</p> <p>public class Perform() {<br /> public static void main(String[] args) {<br /> Context context = new Company(new Employee1()); // we inject the Employee1<br /> context.completeTheWorky(); // it will print “Execute employee 1”;</p> <p> context = new Company(new Employee2()); // we inject the Employee2<br /> context.completeTheWork(); // it will print “Execute employee 2”<br /> }<br /> }</p> <p>So the Company is decoupled from a specific Employee class. You could implement many Employees it needed and no matter how they work and what you want them to do, you don’t need to modify the Company class. The Company class knows just that it must call someWork method and it is enough.</p> <p>After taking a closer look at the Single Responsibility Principle, we now discussed the Open/Closed Principle.<br /> It uses Interfaces to enable you the functionality of your application without changing the existing code.</p> ', 'created' => '2019-05-24 11:59:08', 'tags' => '' ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/Solid-part-2-28564-small.jpg', 'namemedium' => '/files/uploads/postimages/Solid-part-2-28564-medium.jpg' ), 'Tofriend' => array( (int) 0 => array( [maximum depth reached] ) ) ), (int) 2 => array( 'Post' => array( 'id' => '9', 'user_id' => '0', 'title' => 'SOLID Part-1 : Single Responsibility Principle - Software design', 'body' => '<p>S O L I D</p> <p>'S' represents Single Responsibility Principle</p> <p>Every class should have responsibility over a single part of the functionality provided by the software and that responsibility should be entirely encapsulated by the class. In other words there should never be more than one trigger or reason for a class to change. When a (functional) responsibility is divided over more than one class, all classes’ part of that responsibility has to change.</p> <p>The code must be maintainable. When we need to make a change in a class having more responsibilities the change might affect the other functionality related to the other responsibility of the class. The code, which cannot adapt to change requirements with ease, is not a well defined.</p> <p>When we design our classes, we should take care that one class at the most is responsible for doing only one task or single responsibility. Not only should the class, even operations or methods in the class defined in a way that it has only one responsibility to handle. To understand this let us take an example of Employee class. Class Employee is made with few of its attributes and operations.</p> <p>Class Employee{</p> <p> private String employeeId;</p> <p> private String name;</p> <p> private string address;</p> <p> private Date dateOfJoining;</p> <p> private Int DesignationId;</p> <p> </p> <p> public amtIncrement(){</p> <p> //increment logic implementation</p> <p> }</p> <p> public calDOR(){</p> <p> //Date of retirement logic implementation</p> <p> } </p> <p> public setDateOfJoining(){</p> <p> }</p> <p> public setEmployeeId(){</p> <p> }</p> <p> public getDateOfJoining(){</p> <p> }</p> <p> public getDesignationId(){ </p> <p> } </p> <p>}</p> <p>The above class is correctly structured and it has employee attributes declared. Also it has operations related to employee.</p> <p>Here Employee class should have only responsibility to maintain and manage the data of employee in formations. But this class is violating the principle of Single Responsibility. How?</p> <p><strong>First,</strong> the logic of calculating the Date of Retirement is not the employee's responsibility. This might be defined under the HR class and calculate by taking employee's Date of Joining in the organization which is an attribute of Employee class. So if any change happens in the HR policies, the Employee Class does not get updated. Just because HR policies updated this has nothing to do with the Employee entity.</p> <p><strong>Second,</strong> the logic of calculating the amount of increment is a responsibility of Finance class and it calculated by taking the level or designation of the employee in the organization. So if any change happens to the financial status, the Employee class doesn’t get affected with that.</p> <p>If the class has only one reason to change then it stays less fragile. More responsibilities lead to more dependencies and higher coupling. A test class for a ‘one responsibility class’ will have less test cases (branches). If a class has one purpose it will usually have less dependencies, thus less mocking and test preparing.</p> <p>The Single Responsibility Principle represents a good way of identifying classes during the design phase of an application and it reminds you to think of all the ways a class can evolve. Class and module design is highly affected by SRP and it leads to a low coupled design with less and lighter dependencies.</p> <p>Points to consider when you design the class.</p> <ul> <li>Define clearly what this class is going to do.</li> <li>Reduce the long procedures of the logic. Divide into multiple chunks.</li> <li>Write the code in the way that very small steps can be tested independently.</li> </ul> ', 'created' => '2017-07-12 16:42:05', 'tags' => '' ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/Solid-part-1-50472-small.jpg', 'namemedium' => '/files/uploads/postimages/Solid-part-1-50472-medium.jpg' ), 'Tofriend' => array( (int) 0 => array( [maximum depth reached] ), (int) 1 => array( [maximum depth reached] ), (int) 2 => array( [maximum depth reached] ) ) ), (int) 3 => array( 'Post' => array( 'id' => '8', 'user_id' => '0', 'title' => 'CSV files data into php array to store in MySql', 'body' => '<p><strong><em>What are CSV files?</em></strong></p> <p>A CSV (Comma Separated Values) files are text files, allows data to be saved in a structured format. CSV files can be used with Microsoft Excel, Google Spreadsheets or Open Office Calc kind of tools. These CSV files are saved with .csv extension. In CSV files data fields are usually separated by comma as delimiter, but can also use a tab or pipe symbol instead of comma. CSV files are used to import and export data from application to application. Mostly, the first record is a header containing a list of field names. Any programming language has technique to import and export data from and to database like MS-SQL, MySql, PostGres, etc..</p> <p>PHP is one of the best programming languages for import and export of the data with the database to and from flat files like CSV files.</p> <p><strong><em>Fetching the data from the CSV file</em></strong></p> <p>Open the file in the read mode and store the content into variable. We assume that the CSV file contains the information about the contacts having fields firstname, lastname, email, and phone exported and the file name is contacts.csv.</p> <p>$csvfilehandle = fopen("contacts.csv","r");</p> <p>Here $csvfilehandle is file pointer to a file "contacts.csv" successfully opened</p> <p>while (($line = fgetcsv($csvfilehandle,1000,',','"'))!==false){</p> <p> $data[] = $line;</p> <p>}</p> <p>Close the opened file handle with </p> <p>fclose($csvfilehandle);</p> <p>The first argument $csvfilehandle is the mandatory arguments and remaining are optional.</p> <p>1000 is a length of characters per line to be set. This should be greater than the longest line in the file. If you are not sure about the length then don`t specify it.</p> <p>',' comma is a delimiter you can set or according to the data in the file the delimiter is used.</p> <p>'"' is the enclosure in the file used for the field value</p> <p>Now you have all the data of the CSV file into the array $data. If you print this with print_r($data); you get values into array.</p> <p><strong><em>Importing data into MySQL table</em></strong></p> <p>Now to import the data into the MySQL table named contacts, we need to modify the above wile loop. Let`s do that now.</p> <p>while (($line = fgetcsv($csvfilehandle,1000,',','"'))!==false){ </p> <p> mysql_query("insert into contacts(</p> <p> firstname, lastname, email, telephone</p> <p> )VALUES(</p> <p> '".mysql_real_escape_string($line[0])."',</p> <p> '".mysql_real_escape_string($line[1])."',</p> <p> '".mysql_real_escape_string($line[2])."',</p> <p> '".mysql_real_escape_string($line[3])."'</p> <p> )")</p> <p>or die(mysql_error());</p> <p>}</p> <p>fclose($csvfilehandle);</p> <p>Write me back if you are working for such functionality and not getting through the code.</p> ', 'created' => '2016-11-03 07:17:48', 'tags' => '' ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/csv-files-data-into-88773-small.png', 'namemedium' => '/files/uploads/postimages/csv-files-data-into-88773-medium.png' ), 'Tofriend' => array() ), (int) 4 => array( 'Post' => array( 'id' => '7', 'user_id' => '0', 'title' => 'How the PHP script may report what is the total size of any web page browsed', 'body' => '<p>These days excellent work is being done to attract web site users by creating attractive and well managed web pages. While browsing any internet site or a web page as developer or designer of the web pages we might came across the thought, “how much size of this web page is? or how much costly to render this on my browser?”. Well today lets build a script which reports information of above questions. As usual we will be using PHP for scripting the code. This script includes two things in consideration. <strong>First,</strong> how many http/https requests are being used to render the page and <strong>Second,</strong> what is the total size of the rendered web page. We will create a script in a manner that it can be used from command line interface as well as from the browser. For this the cURL module is used. If it is not installed in your PHP set up then go to my previous article of installation and configuration of PHP.</p> <p>Ok. So now what is the meaning of <strong>First</strong> part, “how many http/https requests are”. When any web page is rendered or loaded in your browser, it is a combination of one or multiple CSS files, one or multiple javascripts or .js files, code of Html, multiple images, etc… we call them web page resources as all together they make a web page. While web page is loaded all these multiple files are being called from one or different locations with specific web address. These files are called one by one as it cannot called all once at a time. The separate calls for each of these files are known as http/https requests.</p> <p>Now let’s come to the Second part of the task – “what is the total size of the rendered web page” and that consist of file size of each of these resource we saw above. When http/https requests are responded uninterrupted then that response contains response header (developers and designers knows that). One of the headers is called “Content-Length” and that gives the size of that particular resource. We need to use built in API of PHP ie. get_headers and the argument would be the URL where the http/https request is sent. Bellow is the hint and good start of the code in PHP.</p> <p><strong><em>function file_size_rendered($url) { </em></strong></p> <p><strong><em>//where $url in the argument is the location where request is being sent.</em></strong></p> <p><strong><em> $headers = get_headers($url, 1);</em></strong> </p> <p><strong><em> if (isset($headers['Content-Length'])) </em></strong></p> <p><strong><em> return $headers['Content-Length'];</em></strong> </p> <p><strong><em>//Also check whether lower case of "L" is used in Content-length</em></strong></p> <p><strong><em> if (isset($headers['Content-length'])) </em></strong></p> <p><strong><em> return $headers['Content-length'];</em></strong></p> <p><strong><em>//if the content header is not found then use the curl request</em></strong></p> <p><strong><em> $c = curl_init();</em></strong></p> <p><strong><em> curl_setopt_array($c, array(</em></strong></p> <p><strong><em> CURLOPT_URL => $url,</em></strong></p> <p><strong><em> CURLOPT_RETURNTRANSFER => true,</em></strong></p> <p><strong><em> CURLOPT_HTTPHEADER => array('User-Agent: Mozilla/5.0 </em></strong></p> <p><strong><em> (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.3) </em></strong></p> <p><strong><em> Gecko/20090824 Firefox/3.5.3'),</em></strong></p> <p><strong><em> ));</em></strong></p> <p><strong><em> curl_exec($c);</em></strong> </p> <p><strong><em> $size = curl_getinfo($c, CURLINFO_SIZE_DOWNLOAD);</em></strong> </p> <p><strong><em> return $size;</em></strong> </p> <p><strong><em> curl_close($c);</em></strong></p> <p><strong><em>}</em></strong></p> <p>This article is just a good start to inspire for deeper understanding or the technique of coding. One can browse more or post questions to get answer on more specific tasks.</p> ', 'created' => '2015-12-28 10:52:20', 'tags' => '' ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/how-the-php-script-may-62903-small.jpg', 'namemedium' => '/files/uploads/postimages/how-the-php-script-may-62903-medium.jpg' ), 'Tofriend' => array() ) ) $regions = array() $appcountries = array( (int) 1 => 'Andorra', (int) 2 => 'United Arab Emirates', (int) 3 => 'Afghanistan', (int) 4 => 'Antigua and Barbuda', (int) 5 => 'Anguilla', (int) 6 => 'Albania', (int) 7 => 'Armenia', (int) 8 => 'Netherlands Antilles', (int) 9 => 'Angola', (int) 12 => 'Argentina', (int) 13 => 'American Samoa', (int) 14 => 'Austria', (int) 15 => 'Australia', (int) 16 => 'Aruba', (int) 17 => 'Azerbaijan', (int) 18 => 'Bosnia and Herzegovina', (int) 19 => 'Barbados', (int) 20 => 'Bangladesh', (int) 21 => 'Belgium', (int) 22 => 'Burkina Faso', (int) 23 => 'Bulgaria', (int) 24 => 'Bahrain', (int) 25 => 'Burundi', (int) 26 => 'Benin', (int) 27 => 'Bermuda', (int) 28 => 'Brunei Darussalam', (int) 29 => 'Bolivia', (int) 30 => 'Brazil', (int) 31 => 'Bahamas', (int) 32 => 'Bhutan', (int) 34 => 'Botswana', (int) 35 => 'Belarus', (int) 36 => 'Belize', (int) 37 => 'Canada', (int) 38 => 'Cocos (Keeling) Islands', (int) 40 => 'Central African Republic', (int) 41 => 'Congo', (int) 42 => 'Switzerland', (int) 43 => 'Cote D'Ivoire', (int) 44 => 'Cook Islands', (int) 45 => 'Chile', (int) 46 => 'Cameroon', (int) 47 => 'China', (int) 48 => 'Colombia', (int) 49 => 'Costa Rica', (int) 51 => 'Cuba', (int) 52 => 'Cape Verde', (int) 53 => 'Christmas Island', (int) 54 => 'Cyprus', (int) 55 => 'Czech Republic', (int) 56 => 'Germany', (int) 57 => 'Djibouti', (int) 58 => 'Denmark', (int) 59 => 'Dominica', (int) 60 => 'Dominican Republic', (int) 61 => 'Algeria', (int) 62 => 'Ecuador', (int) 63 => 'Estonia', (int) 64 => 'Egypt', (int) 65 => 'Western Sahara', (int) 66 => 'Eritrea', (int) 67 => 'Spain', (int) 68 => 'Ethiopia', (int) 70 => 'Finland', (int) 71 => 'Fiji', (int) 72 => 'Falkland Islands (Malvinas)', (int) 73 => 'Micronesia, Federated States of', (int) 74 => 'Faroe Islands', (int) 75 => 'France', (int) 77 => 'Gabon', (int) 78 => 'United Kingdom', (int) 79 => 'Grenada', (int) 80 => 'Georgia', (int) 81 => 'French Guiana', (int) 82 => 'Ghana', (int) 83 => 'Gibraltar', (int) 84 => 'Greenland', (int) 85 => 'Gambia', (int) 86 => 'Guinea', (int) 87 => 'Guadeloupe', (int) 88 => 'Equatorial Guinea', (int) 89 => 'Greece', (int) 90 => 'South Georgia and Sandwich Island', (int) 91 => 'Guatemala', (int) 93 => 'Guinea-Bissau', (int) 94 => 'Guyana', (int) 95 => 'Hong Kong', (int) 97 => 'Honduras', (int) 98 => 'Croatia', (int) 99 => 'Haiti', (int) 100 => 'Hungary', (int) 101 => 'Indonesia', (int) 102 => 'Ireland', (int) 103 => 'Israel', (int) 104 => 'India', (int) 106 => 'Iraq', (int) 107 => 'Iran, Islamic Republic of', (int) 108 => 'Iceland', (int) 109 => 'Italy', (int) 110 => 'Jamaica', (int) 111 => 'Jordan', (int) 112 => 'Japan', (int) 113 => 'Kenya', (int) 114 => 'Kyrgyzstan', (int) 115 => 'Cambodia', (int) 116 => 'Kiribati', (int) 117 => 'Comoros', (int) 118 => 'Saint Kitts and Nevis', (int) 119 => 'Korea, Democratic', (int) 120 => 'Korea, Republic of', (int) 121 => 'Kuwait', (int) 122 => 'Cayman Islands', (int) 123 => 'Kazakhstan', (int) 124 => 'Laos', (int) 125 => 'Lebanon', (int) 126 => 'Saint Lucia', (int) 127 => 'Liechtenstein', (int) 128 => 'Sri Lanka', (int) 129 => 'Liberia', (int) 130 => 'Lesotho', (int) 131 => 'Lithuania', (int) 132 => 'Luxembourg', (int) 133 => 'Latvia', (int) 134 => 'Libya', (int) 135 => 'Morocco', (int) 136 => 'Monaco', (int) 137 => 'Moldova', (int) 138 => 'Madagascar', (int) 139 => 'Marshall Islands', (int) 140 => 'Macedonia', (int) 141 => 'Mali', (int) 142 => 'Myanmar', (int) 143 => 'Mongolia', (int) 144 => 'Macau', (int) 145 => 'Northern Mariana Islands', (int) 146 => 'Martinique', (int) 147 => 'Mauritania', (int) 148 => 'Montserrat', (int) 149 => 'Malta', (int) 150 => 'Mauritius', (int) 151 => 'Maldives', (int) 152 => 'Malawi', (int) 153 => 'Mexico', (int) 154 => 'Malaysia', (int) 155 => 'Mozambique', (int) 156 => 'Namibia', (int) 157 => 'New Caledonia', (int) 158 => 'Niger', (int) 159 => 'Norfolk Island', (int) 160 => 'Nigeria', (int) 161 => 'Nicaragua', (int) 162 => 'Netherlands', (int) 163 => 'Norway', (int) 164 => 'Nepal', (int) 165 => 'Nauru', (int) 166 => 'Niue', (int) 167 => 'New Zealand', (int) 168 => 'Oman', (int) 169 => 'Panama', (int) 170 => 'Peru', (int) 171 => 'French Polynesia', (int) 172 => 'Papua New Guinea', (int) 173 => 'Philippines', (int) 174 => 'Pakistan', (int) 175 => 'Poland', (int) 176 => 'Saint Pierre and Miquelon', (int) 177 => 'Pitcairn', (int) 180 => 'Portugal', (int) 181 => 'Palau', (int) 182 => 'Paraguay', (int) 183 => 'Qatar', (int) 184 => 'Reunion', (int) 185 => 'Romania', (int) 186 => 'Russian Federation', (int) 187 => 'Rwanda', (int) 188 => 'Saudi Arabia', (int) 189 => 'Solomon Islands', (int) 190 => 'Seychelles', (int) 191 => 'Sudan', (int) 192 => 'Sweden', (int) 193 => 'Singapore', (int) 194 => 'Saint Helena', (int) 195 => 'Slovenia', (int) 196 => 'Svalbard and Jan Mayen', (int) 197 => 'Slovakia', (int) 198 => 'Sierra Leone', (int) 199 => 'San Marino', (int) 200 => 'Senegal', (int) 201 => 'Somalia', (int) 202 => 'Suriname', (int) 203 => 'Sao Tome and Principe', (int) 204 => 'El Salvador', (int) 205 => 'Syrian Arab Republic', (int) 206 => 'Swaziland', (int) 207 => 'Turks and Caicos Islands', (int) 208 => 'Chad', (int) 209 => 'French Southern Territories', (int) 210 => 'Togo', (int) 211 => 'Thailand', (int) 212 => 'Tajikistan', (int) 213 => 'Tokelau', (int) 215 => 'Turkmenistan', (int) 216 => 'Tunisia', (int) 217 => 'Tonga', (int) 218 => 'Turkey', (int) 219 => 'Trinidad and Tobago', (int) 220 => 'Tuvalu', (int) 221 => 'Taiwan', (int) 222 => 'Tanzania, United Republic', (int) 223 => 'Ukraine', (int) 224 => 'Uganda', (int) 226 => 'United States', (int) 227 => 'Uruguay', (int) 228 => 'Uzbekistan', (int) 230 => 'Saint Vincent and the Grenadines', (int) 231 => 'Venezuela', (int) 232 => 'Virgin Islands, British', (int) 233 => 'Virgin Islands, U.S.', (int) 234 => 'Vietnam', (int) 235 => 'Vanuatu', (int) 236 => 'Wallis and Futuna', (int) 237 => 'Samoa', (int) 238 => 'Yemen', (int) 239 => 'Mayotte', (int) 240 => 'South Africa', (int) 241 => 'Zambia', (int) 242 => 'Zaire', (int) 243 => 'Zimbabwe' ) $data = array( 'Post' => array( 'id' => '5', 'postcategory_id' => '7', 'user_id' => '1', 'title' => 'Social website login for your site is Open source standards for authorization', 'body' => '<p>You might have seen many of sites now showing links or buttons of Facebook, Twitter, Google + or other social network sites on their sign up and sign in page. This is to make users life bit easier for the login or sign up process on various websites. What happens when you click on any of that link? Have you tried anytime?</p> <p>Let’s see how you as a developer can develop this feature for your website. For this we consider a use case.</p> <p><em>User came to the sign in page of your site and he looked at the login with “facebook” or “twitter” or “google” (or any of the site) link. He has a separate account of any of these listed social network sites which you have integrated in your website. He clicks on any of the link and now he is redirected to the respective site for authentication. He provides correct credential for that social network site. He is now authenticated by that social network site and if it is for the first time he is using this authentication system, he has to agree to share his profile data with the other site from where he is coming for the authentication.</em></p> <p>When user agrees to share his profile data on successful login, that social network site redirect him to your site with user’s profile information. Of course password would not be sent to your site. This authenticating social network site will generate one token for this session and send along with the user’s profile data. This token is unique to user and your site. Now all communication and data exchange between your site and the authenticating social network site happens with this token generated by the authenticated site. Give essential profile data to your website login system and create a successful login session at your website and treat him as a logged in user.</p> <p> You can store this user information into your database and send an email to him with the new login credentials to login in your site directly in future. If he doesn’t want to login from your site directly, he still has an option to login again from the social network site which he chooses. Check every time while login weather he is the stored user with his unique field value like email address or username and if not found in your database store it and or otherwise directly give an authentication to the logged in section of your site.</p> <p>All of these redirections and authentications are made through APIs provided by these authenticating sites. Most of these sites do provide a sign in APIs but do not have the APIs for sign off from the authenticated site (There are few exceptions in this). Once user is logged in to your website through open authentication system via a different web site, he has to actually login into that website. Now when he clicks on the logout link of your site, he logs out from your site not from the site from where he was authenticated. This is risk if any user is accessing your site from the public computer and forgets to log off from the authenticated site. His account would be compromised.</p> <p>You as a developer of your site must provide information about the risk factors to your users before they use separate authentication system for your site. Developers need to create an account on these sites and get secret API key to use their APIs and use this secret key into data transactions with the site.</p> <p>Here are few providers of open authentication services are also called resource owners to authorize other web service or web site to their resources without sharing their users’ credentials.</p> <p>Amazon, Dropbox, Facebook, Flickr, GitHub, Instagram, LinkedIn, Twitter, Tumblrand …..And many of others.</p> ', 'comment_count' => '0', 'postview_count' => '2059', 'active' => '1', 'created' => '2015-06-15 08:15:29', 'modified' => '2019-11-21 06:01:51', 'tags' => 'Open Authentication, Social Network Login, oAuth' ), 'User' => array( 'id' => '1', 'firstname' => 'Chirayu' ), 'Postcoverimage' => array( 'namesmall' => '/files/uploads/postimages/social-website-login-for-65938-small.jpg', 'namemedium' => '/files/uploads/postimages/social-website-login-for-65938-medium.jpg' ), 'Rating' => array( (int) 0 => array( 'id' => '2', 'foreign_model' => 'Post', 'foreign_id' => '5', 'author_ip' => '101.56.103.146', 'rating' => '5', 'created' => '2015-06-15 16:13:35' ) ), 'Tag' => array( (int) 0 => array( 'id' => '11', 'name' => 'Open Authentication', 'keyname' => 'openauthentication', 'Tagged' => array( [maximum depth reached] ) ), (int) 1 => array( 'id' => '12', 'name' => 'Social Network Login', 'keyname' => 'socialnetworklogin', 'Tagged' => array( [maximum depth reached] ) ), (int) 2 => array( 'id' => '13', 'name' => 'oAuth', 'keyname' => 'oauth', 'Tagged' => array( [maximum depth reached] ) ) ), 'RatingSummary' => array( 'total_votes' => (int) 1, 'total_rating' => (float) 5 ) ) $model = null $modelClass = null $submit_url = '/feedback/ratings/add' $element_id = 'rating-789843234' $message_id = 'message-789843234' $values_id = 'values-789843234' $readonly = 'false' $value = (float) 5 $votes = (float) 1 $user_vote = (int) 0 $user_vote_message = 'Your vote: 0.0' $submitting_message = 'Sending vote...' $error_message = 'There was an error while saving your vote'include - APP/Plugin/Feedback/View/Elements/rating.ctp, line 59 View::_evaluate() - CORE/Cake/View/View.php, line 971 View::_render() - CORE/Cake/View/View.php, line 933 View::_renderElement() - CORE/Cake/View/View.php, line 1224 View::element() - CORE/Cake/View/View.php, line 418 RatingsHelper::display_for() - APP/Plugin/Feedback/View/Helper/RatingsHelper.php, line 53 include - APP/View/Posts/filter.ctp, line 30 View::_evaluate() - CORE/Cake/View/View.php, line 971 View::_render() - CORE/Cake/View/View.php, line 933 View::render() - CORE/Cake/View/View.php, line 473 Controller::render() - CORE/Cake/Controller/Controller.php, line 963 Dispatcher::_invoke() - CORE/Cake/Routing/Dispatcher.php, line 200 Dispatcher::dispatch() - CORE/Cake/Routing/Dispatcher.php, line 167 [main] - APP/webroot/index.php, line 109
Page 1 of 1, showing 5 records out of 5 total, starting on record 1, ending on 5