1

I want to redirect the user to homepage if he tries to access the "example.com/site" without variable "example.com/site?website=" but if the variable is passed then it should show the desired page. Note: i am getting the "website" variable on another page from a url.

Aamir
  • 11
  • 2
  • use`if(empty($_GET['website']) ||($_GET['website'] == $row['site_title']) ) {` instead of `if(empty($_GET['website'])) {` as per your condition – M A SIDDIQUI Feb 08 '17 at 06:46
  • 1
    And what is the problem? – u_mulder Feb 08 '17 at 06:47
  • In case the redirect itself is not working, please take a look here, and make sure you have proper spaces in header(). http://stackoverflow.com/questions/7467330/php-headerlocation-force-url-change-in-address-bar – besciualex Feb 08 '17 at 06:48
  • problem is i don't want the user to directly access the example.com/site page without variable "website". – Aamir Feb 08 '17 at 06:50
  • @u_mulder the problem is i don't want user to access the page "example.com/site" directly without variable like this "example.com/site?website=sdffsd" ...Help? – Aamir Feb 08 '17 at 06:59
  • You show us code. Is it working? Or is it not? What is the problem with the code you showed? – u_mulder Feb 08 '17 at 07:00
  • its not working .. the page is still accessed directly. – Aamir Feb 08 '17 at 07:02

1 Answers1

0
if(isset($_GET['website'])) { 
    if($_GET['website'] !== $row['site_title']) {
        header('Location:websites');
      }
} else {
   header('Location:index');
}

Above will work, if website is set and your condition satisfy it will redirect to websites else it will always redirect to index page

I hope it will help.

Naincy
  • 2,953
  • 1
  • 12
  • 21
  • Forget the code. I don't want the user to access page "example.com/site" directly. – Aamir Feb 08 '17 at 07:05
  • then use the session concept to allow or not allow based on logged in user or may be role assigned to them. – Naincy Feb 08 '17 at 07:13