问题
I am not able to get this to work correctly!!
I have a view.php page that uses a variable of 'ID' to retrieve db info.
So my url is like this:
/view.php?id=23
I am trying to get it to "redirect" the user to the home page if they erase the "23" part of the url.. ?
so when you visit
/view.php?id=
It should :
if(isset($_GET['id']) == "")
{
header('Location: /');
exit; }
Works if I visit
/view.php
回答1:
Try using empty():
if(empty($_GET['id']))
{
header('Location: /');
exit;
}
回答2:
Another way:
if(strlen($_GET['id'])>0) {
header('Location: /');
exit;
}
来源:https://stackoverflow.com/questions/13848629/if-url-variable-is-empty-redirect-to-home-page