First, always get a contract in writing. Second, do not agree to contracts with unfavorable terms.
Even following the advice above, there are times when photographers end up getting a raw deal. This is most likely to occur when there is a power imbalance between the publisher/buyer/employer and the photographer. That imbalance is often exacerbated by the modern proliferation of digital cameras and the willingness of many amateurs to provide photos at low cost or for free.
As in other conflicts between labor and capital, individual workers have little power, and collective action is often necessary. Photographers have also benefited by going public with particularly egregious contract terms, shaming the powerful in the press and social media, thus prompting changes favorable to photographers.
Photographers have more power when they work together on common issues. Here are a few professional associations for photographers: