How can I install a curtain rod so that it doesn't slide on the mounting brackets when opening and closing the curtains?
Typically curtain rod brackets will have a Set Screw, which is used to prevent the rod from moving.

If your bracket does not have a set screw, check to see if there is a hole where one should be.

If you have a hole but no screw, you'll have to find a screw that will fit in the hole.  Make sure it's a Machine Screw with a flat end (not pointy), so it will work properly. Finding the proper size screw might be a bit of a challenge, so it's probably a good idea to take the bracket with you to the hardware store.
If you don't have a hole for a set screw; or any other mechanism to prevent the rod from moving, you might be able to add your own.  Doing so will require a drill motor, the proper drill bit, a center punch (if the bracket is metal),and a tap.