I recently found out many people in certain countries no matter what kinds of devices they're using, have issues with WiFi when SIM-Card is inserted.
I realized that changing the WiFi Country Code solves the problem and made an application that does this automatically on each boot and on network state changes.
You can download it and follow the updates here.
You can also download and install WiFix Manager from Google Play (Make sure to rate the application.)
It's pretty easy; first of all you should root your device.
Then install WiFixManager.apk.
Start WiFix Manager from applications menu and tap Install WiFix (allow SuperUser permission.)
Once installed, you're ready to go. The application will change the country code when needed. You can also invoke it manually by dialing *#94349# (*#WIFIX#) and pressing the call button (don't forget to press call button; it's not a MSL code).
You can check for updates and install them via WiFix Manager.
Change Log: 1/14/12 WiFix V1.0, WiFix Manager V1.1: Initial Release 1/25/12 WiFix 1.1, WiFix Manager V1.2: Changed minimum SDK version and API Level to 3 Minor layout changes Minor bug fixes 1/30/12 WiFix 1.2, WiFix Manager V1.3: Added custom country code support 7/3/12 WiFix V1.2, WiFix Manager V1.31: Minor layout bug fixes Compiled with Android SDK 14 12/9/12 WiFix V1.2, WiFix Manager V1.32 Minor bug fixes (Device compatibility improvement.) Added reboot prompt after installation and removal. Compiled with Android SDK 16
Sometimes when you reboot your phone with WiFi turned on, you won't have internet access (you can't open webpages, download files etc.) even though it says it's already connected to your AP.
This issue can be fixed by turning WiFi Off and On or dialing *#WIFIX# as described before.
For ROM Cookers
By placing WiFix.apk in /system/app you'll have a WiFix enabled ROM.
If you're publishing that ROM, please include a link to this thread
Newer fix by XDA Member HTCZ715E
As of today, most of the manufacturers (including HTC and Sony) solved this Wi-Fi issue with their ROMs. Fortunately, there's no need for WiFix anymore.
For those who still have issues with custom ROMs and WiFix, try this.