Sending information to a PHP-server

Discussion in 'PHP' started by TriKri, Jul 2, 2007.

  1. #1
    Say just theoretically:

    You have a web page with 1000 links in it, each of them referring to the same PHP-page, located at another computer. Each link shall sen different information to the page, supposably not by writing ? and then the arguments after the link, cause the amount of data is as large as 1 MB. Totally, your html-document or web page contains about 1 GB of data, but you only want to send the information from one of the links (~1 MB) to the PHP-page, since the rest of the information is unintresting and 1 GB is to much to send.

    Is it possible to do so? How shall the two documents be constructed?

    For example, you have many different links in your html-document:

    Send "Moby Dick"
    Send "Alice in wonderland"
    Send "Robinson Crusoe"
    etc.

    The PHP page at the other computer is then going to display the Novel in html for you.
     
    TriKri, Jul 2, 2007 IP
  2. sarahk

    sarahk iTamer Staff

    Messages:
    28,898
    Likes Received:
    4,555
    Best Answers:
    123
    Trophy Points:
    665
    #2
    Create the page with many forms and an html submit link.
    Use the POST method.
     
    sarahk, Jul 2, 2007 IP
  3. ansi

    ansi Well-Known Member

    Messages:
    1,483
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    100
    #3
    either that or just send an "id" to the external page and let it get the information that is related to the id that was sent from within the database. that way all you are sending is www.foo.com/bar.php?id=5423 and then having bar.php fetch all the relative information for id # 5423
     
    ansi, Jul 2, 2007 IP
  4. sarahk

    sarahk iTamer Staff

    Messages:
    28,898
    Likes Received:
    4,555
    Best Answers:
    123
    Trophy Points:
    665
    #4
    and then you can use .htaccess to remove the ? too.

    If site #2 doesn't have a database it could always pick up the actual content via xml.
     
    sarahk, Jul 2, 2007 IP
  5. TriKri

    TriKri Peon

    Messages:
    19
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thank you both of you, I didn't know of even one of the methods you mentioned! Worth taking a look at. :)
     
    TriKri, Jul 3, 2007 IP
  6. TriKri

    TriKri Peon

    Messages:
    19
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Sorry, but what do you mean with "fetching" the information? Is there som function fetch or do you have any special method in mind? I can't really figure out how to do it... Thanks once again!
     
    TriKri, Jul 9, 2007 IP
  7. ansi

    ansi Well-Known Member

    Messages:
    1,483
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    100
    #7
    you pass id in $_GET to fetch.php or whatever via a link to it <a href="fetch.php?id=1234">fetch it</a> and then in fetch.php your code would look something like this
    
    <?php
        $sql = "select foo, bar, poo, babies from tbl1 where id = '".mysql_real_escape_String($_GET['id'])."'";
        $result = mysql_query($sql) or die( mysql_error() );
        while( $row = mysql_fetch_array($result, MYSQL_ASSOC) )
        {
            echo $row['foo']."<br />\n";
            echo $row['bar']."<br />\n";
            echo $row['poo']."<br />\n";
            echo $row['babies']."<br />\n";
        }
    ?>
    
    PHP:
     
    ansi, Jul 9, 2007 IP
  8. Cloudberries

    Cloudberries Peon

    Messages:
    74
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #8
    You could perhaps achieve the same result by sending the name of the document you'd want to read, and then use that name to fetch an html/text file and "include" it in the current document.

    For example, if your page address is as follows : index.php?novel=robinson_crusoe

    you could have the following php code
    
    <?php
    
    $novel = $_GET['novel'];
    //check if a text file exists in the same directory as the index.php
    //script (in this case, a file called "robinson_crusoe.txt" - use
    //underlines instead of spaces) - if so, "include" this information in
    //the current file with readfile(). If not, send an error saying the
    //data cannot be found.
    if(file_exists($novel.".txt")
    {
      readfile($novel.".txt");
    }
    else
    {
      echo ("The novel you are looking for does not exist");
    }
    
    ?>
    
    Code (markup):
    It's quite a basic way of doing it, but it's simple to maintain and if you don't have experience of databases, it's much simpler to see where all the novel data is stored - i.e. in a list of .txt files in your main directory
     
    Cloudberries, Jul 9, 2007 IP