All java c# asp.net .net servlet jdbc c sqlserver android ado.net javascript php wcf clearcase angularjs 2

How to get facebook access token for application

Hi, I came across a good article at : https://smashballoon.com/custom-facebook-feed/access-token/, it got step-by-step instructions, it may be useful to you.

Obtaining an App Access Token

To obtain an App Access Token, invoke the following HTTP GET request:

GET https://graph.facebook.com/oauth/access_token?
            client_id=YOUR_APP_ID
           &client_secret=YOUR_APP_SECRET
           &grant_type=client_credentials

The API will respond with a query-string formatted string of the form:

access_token=YOUR_APP_ID|YOUR_APP_ACCESS_TOKEN

Reference: http://developers.facebook.com/docs/opengraph/howtos/publishing-with-app-token/

how do you insert the data into mySQL Using PHP

<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

$sql = "INSERT INTO MyGuests (firstname, lastname, email)
VALUES ('John', 'Doe', 'john@example.com');"
;
$sql .= "INSERT INTO MyGuests (firstname, lastname, email)
VALUES ('Mary', 'Moe', 'mary@example.com');"
;
$sql .= "INSERT INTO MyGuests (firstname, lastname, email)
VALUES ('Julie', 'Dooley', 'julie@example.com')"
;

if ($conn->multi_query($sql) === TRUE) {
    echo "New records created successfully";
else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();
?>

  • The SQL query must be quoted in PHP
  • String values inside the SQL query must be quoted
  • Numeric values must not be quoted
  • The word NULL must not be quoted

The INSERT INTO statement is used to add new records to a MySQL table:

INSERT INTO table_name (column1, column2, column3,...)
VALUES (value1, value2, value3,...)

Getting 'Access-Control-Allow-Origin' missing error

If I understood it right you are doing an XMLHttpRequest to a different domain than your page is on. So the browser is blocking it as it usually allows a request in the same origin for security reasons. You need to do something different when you want to do a cross-domain request. A tutorial about how to achieve that is Using CORS.

When you are using postman they are not restricted by this policy. Quoted from Cross-Origin XMLHttpRequest:

What is Open Source Software and PHP ?

Generally, the source code is protected by the developer, of the late, developers are willing to share the source code of the software, to modify, share and reuse, this trend is called as open source movement, recently microsoft is also started sharing their source code. Php is a server side scripting language, usef for web application, the success for this is open source, and applications like facebook, etc. using the php.

 In general, open source refers to any program whose source code is made available for use or modification as users or other developers see fit. Open source software is usually developed as a public collaboration and made freely available.

PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used open source general-purpose scripting language that is especially suited for web development and can be embedded into HTML.

List common error types and differences in php

In PHP there are 3 types of errors:

  • Notices: These are simple and non-critical errors that generates during the script execution, like trying to access the undefined value.
  • Warnings: These are warnings only, but these are only warnings, doesn't stop the execution, like referring a non-existing file, etc.,
  • Fatal : These are more critial errors, which breaks the script execution, most common error would be, trying to access a non-existing object, etc.,

The clear understanding of the error types and their nature is important, they help the developer to understand the issues arising during the run-time, and find the solution to fix them.

Basically there are four kinds of errors in PHP:

Parse Error (Syntax Error): The parse error occurs if there is a syntax mistake in the script; the output is Parse error. A parse error stops the execution of the script. There are many reasons for the occurrence of parse errors in PHP.

Fatal Error: Fatal errors are caused when PHP understands what you've written, however what you're asking it to do can't be done. Fatal errors stop the execution of the script. If you are trying to access the undefined functions, then the output is a fatal error.

Warning Error: Warning errors will not stop execution of the script. The main reason for warning error is to include a missing file or using the incorrect number of parameters in a function.

Notice Error: Notice error is the same as a warning error i.e. in the notice error, execution of the script does not stop. Notice that the error occurs when you try to access the undefined variable, then produce a notice error.

Differences in PHP:

PHP is a server-side scripting language that has its main implementation in web development. PHP is an open source, server-side, HTML embedded scripting language. It can basically perform any task that other CGI programs can, but it is mainly used to create dynamic Web pages. Its main advantage is that it is compatible with many types of databases. Furthermore, PHP can talk across networks using IMAP, SNMP, NNTP, POP3, or HTTP.

  • E_ERROR: A fatal error that causes script termination.
  • E_WARNING: Run-time warning that does not cause script termination.
  • E_PARSE: Compile time parse error.
  • E_NOTICE: Run time notice caused due to error in code.

List various various errors in PHP ?

Basically, PHP offers 4 different types of errors.
Parse Errors : These are syntax errors in codes, like missing semicolon, mismatch brackets, etc.,
Fatal Errors : Runtime errors, like referring to non-existing object or function, etc.,
Warning Errors : Application warns you when you refer files, which are not available. The important point, these are warnings only, it will not stop the application, unless the referred file contains next steps of the flow.
Notice Errors: Notice errors, alert you about the errors.

Different type of errors are as following:

  1. E_ERROR : Fatal run-time errors.
  2. E_WARNING : Run-time warning.
  3. E_PARSE : Compile time parse error.
  4. E_NOTICE : Run time notice.
  5. E_CORE_ERROR : errors that occur during PHP's initial startup.
  6. E_CORE_WARNING : Warnings (non-fatal errors) that occur during PHP's initial startup. 
  7. E_COMPILE_ERROR : Fatal compile-time errors.
  8. E_USER_ERROR : User-generated error message. 
  9. E_USER_WARNING : User-generated warning message. 
  10. E_USER_NOTICE : User-generated notice message. 
  11. E_STRICT : Run-time notices. Enable to have PHP suggest changes to your code which will ensure the best interoperability and forward compatibility of your code.
  12. E_RECOVERABLE_ERROR :Catchable fatal error. It indicates that a probably dangerous error occured, but did not leave the Engine in an unstable state.
  13. E_ALL : All errors and warnings, as supported, except of level E_STRICT in PHP < 6.
  • E_ERROR: A fatal error that causes script termination.
  • E_WARNING: Run-time warning that does not cause script termination.
  • E_PARSE: Compile time parse error.
  • E_NOTICE: Run time notice caused due to error in code.

what are encryption functions in php?

The crypt() function returns a hashed string using DES, Blowfish, or MD5 algorithms. This function behaves different on different operating systems. PHP checks what algorithms are available and what algorithms to use when it is installed. The salt parameter is optional. However, crypt() creates a weak password without the salt. Make sure to specify a strong enough salt for better security.

For real encryption, mcrypt is the solution. For obfuscation, a third function is uuencode; here's some code for decoding; encoding involves reversing the order.

$text = str_rot13($text);
$text = base64_decode($text);
$text = convert_uudecode($text);

Note that both base64_encode and convert_uudecode increase the size of the data.

How can we know the total number of elements of Array?

  • sizeof($array_var)
  • count($array_var)

If we just pass a simple var instead of a an array it will return 1.

The count() function returns the number of elements in an array.

Syntax: count(array,mode);

What is the use of 'print' in php?

This is not actually a real function, It is a language construct. So you can use with out parentheses with its argument list.
Example print('PHP Interview questions'); 
print 'Job Interview ');

The print() function outputs one or more strings.

print(strings)

What is the difference between the functions unlink and unset?

unlink() deletes the given file from the file system.
unset() makes a variable undefined.

unlink() is a function for file system handling, unlink() is used to delete files. Suppose you have uploaded a file and wants to delete this file through the coding then unlink() function is used to delete the file. unset() is a function for variable management. It will make a variable undefined. Or we can say that unset() is used to null out the value of a given variable. OR Unset () is used to destroy a variable in PHP. In can be used to remove a single variable, multiple variables, or an element from an array.