www.webdeveloper.com
Results 1 to 3 of 3

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

  1. #1
    Join Date
    Oct 2013
    Posts
    28

    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:
    galleries.php?id=320&folder=rass 
    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:
    <?=$array["folder"]?>
    If I in the HTML codes make a link like:
    PHP Code:
    galleries.php?folder=<?=$array["folder"]?>
    Then it’s working and calls the variable “folder”

    Any suggestions how to do this?

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

  3. #3
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,227
    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 '';
        if(!empty(
    $_GET['folder']) { 
            
    $queryString "?folder=".urlencode(basename($_GET['folder']));
        }
        
    header("Location: http://www.example.com/galleries.php".$queryString);
    }
    else {
        
    error_log("Headers already sent!");

    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

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



Recent Articles