SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2001
    Location
    London, UK
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How do I automatically pass POST variables?

    Hi,

    I'm looking to forward any variables passed to my script onto another script in a header.

    e.g.

    Code:
    header("Location:http://www.domain.com/index.php?name1=$value1");
    The problem is that I wont know the names or values of the variables being posted to my script.

    Is there a way to get the variable names and values from $_POST and add them to the header URL?

    Remember that I will also not know the number of variables being posted and therefore maybe a loop will be needed.


    Thanks for any help,


    Rob


  2. #2
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $string "?";
    foreach (
    $_POST AS $key=>$value)
    {
    $string .= $key."=".$value;
    }
    header("Location: index.php".$string); 
    Should do it.

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2001
    Location
    London, UK
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, I'll give it a go

  4. #4
    No. Phil.Roberts's Avatar
    Join Date
    May 2001
    Location
    Nottingham, UK
    Posts
    1,142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That won't work, becuase you're passing the variables as a GET request.

    I don't think there is any simple way to do what you're asking.

    Unless of course, you don't mind this.


Bookmarks

Posting Permissions

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