Grow your CSS skills. Land your dream job.

How do I send a PHP variable to another file.

  • # May 21, 2009 at 2:04 pm

    How would I send a php variable to another php file and then redirect the user to a totaly different file?

    # May 21, 2009 at 7:09 pm
    "mattvot" wrote:
    How would I send a php variable to another php file?

    You don’t really send variables in php. If you include another php file, the included file will have access to all global variables.

    If you want to keep the value of some variable between page requests then you will need to store the value somewhere. The easiest places to store values are in cookies, sessions or a database. Which one you use depends on the exact scenario.

    http://www.w3schools.com/PHP/php_includes.asp
    http://www.w3schools.com/PHP/php_sessions.asp

    # May 22, 2009 at 7:17 pm

    Or, you can POST or GET the variable over.

    Like when you see something like http://example.com/?var=123

    That is available through a GET on another PHP file as a way to pass variables back and forth.

    # May 22, 2009 at 9:02 pm

    So, how would would I POST it, without creating a new form?

    Basically, the original issue I needed this for is solved. I tried sessions, but that was to confusing, and there were security issues, so I opted for cookies instead.

    But never-the-less, I am intrigued on how you would send a POST variable over to another php file without a form by actually POSTing it, if it is even possible?.

    (p.s. It’s a shameful plug, i know :) but the site this thread was going to help is now completed. http://www.phpyouradmin.com/)

    # May 23, 2009 at 12:37 am
    "mattvot" wrote:
    So, how would would I POST it, without creating a new form?

    PHP cURL:

    I would learn sessions first though, as it’s about 1/3 as complicated… I don’t fully know cURL; I just hack my way through it when I need to. Lots of guessing and checking.

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".