You can lock the screen rotation on the iPhone 3GS and 4, running iOS 4 and up , to portrait only by double pressing the Home button (bringing up the task switcher), swiping right to show the media controls and pressing the left most icon (looks like a refresh button), the rotation lock. When locked you will see a padlock in the icon and a new status bar icon.
If your iPhone is jailbreaked, sbSettings has a handy shortcut to dis/-enable rotate whenever you want