can i send variables to the next file assigning them like this:

$_POST["var"]="xpto";

and then in the other file:

$var=$_POST["var"];

?

if not wich method should i use?

i gess could send it through the session but that variable will only be necessary once.

thx in advance

    Construct the POST request:

    $req='var=xpto&var=somevalue';


    Send the POST request to the server:

    $fp = fsockopen ('testserver.com', 80, $errno, $errstr, 30);
    $header = "POST /test.php HTTP/1.0\r\n";
    $header.= "Host yourserver.com\r\n";
    $header.= "Content-Type: application/x-www-form-urlencoded\r\n";
    $header.= "Content-Length: ".strlen($req)."\r\n\r\n";
    fputs ($fp, $header.$req);
    fclose($fp);
    

    Alternatively you can use libcurl for this.

      that look pretty complex...

      didnt understand it 🙁

      any simpler way out there?

        Why don't you want it to be in a form? Remember that a form doesn't have to have any fields if you don't want. You can make a form that looks like an image like this:
        <form action="blah" method=post>
        <input type=hidden name="foo" value="bar">
        <input type=image src="images/pic.gif">
        </form>

        And that way, it doesn't look like a form... but it passes values to the next page as a post instead of get which is what you're looking for, I think.

          mmm...

          ok... i have a form with multiple fields... but i want to pass some fields not be visible.
          can i like... put an input in a form that is not visible at all?

            Yes. Use the hidden tag. (This is more of an HTML question than a PHP question which is why the previous answers were confusing to you).

            <form action="blah" method=post>
            What is your name: <input type=text name="first_name><br>
            <input type=hidden name="web_page_source" value="The Contact Us Page">
            <input type=submit value="Continue">
            </form>

            Notice in the example above that the variable "web_page_source" will be POSTED to the next page but the user can't see it.

              yep thats true... it turned out to be more of an html question.

              what confused me in the previous post was the fact of this code:

              <form action="blah" method=post>
              <input type=hidden name="foo" value="bar">
              <input type=image src="images/pic.gif">
              </form>

              not having a submit and the input with an image not having any name or value

                it turned out to be more of an html question.

                Yeah... Its probably easiest to be fairly efficient in html before you try and create it with php.

                  If you're sending data from the client to the page, then onto a second page, then yeah, use hidden form fields.

                  Another method you might look into is using a [man]session[/man].

                  You could even send data from one script to another across a page load by the query string, i.e.

                  header('Location: script2.php?var=xpto');

                    mmm

                    thenks for the help guys, i think i'll use the session, it sounds like the most secure method.

                    i will unset the session variable right after i use it

                      Well, even better than unsetting a session varaible would be to set $_SESSION to an empty array, expire the cookie used for session data, and finally, use [man]session_destroy/man if you don't need any more information from the session. (This process is shown in detail on the man page for [man]session_destroy[/man] in example 1.)

                        i cant destroy the session, is data that i need.

                          Write a Reply...