Geeks Talk

Prepare for your Next Interview


Welcome to the Geeks Talk forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

File Checksums

This is a discussion on File Checksums within the PHP forums, part of the Web Development category; Hi what is exactly the purpose of sha1_file function, how the string it returns is useful ?I've tried to understand the example which has been given in the manual but ...

Go Back   Geeks Talk > Web Development > PHP
Register Blogs FAQ Tag Cloud Calendar Mark Forums Read

PHP PHP - The most popular scripting language. Discuss PHP related questions here. Sample Scripts, Popular downloads, tools and utilites and more...

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-28-2009
Junior Member
 
Join Date: Jul 2009
Location: UAE
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
saara is on a distinguished road
Question File Checksums

Hi
what is exactly the purpose of sha1_file function, how the string it returns
is useful ?I've tried to understand the example which has been given in the manual but i am unable to get through it,can anybody explain in simple words?
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-28-2009
Expert Member
 
Join Date: May 2009
Location: Bangalore
Posts: 984
Thanks: 155
Thanked 420 Times in 201 Posts
rijus is just really nicerijus is just really nicerijus is just really nicerijus is just really nicerijus is just really nice
Re: File Checksums

Hi,

Did u have an idea of US Secure Hash Algorithm 1. ?????


US Secure hash algorithm 1


The US secure hash algorithm 1: "sha-1 produces a 160-bit output called a message digest.

The message digest can then, for example, be input to a signature algorithm which generates or verifies the signature for the message.


Signing the message digest rather than the message often improves the efficiency of the process because the message digest is usually much smaller in size than the message.

The same hash algorithm must be used by the verifier of a digital signature as was used by the creator of the digital signature."

the sha1_file() function calculates the sha-1 hash of a file..

It uses the us secure hash algorithm 1.

syntax :sha1_file(file,raw)

I'll give u an example....

<?php

$sha1file = file_get_contents("sha1file.txt");

if (sha1_file("test.txt") == $sha1file)

{

echo "Hello,Welcome to geekinterview.com";

}
else
{

echo "Goodbye";
}

?>

The output of the code above could be: Hello,Welcome to geekinterview.com

I think its enough to resolve u r query, if any .... Let me know...

Thanks & Regards,

Riju.

Last edited by rijus; 07-28-2009 at 12:03 PM.
Reply With Quote
The Following User Says Thank You to rijus For This Useful Post:
  #3 (permalink)  
Old 07-31-2009
Junior Member
 
Join Date: Jul 2009
Location: UAE
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
saara is on a distinguished road
Re: File Checksums

Hi,
Thanks for you help Riju.I have some basic idea about US secure hashing Algorithm,maybe i haven't explained my querry proerly before,but still you reply was of gr8 help.
If i m not wrong, sha1_file can be used to check whether a file has been downloaded properly or not?...
below, i m quoting some simple code,the filename given as parameter, is a webpage i have downloaded and saved on my desktop.




$sha1_val1 =sha1(.../sha1_test.htm"));
$sha1_val2 =sha1_file(".../sha1_test.htm");

echo $sha1_val1."<br>";
echo $sha1_val2."<br>";


if($sha1_val1==$sha1_val2)
{
print "file contents matched<br>"; }

else
{
print "file contents did not match<br>";
}

Above code is working fine and shows that file contents match.I just want you to tell me whether i m doing correctly(logically) or not?, Is this the way we can check whether file has been downloaded correctly or is there another method.

Thanks for your help,
Regards,

Saara
Reply With Quote
  #4 (permalink)  
Old 08-01-2009
Expert Member
 
Join Date: May 2009
Location: Bangalore
Posts: 984
Thanks: 155
Thanked 420 Times in 201 Posts
rijus is just really nicerijus is just really nicerijus is just really nicerijus is just really nicerijus is just really nice
Re: File Checksums

Hi,

Yes U r correct.

It's a simple method & the the code also works fine .So it can be used to chek whether a file has been downloaded correctly or not.
Just Go a head...

If any pblm we all r here to help u out.

Regards,
Riju.
Reply With Quote
Reply

  Geeks Talk > Web Development > PHP

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
Convert dbf file to ASCII (text) file mohit1211 Oracle 2 02-17-2008 11:54 PM
Use of export xml file and import xml file options naags QTP 1 07-19-2007 02:37 PM
Steps for deploying a war file/ear file on websphere Sujatars Java 0 07-19-2007 12:49 AM
How do I 'unpack' and view a .FILE vsam file Geek_Guest MainFrame 0 06-26-2007 09:22 PM
Frigate3 File Manager: highly configurable and convenient file management environment JobHelper Geeks Lounge 0 03-30-2007 03:30 PM


All times are GMT -4. The time now is 07:48 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.3.1
Copyright © 2009 GeekInterview.com. All Rights Reserved