Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    May 2004
    Posts
    56
    Thanks
    12
    Thanked 0 Times in 0 Posts

    echo to a different web page.

    I have a form that has 2 text boxes and a button. When the user types in the 1st text box and hits the button, ajax sends the contents to the following php code, which echos it back, and is displayed in the 2nd text box. In addition, I'd like to echo it to another page other than the page that sent the data. I'll call this page monitor.html Googling gave me the impression I could do this, but it doesn't work. Any ideas how I can take a value from a text box in one web page and send it to the text box of another web page?
    PHP Code:
    <?php
    if (isset($GLOBALS["HTTP_RAW_POST_DATA"]))
    {
       
    $receiveMe=$GLOBALS['HTTP_RAW_POST_DATA'];
    }

    echo 
    $receiveMe('monitor.html');
    echo 
    "$receiveMe"

    ?>
    monitor.html:
    Code:
    <html><head><title></title></head><body>
    
    <input type='text' id = 'txtOutput'>
    
    <script type = 'text/javascript'>
          //txtOutput.value="hello world";  //verify that the script is executing
          var ajax = new XMLHttpRequest();
          ajax.open("POST",'sleep.php',true); 
          ajax.onreadystatechange = function(){txtOutput.value = ajax.responseText;}
    </script>
    </body></html>

  • #2
    Senior Coder
    Join Date
    Sep 2010
    Posts
    2,032
    Thanks
    15
    Thanked 240 Times in 240 Posts
    Sure, save it as a $_SESSION variable, check to see that it exists onthe other page, then echo it to the page.
    Welcome to http://www.myphotowizard.net

    where you can edit images, make a photo calendar, add text to images, and do much more.


    When you know what you're doing it's called Engineering, when you don't know, it's called Research and Development. And you can always charge more for Research and Development.

  • #3
    New Coder
    Join Date
    May 2004
    Posts
    56
    Thanks
    12
    Thanked 0 Times in 0 Posts
    Thanks DrDOS. It didn't work. But I probably didn't understand your suggestion. This way it doesn't echo to either webpage. Here's the new php with the session variable, and below that is the code for the 1st web page that contains the info I want echoed to the other webpage. Any other ideas? Thanks!

    1st Webpage: Take a value from the 1st textbox and use Ajax to send it to PHP.
    Code:
    <html><head><title></title></head><body>
    <input type='button' id = 'btnSend' onclick="send()" value="Do It"><br>
    <input type='text' id = 'txtInput'>
    <input type='text' id = 'txtOutput'>
    
    <script type = 'text/javascript'>
       function send() {
          var ajax = new XMLHttpRequest();
          ajax.open("POST",'sleep.php',false); 
          ajax.send(txtInput.value);
          ajax.onreadystatechange = function(){txtOutput.value = ajax.responseText;}
       }
    </script>
    </body></html>
    php. Receive this value. Echo it back to the web page that sent it, and also echo it to a webpage called monitor.html
    PHP Code:
    <?php
    if (isset($GLOBALS["HTTP_RAW_POST_DATA"]))
    {
       
    $receiveMe=$GLOBALS['HTTP_RAW_POST_DATA'];
       
    $_SESSION['c']=$receiveMe;

    }

    echo 
    "$_SESSION['c']('monitor.html')";
    echo 
    "$_SESSION['c']";

    ?>
    monitor.html. Receive the value and place it in a textbox.
    Code:
    <html><head><title></title></head><body>
    
    <input type='text' id = 'txtOutput'>
    
    <script type = 'text/javascript'>
          //txtOutput.value="hello world";  //verify that the script is executing
          var ajax = new XMLHttpRequest();
          ajax.open("POST",'sleep.php',true); 
          ajax.onreadystatechange = function(){txtOutput.value = ajax.responseText;}
    </script>
    </body></html>

  • #4
    Senior Coder
    Join Date
    Sep 2010
    Posts
    2,032
    Thanks
    15
    Thanked 240 Times in 240 Posts
    For you to echo or print in php the page has to have a php extension. Once you've declared a $_SESSION variable you you don't need to send the information as post or otherwise to the server, as it exists on the server already. You can send the information in a simple form processed by a php script, which declares it a $_SESSION variable..
    Welcome to http://www.myphotowizard.net

    where you can edit images, make a photo calendar, add text to images, and do much more.


    When you know what you're doing it's called Engineering, when you don't know, it's called Research and Development. And you can always charge more for Research and Development.

  • #5
    New to the CF scene
    Join Date
    Jan 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    you need to put session_start(); at the top of each page where you want the session to be available.
    PHP Code:
    <?php
    session_start
    ();
    ....

  • #6
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,341
    Thanks
    60
    Thanked 527 Times in 514 Posts
    Blog Entries
    4
    Quote Originally Posted by tony873004 View Post
    php. Receive this value. Echo it back to the web page that sent it, and also echo it to a webpage called monitor.html

    monitor.html. Receive the value and place it in a textbox.
    When your first page sends the value from the text box, it should store it in a session.

    The second page will need to be running a ajax request in a loop (eg once per second) which causes another php script tp check the session for a value. If it finds it, that script will print it and then delete it from the session.

    You cannot directly print from a php script to another browser window / tab - if you could that would be a massive security threat.

    So to recap:

    1) Page 1 sends value
    2) PHP script 1 saves it in the session
    3) Page 2 regularly 'polls' PHP script 2
    4) PHP script 2 checks the session for a value and if found, prints it
    5) Page 2's ajax request receives the echo'd value and displays it.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!


  •  

    Posting Permissions

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