iframe and php question

Discussion in 'PHP' started by x0x, Sep 20, 2008.

  1. #1
    page where i put my iframe has the $variable = 1 for example

    and then with iframe i include another file that needs to use that variable. Can it use it?
     
    x0x, Sep 20, 2008 IP
  2. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Can you be a bit clearer? It's a very vague question
     
    JAY6390, Sep 20, 2008 IP
  3. x0x

    x0x Well-Known Member

    Messages:
    510
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    110
    #3
    1. page.php with the variable $variable=1
    it also has a iframe pointing to page2.php

    2. page2.php has a javascript that uses $variable, but I don't think it can access it, with the php include command it worked fine but not with iframe...
    Should it work?
     
    x0x, Sep 20, 2008 IP
  4. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #4
    If both pages are yours you should be able to do this yes. I'm not too familiar with JavaScript but I am fairly sure you can use JavaScript to change data in an iframe.

    If you do own both pages, then you can use MySQL or a simple file system to retrieve the value from independently, and then echo it in the correct place in page2.php for the javascript
     
    JAY6390, Sep 20, 2008 IP
  5. conductr

    conductr Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    You are right, the iframe uses 2 http requests. You would have to load page2.php?variable=1 in the iframe
     
    conductr, Sep 20, 2008 IP
  6. classic

    classic Peon

    Messages:
    96
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    You cant share php variables that are not loaded in same "request" you need to pass to page2.php variables through URL params.
    iframe is just a another URL inside HTML page. it is not file inside page1.php so you cant share variables directly
     
    classic, Sep 20, 2008 IP
  7. Whiteagle

    Whiteagle Peon

    Messages:
    68
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Just like conductr said

    The iframe must be like:

    
    <iframe src="page1.php?variable= <?php echo $variable; ?> &variable2= <?php echo $variable2; ?> "></iframe>
    
    PHP:
    And the page1.php:
    
    The value of the variable 1 is : <?php echo $_GET["variable"]; ?>
    The value of the variable 2 is :  <?php echo $_GET["variable2"]; ?>
    
    PHP:
     
    Whiteagle, Sep 20, 2008 IP
  8. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #8
    pass the variables using get method on the url
     
    ads2help, Sep 21, 2008 IP