0

I have a login page that submits to another page while adding a string to the end of the url. Would look something like this 'http://example.com?klc' I know I can use $_SERVER["QUERY_STRING"] to get the string, but now I need to use it in a function to direct the user to a different page, based on the string. This is what I have written in the target file

<?php

$access = $_SERVER["QUERY_STRING"];

function user_admin_redirect($access){
    if ($access = "ppl"){
        redirect_to("ppl_admin.html");}
    else ($access = "klc"){
        redirect_to("klc_admin.html");}
    }
}

user_admin_redirect($access); 

but for some reason the script dies. Any tips would be welcomed. Also, I have the system setup on my website, contact me if you are willing to help I can give you a test login.

mim.
  • 669
  • 9
  • 18
Rjoel
  • 66
  • 1
  • 10

2 Answers2

0

I don't think redirect_to is a built-in PHP function.

You might need to use

header("Location:".$myPhpScript);

or you could define redirect_to, like:

function redirect_to($location){
    header("Location:".$location);
}

See more here:

php redirect_to() function undefined

How to make a redirect in PHP?

Kyrre
  • 670
  • 1
  • 5
  • 19
0
$access = $_SERVER["QUERY_STRING"];

function user_admin_redirect($access){
    if ($access == "ppl"){
        redirect_to("ppl_admin.html");}
    else if($access == "klc"){
        redirect_to("klc_admin.html");}
    }
}

user_admin_redirect($access); 
  1. You need to use == and not = when using if

  2. You need to use else if and not just else

  3. I am assuming redirect_to is some custom function that you have written which will redirect you to the mentioned page. If not, you should use header('Location: ' . $location);
Milan Chheda
  • 8,159
  • 3
  • 20
  • 35