Phppost

Posted:
in Genius Bar edited January 2014
Is there anyway to send information through post without using a form? I was hoping there was some trick to get $_POST to work just like a regular array that I can add information too like:



$_POST[] = $whatever;



Or any other way to send information from one page to another without making it visible for the user as in GET?

Comments

  • Reply 1 of 9
    torifiletorifile Posts: 4,024member
    Quote:

    Originally posted by ast3r3x

    Is there anyway to send information through post without using a form? I was hoping there was some trick to get $_POST to work just like a regular array that I can add information too like:



    $_POST[] = $whatever;



    Or any other way to send information from one page to another without making it visible for the user as in GET?




    I'd like to know this as well. I haven't found anyway of passing information between pages without using get unless it's some sort of form. As far as I know, POST is a form function so I can't imagine it'd work without one.
  • Reply 2 of 9
    w1n78w1n78 Posts: 26member
    there's really no way to pass post variables w/o forms. if you don't want to use forms you can use variables to pass from one page to another, or sessions.
  • Reply 3 of 9
    ast3r3xast3r3x Posts: 5,012member
    What do you mean by variables? I'll look into using sessions and get back to you. Thanks in advance though
  • Reply 4 of 9
    dcmac32dcmac32 Posts: 67member
    I don't know if this is what you are looking for, but couldn't you put a hidden form and a hidden field at the bottom of the first page that can post to the next page.
  • Reply 5 of 9
    ast3r3xast3r3x Posts: 5,012member
    Quote:

    Originally posted by DCmac32

    I don't know if this is what you are looking for, but couldn't you put a hidden form and a hidden field at the bottom of the first page that can post to the next page.



    The problem with this (I believe) is that the information won't be passed along unless the form is submitted. Since you don't always want to have to press a button to pass information, you run into problems.



    I'll tell you though, I like programming in PHP, but I tend to do stuff all in one page, so I normally use at least one global variable, and my C++ teacher always tried to have us to stay away from them (not sure why) so I have this stigma that they are bad to use. I don't mind using globals like $_SESSION, $_GET, or $_POST though, because they are so nicely contained and seem appropriate;



    (I'm slightly obsessive compulsive)
  • Reply 6 of 9
    dcmac32dcmac32 Posts: 67member
    Good Point, but can't you make the link to the next page the submit button for the form.
  • Reply 7 of 9
    silentechoessilentechoes Posts: 288member
    If your going to another page, or in this case the same page, why not just throw the value int eh URL? Whats wrong with this method? If its something you don't want the user to see than you should be using Base 64 encoded MD5 cookies/sessions anyways.. So I am confused.
  • Reply 8 of 9
    w1n78w1n78 Posts: 26member
    so the reason why you don't want to use a form is coz you don't want to use a button to submit the form variables? if this is so you can use an image or a link that calls a function in javascript that says to submit the form. i wish i had the function on me. me and some friends did a project for school and we used a similar method coz we used one form and multiple buttons that submit form variables but to different pages depending on the button clicked. this method can be used on links or images since the on_click() will be calling a javascript function that says to go to a certain page and submit the form variables. i'll try to find the functions and post it, but can't guarantee since i did this project a year ago.



    i used to code PHP in one page but it got too hard to maintain for me as i kept adding things. it got hard too read and i hated scrolling on long pages when coding.
  • Reply 9 of 9
    xoolxool Posts: 2,460member
    If its only a variable or two, use cookies. Javascripts can read/write cookies as well as PHP.



    For more complex data you should use sessions. The built in PHP kind or some session mechanism of your own. (In my case, DB-based session handling is a standard part of my web framework.)
Sign In or Register to comment.