Passing GET with include()

Discussion in 'PHP' started by Jonhoo, Jan 24, 2006.

  1. #1
    Allright, so, I have a file which I want to include() in another script.. Now, the main script (The one with the include() statement) is passed a GET parameter in the URL which the second file (The one to be included) needs..

    So, my question will now be, how can I pass the GET parameter from the main script to the second script?

    Thanks in advance :)
    Jon
     
    Jonhoo, Jan 24, 2006 IP
  2. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #2
    By just calling $_GET['your_var'];

    Nothing special. Should work as is. Whatever is included can access the URL params (at least on my server).

    If that doesn't work for some odd reason, then whatever you do in the include, make it in a function. Then after you include it go:

    your_function($_GET['your_var']);
     
    T0PS3O, Jan 24, 2006 IP
  3. Jonhoo

    Jonhoo Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    The problem is, you see, that there is another file included in the included file, which is the one which really need the variable.... But I don't know what it wants or how it gets it since it is a phpBB file..

    I'm writing a script for keeping forum sessions alive all across my page...

    If I call the included file directly with the parameter in the URL, then it works...
     
    Jonhoo, Jan 24, 2006 IP
  4. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Why don't you store the session ID in a cookie then.
     
    T0PS3O, Jan 24, 2006 IP
  5. Jonhoo

    Jonhoo Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    How would you suggest I should do that with security in mind?

    And wouldn't that make the page slower to load? If the main page has to set a cookie every time it loads...
     
    Jonhoo, Jan 24, 2006 IP
  6. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #6
    It only sets the cookie once. I don't think checking the set values slows it down that much.

    osCommerce does it that way when you select Force Cookie. You can check it out yourself how they do it, the code is in catalog/includes/application_top.php

    It actually uses a combination of cookies and MySQL session id storage. I don't know the intricacies.
     
    T0PS3O, Jan 24, 2006 IP
  7. Jonhoo

    Jonhoo Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I didn't think of that... :p
    What would you recommend setting the expiration time as?
    And, how would you recommend setting/checking the cookie?

    Just one question though, how will this help me with my problem? If the second script reads the cookie, will the input then be considered as the same as something in the URL? I don't see how else the included script in the second script can get info from the cookie..?

    And whats osCommerce? :p
     
    Jonhoo, Jan 24, 2006 IP
  8. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Considering you're a newbie who's first post was a shameless question rather than an introduction or a contribution I will refrain from answering all that. It will be better for your learning experience to find out yourself.
     
    T0PS3O, Jan 24, 2006 IP
  9. Jonhoo

    Jonhoo Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    1. Yes, I'm a newbie to PHP
    2. Sorry about my lack of introduction, but I've posted this question onto multiple forums, because I wanted to get an answer as quick as possible.. Therefore I did not take the time to properly introduce myself on all the forums...
    3. I think what I meant came out a bit wrong.. What I meant was, do you know any good ways of doing this, and if so, could you provide me with a guide to it as I would in fact like to learn it myself :)

    4. I really do appreciate all the help :)

    Jon
     
    Jonhoo, Jan 24, 2006 IP
  10. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,334
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #10
    If you copy/paste the include code you are using, it would be helpful.
     
    digitalpoint, Jan 24, 2006 IP
  11. DavidAusman

    DavidAusman Peon

    Messages:
    399
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #11
    You can use hidden field if you had form on the main script. Or the other way is passing the variable via URL and then fetch the variable on the second script.
     
    DavidAusman, Jan 25, 2006 IP