1

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

  • I have a page with url www.foo[.]com/mypage

  • I only want that page or url to be accessible if it comes with ?user=$email so if someone tries to visit the url without ?user=$email, they get redirected somewhere else.

  • How do I define that condition?

2
  • 1
    What have you tried so far? Commented Dec 10, 2019 at 4:40
  • 1
    I've tried using the following - if (!$_SERVER['REQUEST_METHOD'] === 'GET') and $user = $_GET['user']; if ($user == '') // if $user as a string is empty Commented Dec 10, 2019 at 4:45

3 Answers 3

1

Try this script !!!

if(!isset($_GET['user'])){
 header("location:./");
}
elseif(isset($_GET['user']) && $_GET['user']==''){
 header("location:./");
}
Sign up to request clarification or add additional context in comments.

Comments

0

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");
    }
?>

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.