etrader Posted March 28, 2011 Share Posted March 28, 2011 I have search page in the form of search.php?q=query, as the php script calls for other files and a long process. When visiting search.php directly, the value of q is indeed null, and it makes a long loop and use lots of cpu. How to kill the script or redirect to the main page when visiting search.php? Link to comment https://forums.phpfreaks.com/topic/231917-when-q-is-empty-in-qsomething/ Share on other sites More sharing options...
Skewled Posted March 28, 2011 Share Posted March 28, 2011 Are you using IF ELSE statments or Switch/Case for your search page? If your using either, add a IF ELSE to deal with a null value for q OR add a case for a null q. Link to comment https://forums.phpfreaks.com/topic/231917-when-q-is-empty-in-qsomething/#findComment-1193138 Share on other sites More sharing options...
etrader Posted March 29, 2011 Author Share Posted March 29, 2011 Actually, I tried IF ELSE, but it was not successful, probably due to the complicated process. I hope to find a safer way to kill the process upon direct access to search.php; something like die upon direct access for mysql Link to comment https://forums.phpfreaks.com/topic/231917-when-q-is-empty-in-qsomething/#findComment-1193513 Share on other sites More sharing options...
isedeasy Posted March 29, 2011 Share Posted March 29, 2011 if ( !isset($_GET['q']) ) { //throw an error message } Link to comment https://forums.phpfreaks.com/topic/231917-when-q-is-empty-in-qsomething/#findComment-1193514 Share on other sites More sharing options...
etrader Posted March 29, 2011 Author Share Posted March 29, 2011 Thanks for this. I think my mistake was using $q instead of $_GET['q'] Link to comment https://forums.phpfreaks.com/topic/231917-when-q-is-empty-in-qsomething/#findComment-1193524 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.