ITTreats.com
Enter your Search term and Hit "Enter"

Thu, 11 Mar 2010 9:51:27 AM +00:00

Latest 'ITTreats'


workaround for sessions on cookie disabled machines in php

workaround for sessions on cookie disabled machines in php

In PHP, Will sessions work on cookies disabled  Computers ?

The answer is   “NO”.

because,

Server cookie is a session or we can say that session is also a cookie on the server.

For session to work, cookies on server as well as on client browser should be enabled.

More . . .

PHP Interview Questions and Answers Part -6

PHP Interview Questions and Answers  Part -6

PHP Interview Questions and Answers Part-6

How many ways I can redirect a PHP page?

Here are the possible ways of php page redirection.

1. Using Java script:
‘; echo ‘window.location.href=”‘.$filename.’”;’; echo ”; echo ”; echo ”; echo ”; } } redirect(‘http://maosjb.com’); ?>

2. Using php function: header(“Location:http://maosjb.com “);

List out different arguments in PHP header function?

void header ( string string [, bool replace [, int http_response_code]])

What type of headers have to be added in the mail function to attach a file?

$boundary = ‘–’ . md5( uniqid ( rand() ) );
$headers = “From: \”Me\”\n”;
$headers .= “MIME-Version: 1.0\n”;
$headers .= “Content-Type: multipart/mixed; boundary=\”$boundary\”";

More . . .

PHP Interview Questions and Answers Part-5

PHP Interview Questions and Answers  Part-5

PHP Interview Questions and Answers Part-5

How can we get second of the current time using date function?

$second = date(“s”);

What is the maximum size of a file that can be uploaded using PHP and how can we change this?

You can change maximum size of a file set upload_max_filesize variable in php.ini file

How can I make a script that can be bilingual (supports English, German)?

You can change charset variable in above line in the script to support bilanguage. More . . .

PHP Interview Questions and Answers Part-4

PHP Interview Questions and Answers  Part-4

PHP Interview Questions and Answers Part-4

What are the differences between mysql_fetch_array(), mysql_fetch_object(), mysql_fetch_row()?

Answer 1:
mysql_fetch_array() -> Fetch a result row as a combination of associative array and regular array.
mysql_fetch_object() -> Fetch a result row as an object.
mysql_fetch_row() -> Fetch a result set as a regular array().

Answer 2:
The difference between mysql_fetch_row() and mysql_fetch_array() is that the first returns the results in a numeric array ($row[0], $row[1], etc.), while the latter returns a the results an array containing both numeric and associative keys ($row['name'], $row['email'], etc.). mysql_fetch_object() returns an object ($row->name, $row->email, etc.).

If we login more than one browser windows at the same time with same user and after that we close one window, then is the session is exist to other windows or not? And if yes then why? If no then why?

Session depends on browser. If browser is closed then session is lost. The session data will be deleted after session time out. If connection is lost and you recreate connection, then session will continue in the browser. More . . .

PHP Interview Questions and Answers Part-3

PHP Interview Questions and Answers  Part-3

PHP Interview Questions and Answers Part-3

For printing out strings, there are echo, print and printf. Explain the differences.

echo is the most primitive of them, and just outputs the contents following the construct to the screen. print is also a construct (so parentheses are optional when calling it), but it returns TRUE on successful output and FALSE if it was unable to print out the string. However, you can pass multiple parameters to echo, like:

<?php echo ‘Welcome ‘, ‘to’, ‘ ‘, ‘fyicenter!’; ?>

and it will output the string “Welcome to fyicenter!” print does not take multiple parameters. It is also generally argued that echo is faster, but usually the speed advantage is negligible, and might not be there for future versions of PHP. printf is a function, not a construct, and allows such advantages as formatted output, but it’s the slowest way to print out data out of echo, print and printf. More . . .

PHP Interview Questions and Answers Part 2

PHP Interview Questions and Answers  Part 2

How can we send mail using JavaScript?

No. There is no way to send emails directly using JavaScript.

But you can use JavaScript to execute a client side email program send the email using the “mailto” code. Here is an example:

function myfunction(form)
{
tdata=document.myform.tbox1.value;
location=”mailto:mailid@domain.com?subject=…”;
return true;
}

What is the functionality of the function strstr and stristr?

strstr() returns part of a given string from the first occurrence of a given substring to the end of the string. For example: strstr(“user@example.com”,”@”) will return “@example.com”.
stristr() is idential to strstr() except that it is case insensitive. More . . .

PHP Interview Questions and Answers Part 1

PHP Interview Questions and Answers  Part 1

PHP Interview Questions and Answers Part-1

What’s PHP

The PHP Hypertext Preprocessor is a programming language that allows web developers to create dynamic content that interacts with databases. PHP is basically used for developing web based software applications.

What Is a Session?

A session is a logical object created by the PHP engine to allow you to preserve data across subsequent HTTP requests.

There is only one session object available to your PHP scripts at any time. Data saved to the session by a script can be retrieved by the same script or another script when requested from the same visitor.

Sessions are commonly used to store temporary data to allow multiple PHP pages to offer a complete functional transaction for the same visitor. More . . .

PHP pagination tutorial

PHP pagination tutorial

Use Pagination to display results of your MySQL query over multiple pages in PHP. This php pagination tutorial will help you out in sorting out problems with pagination More . . .

Sessions in PHP

Sessions in PHP

Using Sessions in PHP

Session variables hold information about one single user, and are available
to all pages in one application.

over internet to maintain state of the user we will use sessions, sessions are
temporary, by a unique id web server will keep the user data in the web server
with which user state can be maintained across the pages in the website.

before we start using the session variables  we have to start the
session with

session_start()

note:we have to start the session before the beginning of static HTML

Once we start the session then  playing with session is easy

Creating Session Variable

To create Session variable

1
2
3
$_SESSION[variablename]=value of the session variable
 
//$_SESSION['username']="supreme";

Retrieving Session Variable

To retrieve Session variable

targetvariable=$_SESSION[variable];

ex: user=$_SESSION["username"];

A sime Program usingSession (Refresh.php)

1
2
3
4
5
6
7
<?php
  session_start();
 
if (isset($_SESSION["refresh"]))
 $_SESSION["refresh"]=date("Y-m-d H:i:s A",time());
echo "You Came to this Page at : ".$_SESSION["refresh"]."<br>Now, Current  Time  is ".date("Y-m-d H:i:s A",time());
?>

paste this code as refresh.php  and refresh the page and you will come to
know the difference

Its always better to check  and  use the session variable like with
isset function we can  know weather the session variable is available or
not.If session variable exists we can start using it otherwise assaign it and
then go for it.

ex: the same way  in the above  refresh.php page

Clearing the Session variables

we can clear either single session variable or we can destroy the total
session

unlike cookies, we have unset function to  clear the session variables

1
 unset($_SESSION["session_variable_name"])

this will be used when  you want to clear one particular  session
variable

1
 unset($_SESSION["refresh"]);

to destroy current session totally

1
2
3
4
session_destroy();
 
 
//ex: session_destroy();