SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jul 2012
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Post Relationship of variables between php files

    Hi everyone,

    I'm curious as to how variables move in php. If a variable is created in a template then $_POST'ed back to the controller which then put's that variable in a file called $variable which is then sent to another template to display some info then sent back again to the controller for deletion.

    Must I always re'$_POST my variables between .php files?

    Thanks

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,010
    Mentioned
    187 Post(s)
    Tagged
    2 Thread(s)
    Hi ellypho, welcome to the forums,

    Always? Not at all.

    But it's perhaps the most common and easiest way to pass variables, depending.

    $_GET if trivial and there aren't many
    Cookies if trivial and there aren't many
    $_SESSION is another common way but a little trickier until you get used using to them
    INSERT into a database table, more over-head and probably only if you want to save across sessions
    File Write (eg. XML CSV), more over-head and probably only if you want to save across sessions

    IMHO except for $_GET the other ways will be more verbose code.

    Or maybe you could write things so there is no need to pass, but include instead?


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
  •