Results 1 to 19 of 19

Thread: Conditionally call <?php ?> code? [RESOLVED]

  1. #1

    Thread Starter
    Addicted Member Phenix's Avatar
    Join Date
    Sep 2002
    Location
    Near A Cube
    Posts
    228

    Question Conditionally call <?php ?> code? [RESOLVED]

    Can I have php code existing in a file, but the code between the tags only gets called conditionally (say, when a javascript button is pressed)?

    I want to set a PHP SESSION variable only if a button is pressed.
    Last edited by Phenix; Apr 27th, 2003 at 12:31 PM.

  2. #2
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    Re: Conditionally call <?php ?> code?

    Originally posted by Phenix
    Can I have php code existing in a file, but the code between the tags only gets called conditionally (say, when a javascript button is pressed)?

    I want to set a PHP SESSION variable only if a button is pressed.
    Not like you want to do it. You can have the button refresh the page and call the code, though.

    But after all the output is sent to the browser (as the PHP file is being parsed), you can't call part of the script.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  3. #3
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    if you want to add the session id to the form than you have to use 2 differetn forms like in one of your other posts. that way you can have the session in the url depending on what form you clicked on, but why? php sessions are read form script to script liek GLOBAL varaibles. don't need the session id for that.

  4. #4

    Thread Starter
    Addicted Member Phenix's Avatar
    Join Date
    Sep 2002
    Location
    Near A Cube
    Posts
    228
    This did come up as a possible workaround for my apparent misuse of setting the querystring. But I wanted to set a session variable other than the php session id from a non-php decision/condition.

  5. #5
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    you can still do that without sending the session_id. just set the session on the next page that you want.

  6. #6
    Lively Member DJ P@CkMaN's Avatar
    Join Date
    Jan 2002
    Location
    Burpengary, Queensland, Australia
    Posts
    95
    Yo could setup a small PHP file to set the session ID then use a hidden IFRAME on your page to do it.
    PHP Code:
    <script type='text/javascript'>
    function 
    setSession() {
       
    document.frames['iframe'].src='ses_sess.php';
    }
    </
    script>
    <
    input type='button' value='Set Session' onClick="sesSession()" /><br />
    <
    iframe id='iframe' style='width: 0px; height: 0px; visibility: hidden;'></iframe
    There's something I've noticed in the last year or so...
    Australian's are good at EVERYTHING !!!

  7. #7
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    why? if you set the session_start() at the start of every page you can save the session anytime you want, without a iframe or hidden frame or anything.

    without using the session_id for anything.

  8. #8
    Lively Member DJ P@CkMaN's Avatar
    Join Date
    Jan 2002
    Location
    Burpengary, Queensland, Australia
    Posts
    95
    Originally posted by phpman
    why? if you set the session_start() at the start of every page you can save the session anytime you want, without a iframe or hidden frame or anything.

    without using the session_id for anything.
    What he really wants is client-side PHP. He wants a session to be set when the user clicks a button in the browser and that can't be done directly in PHP so a hidden IFRAME is probably the next best thing.
    There's something I've noticed in the last year or so...
    Australian's are good at EVERYTHING !!!

  9. #9
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    what?

    if he clicked on the button and it went to the next page, you can set it there with php.

    why make it harder than it isn't. if he didn't goto another page than yes your way would probably be better but he is going to another page. so set the session on the other page.

    and what is client-side php? no such thing

  10. #10

    Thread Starter
    Addicted Member Phenix's Avatar
    Join Date
    Sep 2002
    Location
    Near A Cube
    Posts
    228
    phpman,
    I never was interested in the session id. PHP Sessions takes care of that variable for me. I was interested in setting a different session variable conditionally.

    Anyway, I think it is this thread that is the one that doesn't make sense, now that I have a better understanding of passing POST and GET variables at the same time from the other thread ( http://vbforums.com/showthread.php?s...92#post1422892 ).

    The session variable could be set depending on what was passed from the previous page as you said.

    If anyone really needs to do this, what DJ P@CkMaN said looks like a solution.

  11. #11
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by phpman
    and what is client-side php? no such thing
    Packman wasn't saying there was. He was saying that Phenix wanted to use client-side functionality.

    Is English your first language, phpman?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  12. #12
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    Originally posted by DJ P@CkMaN
    What he really wants is client-side PHP.
    he said it right there Hobo. And yes English is my first language, just because I don't punctuate doesn't mean it isn't. I hated english class and I am also lazy when it comes to spelling and punctuation.

  13. #13
    Lively Member DJ P@CkMaN's Avatar
    Join Date
    Jan 2002
    Location
    Burpengary, Queensland, Australia
    Posts
    95
    Yes I said that, but where did I say it existed? I meant it as

    "What he wants is client-side PHP but since that doesn't exist, here is what he could do..."
    There's something I've noticed in the last year or so...
    Australian's are good at EVERYTHING !!!

  14. #14
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by phpman
    he said it right there Hobo.
    That is not saying it exists. The fact that you are missing this is why I asked if English is your native language. If not, I was just going to drop it.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  15. #15
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    what you say and what you mean are two different things.

    put it this way, if you knew nothing about php and I told you to use client-side php, what would you think?

    "What he really wants is client-side PHP."

    to me at first glance means that DJ P@CkMaN thinks that there is client-side php.

    where did he say that is doesn't exist? (except for the better explaination of it on the last post)

    and knowing english doesn't have anything to do with that sentence. it could mean 2 things since DJ P@CkMaN didn't say it did or didn't exist.

  16. #16
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by phpman
    where did he say that is doesn't exist? (except for the better explaination of it on the last post)
    Where does he say it does?

    Haven't you ever heard someone say "What I really want is a mindless woman that loves sex"?

    But mindless women who love sex don't exist. Nor did that sentence imply that they did.

    Originally posted by phpman
    and knowing english doesn't have anything to do with that sentence. it could mean 2 things since DJ P@CkMaN didn't say it did or didn't exist.
    Knowing English has everything to do with that sentence, as it was written in English.

    I'm sure there's even a name for it. It's a language device. If I was that bored, I'd do a search.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  17. #17
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    this is stupid,

    "What he really wants is client-side PHP."

    that is implying that is exist. he ididn't say it didn't therefore it is implied.

    you think inside the box, I will think outisde.

  18. #18
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by phpman
    this is stupid,

    "What he really wants is client-side PHP."

    that is implying that is exist. he ididn't say it didn't therefore it is implied.

    you think inside the box, I will think outisde.
    How can you say that you think outside the box when you can't even grasp the variation or implied nature of language.

    You may be outside of the box, but the box is sixty feet underground, like your thinking.

    I agree this is stupid. And I'm starting to think you are too. You're not even reading my posts, are you?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  19. #19

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width