Insert variable into Header Location PHP

后端 未结 7 1000
北海茫月
北海茫月 2021-02-07 07:39

The question is: How do i insert the variable (echo $url_endpoint;) as a part of the link in the last line: header(\'Location: http://linkhere.com/HERE_I_WANT_THE_VARIABLE\');

相关标签:
7条回答
  • 2021-02-07 07:58
    header('Location: http://linkhere.com/' . $your_variable);
    
    0 讨论(0)
  • 2021-02-07 08:01

    like this?

    <?php
    $url_endpoint = get_permalink();
    $url_endpoint = parse_url( $url_endpoint );
    $url_endpoint = $url_endpoint['path'];
    
    header('Location: http://linkhere.com/'. $url_endpoint);
    
    ?>
    
    0 讨论(0)
  • 2021-02-07 08:14

    Try using double quotes and keeping the L in location lowercase...

    header("location: http://linkhere.com/HERE_I_WANT_THE_VARIABLE");
    

    or for example

    header("location: http://linkhere.com/$variable");
    

    No need to concatenate here to insert variables.

    0 讨论(0)
  • 2021-02-07 08:14
    <?php
    $variable1 = "foo";
    $variable2 = "bar";
    
    
    header('Location: http://linkhere.com?fieldname1=$variable1&fieldname2=$variable2&fieldname3=$variable3);
    
    ?>
    

    This works without any quotations.

    0 讨论(0)
  • 2021-02-07 08:16

    We can also use this with the $_GET method

    $employee_id = 'EMP-1234';
    
    header('Location: employee.php?id='.$employee_id);
    
    0 讨论(0)
  • 2021-02-07 08:17

    You can add it like this

    header('Location: http://linkhere.com/'.$url_endpoint);
    
    0 讨论(0)
提交回复
热议问题