How do I hurt enemies by jumping on them without getting killed?

I have half of the code already written. I am just not sure if the player will get hurt since I have the enemies hurt my player through collisions.

The code here is for the enemy. If i switch this code around will the program allow the player to attack the enemy without getting hurt? or will they both get hurt?

void OnCollisionEnter2D(Collision2D frog)
    {
        if (frog.gameObject == PTarget)
        {
            playerRange = true;
        }
    }

    void OnCollisionExit2D(Collision2D frog)
    {
        if (frog.gameObject == PTarget)
        {
            playerRange = false;
        }
    }

    // Update is called once per frame
    void Update()
    {
        attackTime();
    }


    void attack()
    {
        timer = 0f;

        if (PlayerHealth.currentHealth > 0)
        {
            PlayerHealth.TakenDmg(amount);
        }
    }

There should be either 4 colliders on each side, or raycasting from 8 points.
Left/right/top collider corresponds for you being hurt, bottom one - kick enemies.
Top collider also checks if you’re hitting a ceiling.
Same for raycasting, just each raycast should be out of imaginary colliders boundaries.