using variables in a header(location: 'url?value=$value)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pedalpete
    New Member
    • Oct 2007
    • 109

    using variables in a header(location: 'url?value=$value)

    I thought this should be simple, but i can't seem to get it to work.

    I'm trying to do a simple redirect to a page, but need to pass a variable.
    I've tried a few things, but nothing seems to work.

    here's what I've tried

    Code:
    		header('Location: edit.php?sid=$sid');
    // or
    $url = "edit.php?sid=$sid";
                  	header('Location: $url');
    
    // or
    		header('Location: edit.php?sid=\$sid');
    and a bunch of other random attempts. but whenever i use a variable, i get an error eg. the page localhost/$url cannot be found.

    So that lets me know that the variable is not being filled.
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    [php]
    $url = "edit.php?sid=$ sid";
    header("Locatio n: ".$url);
    [/php]

    Does that work?

    Comment

    • pedalpete
      New Member
      • Oct 2007
      • 109

      #3
      of course that works...

      i had tried all sorts of quotes and dashes, but kept getting errors.

      Thanks

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        Originally posted by pedalpete
        of course that works...

        i had tried all sorts of quotes and dashes, but kept getting errors.

        Thanks
        Was that sarcasm or does it actually work?

        =\

        Comment

        • mwasif
          Recognized Expert Contributor
          • Jul 2006
          • 802

          #5
          Originally posted by pedalpete
          Code:
          header('Location: edit.php?sid=$sid');
          // or
          $url = "edit.php?sid=$sid";
                        	header('Location: $url');
          
          // or
          		header('Location: edit.php?sid=\$sid');
          When a string is specified in double quotes, variables are parsed within it. But this is not the case with single quotes.

          Comment

          • honoursiter
            New Member
            • Feb 2008
            • 1

            #6
            Please help!

            Originally posted by markusn00b
            [php]
            $url = "edit.php?sid=$ sid";
            header("Locatio n: ".$url);
            [/php]

            Does that work?



            Yes this is working fine... I was searching for this

            PLEASE TELL ME!!
            How do I use content-dispostion with variables instead of location??
            The above codings are showing location with variable..
            I would like to know the usage of content-disposition with a variable instead of this location
            Last edited by honoursiter; Feb 12 '08, 10:18 AM. Reason: Adding question

            Comment

            • Markus
              Recognized Expert Expert
              • Jun 2007
              • 6092

              #7
              Just use the same logic.. keep the variables in double quotes.
              [php]
              <?php
              /** Define Variables **/
              $_Download = "somefile.j pg";
              $_Download_Type = "image/jpeg";

              /** Set first header: Type. **/
              header("Content-type: " . $_Download_Type );

              /** Second header: Filname. **/
              header("Content-Disposition: attachment; filename='".$_D ownload."');

              ?>
              [/php]
              Hope this helps

              Comment

              • pedalpete
                New Member
                • Oct 2007
                • 109

                #8
                Originally posted by markusn00b
                Was that sarcasm or does it actually work?

                =\
                sorry markus, that was not sarcasm, it actually did work, I was just making fun of myself.

                Comment

                • Markus
                  Recognized Expert Expert
                  • Jun 2007
                  • 6092

                  #9
                  Originally posted by pedalpete
                  sorry markus, that was not sarcasm, it actually did work, I was just making fun of myself.
                  Aha!
                  Nice to know :P

                  Happy php'ing!

                  Comment

                  Working...