-1

I have an Login Form which is linked to login.php. In there, if the password is wrong I have this:

$msg = 'Password is wrong!';
header('Location: /index.php?msg='.$msg);

And this is processed by the index.php file:

if(isset($_REQUEST['msg'])){
    $msg = $_REQUEST['msg'];
    echo($msg);
}

When I use the url in the browser eg. index.php?msg=test it works completly fine but when I use the form, it only redirects to Site Root eg. site.com without the index.php?msg=test.

I hope my problem is clear.

Thanks in advance.

BvstedCrew
  • 47
  • 4

1 Answers1

1

I think the problem is because you are using single quote ('') instead of double quotes ("") inside your header() function...try change to this

header("Location: /index.php?msg=$msg");

Note: if login.php and index.php are in the same directory folder then you dont need the '/' which should be

header("Location: index.php?msg=$msg");
Dharman
  • 30,962
  • 25
  • 85
  • 135
  • This is actually the exact same string. BTW: I would suggest to use `{}` in strings. `?msg={$msg}`. Ppl will then know what to do as soon they want to add array or object values into strings. – cottton Nov 19 '21 at 02:48