Carrying PHP Variables From Web Page To Web Page

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ralph Freshour

    Carrying PHP Variables From Web Page To Web Page

    I was reading about PHP variable scoping - it doesn't seem to support
    carrying any variables from one web page to another - how is this
    usually done? I have a lot of php variables created on my home page
    that I need to make use of on other web pages - how can I do that?

    Thanks...

  • David Walker

    #2
    Re: Carrying PHP Variables From Web Page To Web Page

    > 3 choices[color=blue]
    > 1) use sessions to hold the variables between pages
    > 2) use hidden form fields and submit buttons (not secure)
    > 3) use a database to hold the values and embed the key in your urls (e.g.
    > href='somepage. php?id=34')[/color]

    .... of which sessions (option 1) is the best option, since that effectively
    stores the values on the server as in option 3, but can pass the 'key' from
    option 3 either as a cookie, form fields as in option 2 or as part of the
    link, again from option 3.

    David


    Comment

    • Wm

      #3
      Re: Carrying PHP Variables From Web Page To Web Page

      Is it possible to do something like this:

      Form on page1: POST to page2
      Page2: extract($_POST)
      hyperlink to Page3: <A HREF="page3.php ?data=_POST">co ntinue</A>

      (I know it won't work as written, but is something similar possible?)

      Wm


      "David Walker" <wbsdavenews@ho tmail.com> wrote in message
      news:bgn434$b3u $1@wisteria.csv .warwick.ac.uk. ..[color=blue][color=green]
      > > 3 choices
      > > 1) use sessions to hold the variables between pages
      > > 2) use hidden form fields and submit buttons (not secure)
      > > 3) use a database to hold the values and embed the key in your urls[/color][/color]
      (e.g.[color=blue][color=green]
      > > href='somepage. php?id=34')[/color]
      >
      > ... of which sessions (option 1) is the best option, since that[/color]
      effectively[color=blue]
      > stores the values on the server as in option 3, but can pass the 'key'[/color]
      from[color=blue]
      > option 3 either as a cookie, form fields as in option 2 or as part of the
      > link, again from option 3.
      >
      > David
      >
      >[/color]


      Comment

      • David Walker

        #4
        Re: Carrying PHP Variables From Web Page To Web Page

        > Form on page1: POST to page2[color=blue]
        > Page2: extract($_POST)
        > hyperlink to Page3: <A HREF="page3.php ?data=_POST">co ntinue</A>[/color]

        As far as I know, you could only do this if your hyperlink was actually a
        submit button of a form which was pre-filled in with the values you want to
        pass on - which would require javascript and is more of a bodge than a real
        solution. If theres not much data you could use GET, which can just be
        added onto the end of the hyperlink as you show, but not with POST, which
        can be much much longer. I would still recommend sessions for this - then
        you only need to pass the session ID (which is automatic in most cases
        anyway) and then the rest can be left in the session. Unless your server
        hasn't been updated for quite some time, it should have session support and
        i can't think of any disadvantages to using that instead of passing
        variables around multiple times from many pages - apart from anything else
        if it is a lot of data then its being sent to and from the client at least
        twice more then what it needs to.

        David


        Comment

        Working...