Explain the changing file permission and ownership using PHP's chmod() function.
Correct Answer
Chmod() is used for changing permissions on a file Syntax: Chmod(file, mode) Mode here specifies the permissions as follows: The first number is always zero The second number specifies permissions for the owner The third number specifies permissions for the owner's user group The fourth number specifies permissions for everybody else Possible values (to set multiple permissions, add up the following numbers) 1 = execute permissions 2 = write permissions 4 = read permissions Example: // everything for owner, read for owner's group chmod("testtxt",0740);
Technology problems
Search Results
1. How can we encrypt the username and password using PHP?
Correct Answer: User names and passwords in PHP can be encrypted using md5 function MD5 function calculates the md5 hash of a string It is basically used for encryption It is also used for digital signature applications, where a large file must be "compressed" in a secure manner Example: Md5($str); Crypt() function can also be used to encrypt a string, It used MD5, DES or blow fish algorithms for encryption Syntax: Crypt(str, salt) Salt is an optional parameter used to increase the number of characters encoded, to make the encoding more secure
Correct Answer: A PHP Session persist the user information to be used later For example, user name, password, shopping item details The session is temporary and will be removed soon after the user has left the web site The session can be persisted for long term usage on databases like MySQL Each session is identified by a unique Id number for every visitor The first step to use PHP session is to start the session The starting session must precede the operations like HTML or the other The statement session_start() starts the PHP session and registers the user?s information on the server
Correct Answer: The function setcookie() is used to define a cookie that is to be sent along with HTTP headers The cookie must be sent prior to any output from the script as is the protocol restriction After setting the cookies, they can be used when the next page is loaded by using $_COOKIE or $HTTP_COOKIE_VARS arrays
4. Explain when to use GET or POST. Provide example for both the ways.
Correct Answer: Both GET and POST are used to collect data from a form However, when security is desired $_POST should be used When the $_ POST variable is used, all variables used are NOT displayed in the URL Also, they have no restrictions to the length of the variables GET should be used when the interaction with the form is more like a question For eg firing a query etc POST should be used more often when the interaction is more like an order or the interaction changes the state of the resource POST example: On clicking submit the URL resembles to: https://wwwmysamplesitecom/samplephp The samplephp file can be used for catching the form data using $_POST Hello You are years old! GET EXAMPLE On clicking submit the URL resembles to : https://wwwmysamplesitecom/samplephp?name=jim&age=37 The samplephp file can be used for catching the form data using $_GET Hello You are years old!
5. 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
6. Explain the working with directories using opendir(), readdirs(), closedir() along with examples.
Correct Answer: Opendir():- It opens the directory This function returns a directory stream on success and FALSE and an error on failure Syntax: Opendir(directory, context) Context is a set of options that can modify the behavior of a stream Example: opens sample directory $dir = opendir("directory"); Readdir(): It returns an entry from a directory handle opened by opendir() Syntax: Readdir(dir_stream) Example: $file = readdir($dir); closedir(): It closes a directory handle opened by opendir() Syntax: closedir(dir_stream) Example: $file = close($dir);
7. What is the difference between using copy() and move() function in php file uploading?
Correct Answer: Copy() makes a copy of the file It returns TRUE on success It can copy from any source to destination Move simply Moves the file to destination if the file is valid While move can move the uploaded file from temp server location to any destination on the server If filename is a valid upload file, but cannot be moved for some reason, no action will occur
8. What is the difference between mysql_connect and mysql_pconnect?
Correct Answer: There is a decent page in the php manual on the subject, in short mysql_pconnect() makes a persevering association with the database which implies a SQL join that don't close when the execution of your script closes mysql_connect()provides just for the database new association while utilizing mysql_pconnect , the capacity would first attempt to locate a (relentless) connection that is as of now open with the same host, username and password On the off chance that one is found, an identifier for it will be returned as opposed to opening another connection the connection with the SQL server won't be terminated when the execution of the script ends Rather, the link will stay open for future use
Correct Answer: - When two processes are waiting to update the rows of a table which are locked by another process, the situation is called a deadlock - The reasons for it to happen are: * lack of proper row lock commands * Poor design of front-end application - It reduces the performance of the server severely - These locks get automatically released automatically when a commit/rollback operation is performed or any process is killed externally
Correct Answer: Control File is used for: - Database recovery - Whenever an instance of an ORACLE database begins, its control file is used to identify the database and redo log files that must be opened for database operation to go ahead