Home > Software design >  Get URL Parameter with header php
Get URL Parameter with header php

Time:11-19

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.

CodePudding user response:

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");
  •  Tags:  
  • php
  • Related