Jump to content

Recommended Posts

I have this place on code that a developer has written for me. Can some tell me what "{ }" does where the function is called?

<?php
$_GET['compID'] = base64_decode($_GET['compID']);
$_GET['fileID'] = base64_decode($_GET['fileID']);
if($_GET['hash']!==secret_hash("{$_GET['fileID']}/{$_GET['compID']}")) exit('404 file not found.');


function secret_hash($var) {
  $secret = '[LI{]+]6W>z@Qj{Stjds~+E~t\]U0~6;hb}8+)`ENhle*49;4:wx5pbwYPKM&';
  $algo = 'sha1';
  return $algo($algo($var).$secret);
}
?>

 

Link to comment
https://forums.phpfreaks.com/topic/194461-syntax-explanation/
Share on other sites

when you are using the value of one element in the array in a string (like in your example, which uses an element of the $_GET array as part of the string it passes to some function) , you can either use concatenation (something you may have seen, which looks like this:)

echo "my name is " . $array['key'] . " and I greet you!";

 

the example you gave is the other way, which is to use curly braces "{}" to put the array element directly in the string.

echo "helly my name is {$array['key']}";

 

its similar to using a regular variable straight in a string (delimited by double quotes)

echo "hello my name is $name";

 

the reason you use curly braces is because just putting the array element in a string like so

echo "hello my name is $array['key']";

is ambiguous. It can't decide whether to say the value of the array $array at the index 'key', or to say the value of a string $array with the literal string "['key']" next to it.

Link to comment
https://forums.phpfreaks.com/topic/194461-syntax-explanation/#findComment-1022832
Share on other sites

<?php
$myHash = base64_decode($_GET['fileID']);
$myHash.= base64_decode($_GET['compID']);

if($_GET['hash'] !== secret_hash($myHash)) exit('404 file not found.');


function secret_hash($var) {
  return sha1(sha1($var) . '[LI{]+]6W>z@Qj{Stjds~+E~t\]U0~6;hb}8+)`ENhle*49;4:wx5pbwYPKM&');
}
?>

sha1

base64_encode

base64_decode

 

Either your developer is trying to hide the underlying functionality of the code from you, or protect your site from malicious users.

 

From the looks of that code he is trying to protect the code from malicious users, as the code isn't too ambiguous and is really quite simple to understand and decode.

 

Link to comment
https://forums.phpfreaks.com/topic/194461-syntax-explanation/#findComment-1022853
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.