How to display a flash message in a template
You can use the setFlash function in the userSession Service like this:

In your Controller:

craft()-&gt;userSession-&gt;setFlash('yourVariable', "Something happened yo!");


In your template (that the user gets redirected to):

{% set message = craft.session.getFlash('yourVariable') %}


After that just run an if-statement to see if the message is set or not.

EDIT:
In Craft 3 controller:

Craft::$app-&gt;session-&gt;setFlash('yourVariable', "Something happened yo!");


In template:

{% set message = craft.app.session.getFlash('yourVariable') %}
{% if message|length &gt; 0 %}
    {{message}}
{% endif %}