/    Sign up×
Community /Pin to ProfileBookmark

Why sha1_file() Shows NULL ?

Folks,

Why my following code echoes NULL as vardump() ?

[code]
$_SESSiON[‘search_id’] = $search_id = sha1_file(“Register_Template_1.php”);
var_dump($_SESSION[‘search_id’]);
exit();
[/code]

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@NogDogMar 07.2021 — Maybe check your php error log or turn on error reporting and find out what went wrong (like maybe it can't find that file or does not have read permission?).
Copy linkTweet thisAlerts:
@developer_webauthorMar 08.2021 — @NogDog#1629008

Error reporting is on. I get no error.

File can be found. Here is the proof:

<i>
</i>$_SESSiON['search_id'] = $search_id = sha1_file("Register_Template_1.php");
var_dump($search_id);


The above code shows hash of the file.

However, below code outputs: NULL.

<i>
</i>$_SESSiON['search_id'] = $search_id = sha1_file("Register_Template_1.php");
var_dump($_SESSION['search_id']);


I am puzzled NogDog!
Copy linkTweet thisAlerts:
@NogDogMar 08.2021 — Check your 2 different spellings of $_SESSION and $_SESSiON.
Copy linkTweet thisAlerts:
@developer_webauthorMar 08.2021 — @NogDog#1629046

Ha! Ha! Ha!

If I got the Global Var spelt wrong then why didn't PHP tell me undefined Global Var ?
Copy linkTweet thisAlerts:
@NogDogMar 09.2021 — > @developer_web#1629047 If I got the Global Var spelt wrong then why didn't PHP tell me undefined Global Var ?

Because there's nothing stopping you from making a local variable that looks a lot like a super-global variable. There is nothing special syntax-wise about using $_ to start a variable. Rather, it's a case that PHP has several special variables that start that way to make it less likely you will accidentally use the same name for other variables. In fact, if you unset() a super-global then try to set it again, it's no longer super-global.
<i>
</i>function test() {
echo $_SERVER['LANG'];
}

test();
// outputs "en_US.UTF-8" for my computer

unset($_SEVER);
test();
// outputs an "Undefined variable: _SERVER" error

$_SERVER['LANG'] = 'whatever';
test()
// still outputs an "Undefined variable: _SERVER" error
×

Success!

Help @developer_web spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...