Edwin Lowe
Edwin Lowe

Reputation: 13

PHP - Allow Access to Page Only If Variable Exists in Url

I'm sorry I couldn't come up with a more fitting title but here is what hope to achieve with PHP:

Upvotes: 1

Views: 221

Answers (3)

ChandraShekar
ChandraShekar

Reputation: 386

Hi @Edwin here is the solution for you question.

<?php
    if(!isset($_GET['user']) && $_GET['user']!='' && $_GET['user']!=null) {
        header("Location: http://www.foo[.]com");
    } else {
        header("Location: http://www.foo[.]com/somepage");
    }
?>

Upvotes: 0

slab-dev
slab-dev

Reputation: 11

In your mypage Page at TOP(Very First line) just write following code

<?php
   if(!isset($_GET['user']) || (isset($_GET['user']) && $_GET['user'] == "") ){
       header("Location: http://www.foo[.]com");
   }
?>

Here I not only check if $_GET['user'] is available or not, I also check that there mus be some value pass to. Here you also no need to write else{} to continue.

Upvotes: 0

dhamo
dhamo

Reputation: 555

Try this script !!!

if(!isset($_GET['user'])){
 header("location:./");
}
elseif(isset($_GET['user']) && $_GET['user']==''){
 header("location:./");
}

Upvotes: 1

Related Questions