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

Fri, 19 Mar 2010 5:25:38 PM +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 . . .

Trimming Completely using PHP Regular expressions

Trimming  Completely using PHP Regular expressions

Hello Friends,

Is your  Trimming method  is taking care for  special characters ?  you might be using  some trimming for some of the special characters but what about the rest ? for you  here is a  simple  Function which will trim  the string  entirely  and  results only the pure string

function pureTrim($input)
{
        // This allows Only   Alphabets Numerals  and Space
	$output = preg_replace("/[^a-z0-9\s]/i", " ", $input);
	$output= trim($output);
	return $output;
 
}

So, try using this function your code . Hope this will help you

Calculate Page Execution time in PHP

Calculate Page Execution time in PHP

For those people who want to give users that in how many seconds actually your web page loaded completely. This script will be useful for you. There are so many ways to do this ( As usual ) but the classic approach would be

Step 1 : make a note of  the time when your page get starts

Step 2: make a note of  the time  at the end of your total page execution

Step 3 : step 2 – step1, You will get your page execution time

In simple   Here is the function  which will do it for you .

You have  to   call the function at the  start  and   echo  it  at the  end.   simple !!!!

More . . .

Text Area Values into Array in PHP

Text Area Values into  Array in PHP

If you  want  to split up  the total text area content  into  array  based on the  row ,  Here is simple solution  to convert  textarea  field  value into  array in PHP.

$total=$_POST["textarea"]
 
$keyarr=explode("\n",$total);
// In order to  process this  array  values  here is the code 
 
foreach($keyarr  as  $key=>$value)
{
   //  becareful to check the value for  empty line 
   $value=trim($value);
   if  (!empty($value))
   {
        // Carry out your  own operations 
   }
}

How to Upgrade Your Server PHP Version to latest stable PHP Version using WHM

How to Upgrade Your Server PHP Version to latest stable PHP Version using WHM

To Upgrade the PHP Version of your server, there is no need to contact Tech Support and raise a Ticket which is billable :(

You yourself  can Upgrade your server’s PHP Version to latest PHP Version  if you have access to WHM i.e Web Host Manager

Let’s see How  you can do this your own.

Step 1:  Login to WHM

Step  2:  Look for  Easy Apache  or  Apache Update   Under Software  Section  of  WHM  and  Click on that

Step 3:  Now,  Choose the Profile  which you want to  Customize  or  Rebuild  Totally  , i  prefer  Customizing the default  one  so, Click on Start  Customizing the Profile

Step 3 :  Choose the Apache  Version  Click  Next

Step 4 :  Choose  the PHP  Major  Version  presently  5

Step 5 : Choose the PHP  Minor  Version   presently  Latest stable  release is 5.2.9

Step 6 :  Save  and  Build  Now

Once You say  Build  it will take  min of 15 to 30 min  depending on  the Modules you have selected to update  ,  So be patient  till You see  Build Complete

Once after completing ,  carefully follow  the screen instructions  to save the new config.

!!Congratulations!! you are done.

Apache is Updated , Now go back to your website and create a info.php  page  and paste the following code

<?php

phpinfo()

?>

You will see your PHP  Version Upgraded to the latest version what you have selected ..

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 . . .