Code Monkey home page Code Monkey logo

phpstuff's People

Contributors

djbpitt avatar ebeshero avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Forkers

rjp43

phpstuff's Issues

POST experiment

@djbpitt I've attempted to adapt your PHP-GET sequence of files to do the same thing with POST, and I'm not quite succeeding. Here's what I've done:

  • So as not to confuse any files we worked on with the POST experiment, I created a new subdirectory named "post" underneath "phpStuff" in my Apache server. The POST experiment currently lives here: http://digitalmitford.org/phpStuff/post/lettersInterface.html
    And I uploaded a lettersInterface.html with a new series of PHP files renamed in camelcase as postyears.php, postLetterList.php, and postLetterText.php
  • All of these files are also currently in a new "POST" directory on this GitHub repo. I also created slightly modified alternate XQuery scripts in my eXist db to fire the relevant "post" PHP files.
  • postYears.php is identical to getYears.php (since neither of these is using GET or POST, but initiating the sequence---it just fires a script that returns the years). So of course this is working still.
  • postLettersList.php is supposed to generate the list of letters on click of a year, and currently it's only delivering results because I forced it to with $_GET applied in what is otherwise (I think) a 'method'==> 'POST' context. I know this is behaving like GET or basically is GET. Here's the relevant code:
<?php
    require_once("config.php");
    $year = htmlspecialchars($_GET["year"]);
//ebb: when I change this to $_POST, I generate an HTML page with the h1 element, but no PHP generated output.
    $url = REST_PATH . "/db/queries/postLetterList.xql?year=$year";
$data = array('type' => 'input', 'target' => $year);
$options = array(
    'http' => array(
        'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
        'method'  => 'POST',
        'content' => http_build_query($data)
    )
);
    $context = stream_context_create($options);
    $result = file_get_contents($url, false, $context);
    echo $result;
?>

If I try this: $year = htmlspecialchars($_GET["year"]); it doesn't work, and I think that must be where I'm declaring the $data variable as an array, or earlier where I'm attempting to retrieve the input variable (the information retrieved from mouse-click). So I forced the above PHP to work with GET so I could see if could try to use POST on the next stage, to retrieve the text of a letter.

<?php
    require_once("config.php");
    $uri = htmlspecialchars($_POST["uri"]);
    $contents = REST_PATH . "/db/queries/letterText.xql?uri=$uri";
$data = array('type' => 'input', 'target' => $uri);
$options = array(
    'http' => array(
        'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
        'method'  => 'POST',
        'content' => http_build_query($data)
    )
);
    $context = stream_context_create($options);
    $result = file_get_contents($contents, false, $context);
    echo $result;
?>

With this, I generate an HTML page with the h1 element, and evidently part of my XQuery script is firing, but failing to retrieve the "uri" parameter, because I generate PART of the transformed XSLT file but the letter is missing! The XSLT is evidently firing to produce the basic template of the page but fails to retrieve and transform the XML file.
And once again, if I change the value of $uri to include $_GET instead of $_POST, I do successfully retrieve the XML file and the value of $uri appears in the browser.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.