SitePoint Sponsor

User Tag List

Results 1 to 9 of 9

Threaded View

  1. #1
    SitePoint Wizard ryanhellyer's Avatar
    Join Date
    Oct 2006
    Location
    New Zealand
    Posts
    2,323
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Processing data on other servers

    Due to reasons outlined here, I'm trying to transfer data between servers without using the URL. Below are the scripts I'm using to do this. The test.php is the one run in the browser, it adds a form which when submitted sends the results to an external script on another server. The index.php file processes the data. The data.php file provides the data for use by the original server and the style.php file provides CSS data which creates coloured blocks based on hex colour codes submitted by the form.

    My intention was to grab the processed results via the readfile() function. Unfortunately the session variables I placed the resulting data into are not read by the readfile() function, presumably because the server the test.php file is on is trying to access the data and not the users browser. I was hoping javascript might have the answer, but from another topic I posted this seems to be not possible

    Do any of you know how I can get around this problem?

    Code http://localhost/test/test.php:
    <?php
    	// Start reading function
    	ob_start();
    	readfile('http://test.pixopoint.com/externalform/data.php');
    	$data = ob_get_contents();
    	ob_end_clean();
    	$data_exploded = explode("|", $data);
     
    	// Adds data to variable
    	$coloura = $data_exploded[0];
    	$colourb = $data_exploded[10];
    	$colourc = $data_exploded[2];
     
     
    	// Beginning of the HTML
    ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head profile="http://gmpg.org/xfn/1">
    	<title>Test</title>
    	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    	<link rel="stylesheet" href="http://test.pixopoint.com/externalform/style.php" media="screen" />
    </head>
    <body>
     
    <div id="coloura"></div>
    <div id="colourb"></div>
    <div id="colourc"></div>
     
    <h4>Form</h4>
    <form action="http://test.pixopoint.com/externalform/index.php" method="post">
     
    Colour A: <input name="coloura" type="text" value="<?php echo $coloura; ?>" />
    Colour B: <input name="colourb" type="text" value="<?php echo $colourb; ?>" />
    Colour C: <input name="colourc" type="text" value="<?php echo $colourc; ?>" />
     
    <input type="submit" />
    </form>
     
    </body>
    </html>

    Code http://test.pixopoint.com/externalform/index.php:
    <?php
    	session_start();
    	$_SESSION['coloura'] = $_POST['coloura'];
    	$_SESSION['colourb'] = $_POST['colourb'];
    	$_SESSION['colourc'] = $_POST['colourc'];
     
    	Header( "HTTP/1.1 301 Moved Permanently" );
    	Header( "Location: http://'.$_REQUEST['return_url'].'" );
    ?>

    Code http://test.pixopoint.com/externalform/style.php:
    <?php
    	session_start();
    	header('Content-type: text/css');
    	echo '
    	div {float:left;width:100px;height:100px;border:1px solid #666;}
    	div#coloura {background:#' . $_SESSION['coloura'] .'}
    	div#colourb {background:#' . $_SESSION['colourb'] .'}
    	div#colourc {background:#' . $_SESSION['colourc'] .'}
    	';
    ?>

    Code http://test.pixopoint.com/externalform/data.php:
    <?php
    	session_start();
    	echo $_SESSION['coloura'].'|'.$_SESSION['colourb'].'|'.$_SESSION['colourc'].'|';
    ?>
    Last edited by ryanhellyer; Apr 19, 2009 at 03:11.


Bookmarks

Posting Permissions

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