Syntax error when redirecting with header

1

I try to do a redirection with header like this:

header('location:perfil.php?CodUsua=<?php echo $_SESSION['CodUsua']; ?>');

I receive the following error:

  

Parse error: syntax error, unexpected 'CodUsua' (T_STRING), expecting ',' or ')'

What would be the correct syntax?

    
asked by Carlos Bonilla 26.06.2017 в 01:37
source

1 answer

1

If you're doing header , that means you're already in PHP. You do not have to reopen <?php or write with echo . That's why you get the syntax error.

To fix it: simply concatenate the session variable to the string you already have using the operator . :

header('location:perfil.php?CodUsua=' . $_SESSION['CodUsua']);
    
answered by 26.06.2017 / 01:40
source