Friday, July 1, 2016

PHP Unlink Function

Remember from the PHP File Create lesson that we created a file named testFile.txt.

PHP Code:

$myFile = "testFile.txt";
$fh = fopen($myFile, w) or die("cant open file");
fclose($fh);

Now to delete testFile.txt we simply run a PHP script that is located in the same directory. Unlink just needs to know the name of the file to start working its destructive magic.

PHP Code:

$myFile = "testFile.txt";
unlink($myFile);

The testFile.txt should now be removed.

PHP - Unlink: Safety First!

With great power comes a slough of potential things you can mess up! When you are performing the unlink function be sure that you are deleting the right file!

Inqilab 1857 by P C Joshi

Inqilab 1857 by P C Joshi

Inqilab 1857 history book
       Urdu history PDF copy book  involving  "Inqilab 1857"  through  P C Joshi.Publish  via  peoples publishing house memories  for   following   complete  100 hundred years.  a complete  Discussing  about   an  old historical struggle  with  India .  


Generating excel xls files

Here we generate excel files from php script. To begin we will need some main excel classes as following:
1. BIFFwriter.php (for writing BIFF (binary file format)
2. Format.php (for generating excel XF records)
3. OLEwriter.php (OLE stream for spreadsheet)
4. Parser.php (for parsing excel formula)
5. Workbook.php (for generating excel workbook)
6. Worksheet.php (for generating excel worksheet)

You may want to see some examples in which you can download with all the six files above. You can download them all here (48kb) !!.

There are also five example files included:
1. example1.php (creating first example in generating excel document and comments are also included)
2. example2.php (set and modify fonts and styles)
3. example3.php (set columns and rows)
4. example4.php (set page)
5. example5.php (apply formula)

Link Manager Software

LinkMan link manager software will completely automate your link exchange! Here is how your reciprocal link exchange will work with LinkMan:

  • Webmaster John is interested in exchanging links with your site,
  • He ads a link to your website on his links page (or any other page on his website),
  • He submits the "Add a link" form on your site,
  • LinkMan verifies that a reciprocal link to your site has indeed been added,
  • A few more automated checks to verify everything is OK and the new link automatically appears on your links page!

Its that simple! In the LinkMan admin manager panel you have a special tool that will crawl all URLs where your reciprocal link should be. If a reciprocal link isnt found LinkMan will automatically remove the missing link from your links page.

LinkMan doesnt need a SQL database to operate, it works with simple text files. You can also easily edit header and footer of the links page so it will completely fit into the rest of your website!

LinkMan is rich with features:

  • automate your link exchange,
  • administration panel for easy control,
  • choose to manually approve and reject links,
  • mark links as featured,
  • display website thumbnails,
  • display Google PageRank,
  • block websites with too low PageRank,
  • block links with rel="nofollow" link attribute,
  • block links from pages with the meta robots noindex or nofollow tags,
  • powerful SPAM filter,
  • block superlatives from titles and descriptions,
  • block duplicate website submissions,
  • ban websites,
  • ... and much more!,

Download Link Manager Software

PHP Interview Questions Part 1

Common PHP Interview Questions

1. What is CAPTCHA?

CAPTCHA stands for Completely Automated Public Turing Test to tell Computers and Humans Apart. To prevent spammers from using bots to automatically fill out forms, CAPTCHA programmers will generate an image containing distorted images of a string of numbers and letters. Computers cannot determine what the numbers and letters are from the image but humans have great pattern recognition abilities and will be able to fairly accurately determine the string of numbers and letters. By entering the numbers and letters from the image in the validation field, the application can be fairly assured that there is a human client using it. To read more look here:
http://en.wikipedia.org/wiki/Captcha


2. What is difference between require_once(), require(), include().

Difference between require() and require_once(): require() includes and evaluates a specific file, while require_once() does that only if it has not been included before (on the same page). So, require_once() is recommended to use when you want to include a file where you have a lot of functions for example. This way you make sure you dont include the file more times and you will not get the "function re-declared" error. Difference between require() and include() is that require() produces a FATAL ERROR if the file you want to include is not found, while include() only produces a WARNING. There is also include_once() which is the same as include(), but the difference between them is the same as the difference between require() and require_once().


3. If you have to work with dates in the following format: "Tuesday, February 14, 2006 @ 10:39 am", how can you convert them to another format, that is easier to use?

The strtotime function can convert a string to a timestamp. A timestamp can be converted to date format. So it is best to store the dates as timestamp in the database, and just output them in the format you like.

So lets say we have
$date = "Tuesday, February 14, 2006 @ 10:39 am";
In order to convert that to a timestamp, we need to get rid of the "@" sign, and we can use the remaining string as a parameter for the strtotime function.

So we have
$date = str_replace("@ ","",$date);
$date = strtotime($date);

now $date is a timestamp
and we can say:

echo date("d M Y",$date);


4. How we know browser properties?

get_browser() attempts to determine the capabilities of the users browser. This is done by looking up the browsers information in the browscap.ini file.

echo $_SERVER[HTTP_USER_AGENT] . " ";

$browser = get_browser();

foreach ($browser as $name => $value) {
echo "$name $value
";
}


5. How i will check that user is, logged in or not. i want to make it a function and i want to use in each page and after login i want to go in current page(same page. where i was working)?

For this we can use the session objec($_SESSION)t. When the user login with his/ her user name and password, usually we check those to ensure for correctness. If that user name and password are valid one then we can store that user name in a session and then we can very that session variable has been set or not in a single files and we can include that file in all pages.

6. How i can get IP address?

We can use SERVER var $_SERVER[SERVER_ADDR] and getenv("REMOTE_ADDR") functions to get the IP address.

7. What is differenc between mysql_connect and mysql_pconnec?

mysql_pconnect establishes a persistent connection. If you dont need one (such as a website that is mostly HTML files or PHP files that dont call the db) then you dont need to use it. mysql_connect establishes a connection for the duration of the script that access the db. Once the script has finished executing it closes the connection. The only time you need to close the connection manually is if you jump out of the script for any reason.

If you do use mysql_pconnect. You only need to call it once for the session. Thats the beauty of it. It will hold open a connection to the db that you can use over and over again simply by calling the resource ID whenever you need to interact with the db.

8. What is the difference between echo and print statement?

There is a slight difference between print and echo which would depend on how you want to use the outcome. Using the print method can return a true/false value. This may be helpful during a script execution of some sort. Echo does not return a value, but has been considered as a faster executed command. All this can get into a rather complicated discussion, so for now, you can just use whichever one you prefer.

9. How to make a download page in own site, which i can know that how many file has been loaded by particular user or particular IP address?

We can use hyperlink having URL where file are kept. and we only allow registered user to download. from session of user we can get the user detail