Consider PlayerDir as a vector pointing in direction the player looks and EnemyDir is the direction in which an enemy moves.
Using following calculation :
(PlayerDir.x * EnemyDir.x + PlayerDir.y * EnemyDir.y);
you get the value of cosine between their directions. Importantly, make sure that PlayerDir and EnemyDir are normalized! Otherwise you have to divide your result by length of both vectors!
If result was positive it means, that player and enemy moved in the same direction, so the player was hit in the back. If negative than, they moved in opposite directions. If you get value really close to 0, it means the player was hit from the side.