sha() - how to access this function?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
phummon
Forum Newbie
Posts: 3
Joined: Wed Jul 21, 2010 2:47 pm

sha() - how to access this function?

Post by phummon »

Hi everyone,

Full disclosure: I'm an experienced programming who is relatively new to PHP. Unfortunately, I'm also in a bit of a jam. In short, my boss gave me some PHP code and said, "You have to get this working by Friday." I don't have the luxury to do the proper tutorials, otherwise I wouldn't be rushing to this forum in a bit of a panic.

Here's the problem. The code I'm working with has this line:

Code: Select all

$variable1 = sha1("12345678".$user.$passwd);
When I execute, the compiler gives me this result...

Code: Select all

<br>
<b>Fatal error</b>:  Call to undefined function:  sha1() in <b>/export/qhome/dude1/script1.php</b> on line <b>38</b><br>
...which I'm interpreting to mean "I don't know what this sha() command is!" If this were C++ code (my home turf), I'd just "man sha," figure out which library I need to add, and then pop in the needed "#include ______" statement at the top of my code. That didn't work for in this case.

Does anyone have any insight?

Many, many thanks in advance!
-P
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: sha() - how to access this function?

Post by Jonah Bron »

You might be using an older version of PHP. Do you know what version you're using?
phummon wrote:...the compiler gives me this result...
BTW, PHP uses an interpreter, not a compiler.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: sha() - how to access this function?

Post by Weirdan »

sha1() is a part of standard extension:

Code: Select all

weirdan@virtual-debian: /home/sam/weather$ php --rf sha1
Function [ <internal:standard> function sha1 ] {
  - Parameters [2] {
    Parameter #0 [ <required> $str ]
    Parameter #1 [ <optional> $raw_output ]
  }
}
However, it's available only since php 4.3.0:
sha1 manual page wrote: sha1
(PHP 4 >= 4.3.0, PHP 5)
If you have such ancient php you need to upgrade it first.
phummon
Forum Newbie
Posts: 3
Joined: Wed Jul 21, 2010 2:47 pm

Re: sha() - how to access this function?

Post by phummon »

Sorry, no idea which version of PHP I'm using. I guess its an old one!

I take it sha1() should be a standard function in today's PHP compi- er, interpreters?

Many thanks!
-P
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: sha() - how to access this function?

Post by Weirdan »

phummon wrote:Sorry, no idea which version of PHP I'm using. I guess its an old one!
php -v would tell you

Code: Select all

weirdan@virtual-debian: /home/sam/weather$ php -v
PHP 5.3.2-1 with Suhosin-Patch (cli) (built: Mar 13 2010 22:18:25)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
    with Xdebug v2.1.0, Copyright (c) 2002-2010, by Derick Rethans
    with Suhosin v0.9.31, Copyright (c) 2007-2010, by SektionEins GmbH
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: sha() - how to access this function?

Post by Benjamin »

:arrow: Moved to PHP - Code
phummon
Forum Newbie
Posts: 3
Joined: Wed Jul 21, 2010 2:47 pm

Re: sha() - how to access this function?

Post by phummon »

I see from phpinfo() that I'm running version PHP Version 4.0.3pl1. That sounds pretty ancient. :?

I think this pretty much answers my question. Many thanks to all who chipped in to help! :D

-P
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: sha() - how to access this function?

Post by Weirdan »

phummon wrote: That sounds pretty ancient. :?
Yeah, almost 10 years old:
PHP Changelog wrote: 4.0.3
Released: 11 October 2000
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: sha() - how to access this function?

Post by Jonah Bron »

Older than this forum 8O
Post Reply