My URL is Example.com/gas.php?cid=1 and this URL is opening fine and now a URL which is Example.com/gas.php?cid=123(which actually doesnt exists) but this URL is able to open but a blank page (not even 404 error as gas.php exists) and I want to redirect this page and others where there is no information to main page i.e. Example.com/gas.php
The first part of your PHP script should examine the requested parameters and if they are completely invalid (e.g. ?cid=1h34f3) return a 404 status code and include the 404 page code and content.
The next part of the PHP code should examine plausible parameter values (e.g. ?cid=12345) and check in the database to see if this value exists. If it does not, return a 404 status code and include the 404 page code and content.
If the parameter value is OK and is found in the database then serve the content for that id.
Do NOT redirect non-valid values. Your site will be flagged as having "soft 404 errors". You do NOT want this.
If your code begins with the !DOCTYPE then you will have to refactor your code. The PHP script should interact with the database first and the !DOCTYPE should be at least half way through the script.