Permissions in PHP are very similar to UNIX Each file has three types of permissions ? Read, write and execute Permissions can be changed using the change mode or CHMOD command CHMOD is followed by 3 digit number specifying the permission type CHMOD 777 is for Read, Write and execute Unnecessary permissions can be stripped off using UNMASK command Unmask (777);
Technology problems
Search Results
1. What is the difference between $argv and $argc? Give example?
Correct Answer: To pass the information into the script from outside, help can be taken from the PHP CLI (Command line interface) method Suppose addition of two numbers has to be passed to PHP then it can be passed like this on the command line: php addphp 2 3 Here the script name is addphp, and 2 and 3 are the numbers that has to be added by the script These numbers are available inside the script in an array called $argv This array contains all the information on the command line; the statement is stored as follows: $argv[0]=addphp $argv[1]=2 $argv[2]=3 So, $argv always contains at least one element ? the script name Then, in your script, you can use the following statements: $sum = $argv[1] + $argv[2]; echo $sum; $argc is a variable that stores the numbers of elements in $argv $argc is equal to at least 1, which is saved for the name of the script Example is $argc=3 using the above statements
Correct Answer: $_SERVER and $_ENV arrays contain different information The information depends on the server and operating system being used Most of the information can be seen of an array for a particular server and operating system The syntax is as follows: foreach($_SERVER as $key =>$value) { echo ?Key=$key, Value=$value\n?; }
Correct Answer: Super global arrays are the built in arrays that can be used anywhere They are also called as auto-global as they can be used inside a function as well The arrays with the longs names such as $HTTP_SERVER_VARS, must be made global before they can be used in an array This $HTTP_SERVER_VARS check your phpini setting for long arrays
4. How can we increase the execution time of a php script?
Correct Answer: By the use of void set_time_limit(int seconds) Set the number of seconds a script is allowed to run If this is reached, the script returns a fatal error The default limit is 30 seconds or, if it exists, the max_execution_time value defined in the phpini If seconds is set to zero, no time limit is imposed When called, set_time_limit() restarts the timeout counter from zero In other words, if the timeout is the default 30 seconds, and 25 seconds into script execution a call such as set_time_limit(20) is made, the script will run for a total of 45 seconds before timing out
5. What is the difference between PHP and JavaScript?
Correct Answer: The difference lies with the execution of the languages PHP is server side scripting language, which means that it can?t interact directly with the user Whereas, JavaScript is client side scripting language, that is used to interact directly with the user
Correct Answer: To access the global data which is originating externally, the super globals are used The superglobals are available as arrays These superglobals represents the data from URLs, HTML forms, cookies, sessions and also the web server For this purpose, $HTTP_GET_VARS, $HTTP_POST_VARS are used The super globals are pretty good enough to be used in functions The following are the list of super globals $_GET, $_POST, $_COOKIE;$_REQUEST, $_SERVER, $_SESSION, $_ENV, $_FILE Another PHP Superglobal, called $GLOBALS; is available for persisting every variable with global scope
7. Explain how to send large amounts of emails with php.
Correct Answer: The mail() function of PHP is quite robust for sending bulk emails A SMTP server can also be directly used from the script PHPmailer class can be used for sending emails
8. Explain how to store the uploaded file to the final location.
Correct Answer: A HTML form should be build before uploading the file The following HTML code is used for selecting the file that is to be uploaded The type attribute of input must be ?file? At the time of executing uploaderphp, the uploaded file will be stored in a temporary storage are on the webserver An associative array $_FILES['uploadedfile']['name'] is used for uploading The ?name? is the original file that is to be uploaded Another associative array $_FILES['uploadedfile']['tmp_name'] is used for placing the uploaded file in a temporary location on the server and the file should be empty and should exist with the tmp_name The following code snippet is used for uploading the file $target_path = "uploads/"; // the target location of the file $target_path = $target_path basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file " basename( $_FILES['uploadedfile']['name']) " has been uploaded"; } else { echo ?There was an error while uploading the file?; } The function move_uploaded_file()is used to place the source file into the destination folder, which resides on the server If the uploading is successful, the message ?The file filename has been uploaded Otherwise the error message ?There was an error while uploading the file? would be displayed
Correct Answer: Generating random passwords in PHP can be done in multiple ways depending on how much security the application demands:- Md5 function can be passed one parameter as uniqid() function which in turn generates a random number Passing the parameter as TRUE in uniqid() adds additional uniqueness
10. What type of inheritance that PHP supports? Provide an example.
Correct Answer: PHP supports single level inheritance Inheriting a class would mean creating a new class with all functionality of the existing class in addition to some more The created class is called as a subclass of the parent class Parent is a keyword which we use to access members of a parent class Inheritance is usually defined by using the keyword ?Extend? $this is used a reference to the calling object Inheritance avoids redundancy of code Example: Class employee extends manager : Here Employee is a subclass of manager Echo $this->name can be used to echo variable name of the parent class