Results 1 to 3 of 3

Thread: How to use a variable in the “header Location” link?

  1. #1
    Join Date
    Oct 2013

    How to use a variable in the “header Location” link?

    I need to have a variable in my "header / Location" link. It should get the info from the link:
    PHP Code:
    I have treid this:
    PHP Code:
    header("Location: galleries.php?folder=".$_ARRAY["folder"]."");
    header("Location: galleries.php?folder=".$_GET["folder"]."");
    header("Location: galleries.php?folder="<?=$array["folder"]?>");
    header("Location: galleries.php?folder=".$array["folder"]);
    header("Location: galleries.php?folder=$array['folder']");
    But nothing Works. I need to use the below create the correct link:
    PHP Code:
    If I in the HTML codes make a link like:
    PHP Code:
    Then it’s working and calls the variable “folder”

    Any suggestions how to do this?

  2. #2
    Join Date
    Jul 2013
    Voorheesville NY USA
    Is there an array called $array? Do you have error checking turned on?

  3. #3
    Join Date
    Aug 2004
    Also make sure no output (not even white-space) has been sent by your PHP script before you call header(). Also, to be HTTP 1.1 compliant, you should use full URLs (including the "http://domain/" part). Lastly, you should probably urlencode the folder value, and it wouldn't be a bad idea to sanitize it a bit, maybe something like:
    PHP Code:
    if(!headers_sent()) {
    $queryString '';
    $_GET['folder']) { 
    $queryString "?folder=".urlencode(basename($_GET['folder']));
    header("Location: http://www.example.com/galleries.php".$queryString);
    else {
    error_log("Headers already sent!");

    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center