I really don't know Drupal but have managed to create a simple HTML page that I would like to use the first and last name inputted to run snoopy.class.php to run a script on a web site to retrieve some data. The button should run a function that will submit the URL but I am not getting any results.
Because I don't know how to debug in Drupal I added some echo statements to see how far the code ran it seems to be stopping when it tries to create a new snoopy object. I downloaded the class and put it in what I would think would be an accessible folder, namely public_html/tools it:
-rw-r--r-- 1 agentpitstop apache 37815 Sep 3 21:03 Snoopy.class.php
Below is the code I am using
<form method="post">
<p>Last Name: <input type="text" name="lastname" /><br />
First Name: <input type="text" name="firstname" /></p>
<p><input type="submit" value="Send it!"></p>
</form>
<?php
if($_POST)
{
echo "1st display <br />\n";
$url = "https://pdb-services-beta.nipr.com/pdb-xml-reports/hitlist_xml.cgi?";
$url = $url . "customer_number=beta83agent&pin_number=nipr123&report_type=1";
$lastname = $_POST['lastname'];
$firstname = $_POST['firstname'];
$parms = array("name_last"=>$lastname,"name_first"=>$firstname);
echo "2nd display <br />\n";
$result = curl_download($url,$parms);
$xml=simplexml_load_file("$result.xml");
$nipr_id = $xml->NPN;
echo "url " . $url . "<br />\n";
echo "Agent " . $_POST['firstname'] . " " . $_POST['lastname'] . " Id is:". $nipr_id . "<br />\n";
echo "3rd Result from call " . $result . "<br />\n";
}
?>
<?php
include "Snoopy.class.php";
function curl_download($url,$parms)
{
echo "in call to curldownload ";
$snoopy = new Snoopy();
echo "after setting object";
$snoopy->curl_path = "/usr/bin/curl"; # Or whatever your path to curl is - 'which curl' in terminal will give it to you. Needed because snoopy uses standalone curl to deal with https sites, not php_curl builtin.
echo "after setting path";
$snoopy->httpsmethod = "POST";
echo "after setting post";
$snoopy->submit($url, $parms);
echo "after setting submit";
print $snoopy->results;
echo "results: " . results;
return $snoopy->results;
}
?>
Any help would be appreciated.
If you need custom development on a Drupal site create a custom module and use Drupal's form API.
If you need to perform HTTP request from PHP, use a PHP library/extension, such a php-curl, Guzzle or Drupal's drupal_http_request(). And yes, they all support HTTPS.
Related
I took a part of PHP code from a different Stackoverflow question, and it works perfectly.
<?php header>
//Display IceCast Server Stats
$server = "***********"; //IP (x.x.x.x or domain name)
$iceport = "8070"; //Port
$iceurl = "live"; //Mountpoint
$online = "<font color=green><b>ONLINE</b> </font><br />";
$offline = "<font color=red><b>OFFLINE</b></font><br />";
if($fp = #fsockopen($server, $iceport, $errno, $errstr, '1')) {
fclose($fp);
$ice_status=$online;
echo "<p><b>DJ:</b> $ice_status";
$stats = file("http://" . $server . ":" . $iceport . "/status2.xsl");
$status = explode(",", $stats[5]);
$artist = explode("-", $status[5]);
echo " " . $artist[1];
echo " - ";
echo " " . $artist[2];
echo "<br />";
// echo "<b>Listeners:</b> <b> " . $status[3] . "</b>";
echo "</p>";
//echo "<br />";
//echo "<p><a href=http://" . $server . ":" . $iceport . "/" . $iceurl . " target=new><b>Listen!</b></a></p>";
} else {
$ice_status=$offline;
echo "<p><b>DJ:</b> $ice_status";
}
?>
<hr />
</center>
I'm trying to add the stream name, which is currently:
echo "DJ: $ice_status";
This displays DJ: ONLINE, but I want it to say DJ: (DJ Name/Stream Name)
I do believe its variables from status2.xsl, but I'm a complete noob at this, and can't seem to figure out how to use it. Could anyone tell me what streamname variable would be?
I was also wondering, is it possible to make it so the "nowplaying.php" refreshes, but my whole web page doesn't? I've tried an iframe, but it makes it look really bad, and has errors.
What my website looks like at the moment: https://i.stack.imgur.com/luc4O.jpg
I'd suggest having a look at TheFineManual™:
http://icecast.org/docs/icecast-2.4.1/server-stats.html#xslt
Especially the part about status-json.xsl. Make sure you are running an up to date version of Icecast. Icecast is available from all major Linux distributions in up to date packaging. Xiph provides independent packaging, which is useful if there are no up to date packages for a distribution, e.g. shortly after an Icecast release.
status2.xsl was an example file, and a bad one at that. It was removed from newer Icecast versions.
I currently have a variables.php file like this:
<?php
$rep_name = "John Doe";
$rep_phone = "555-555-5555";
$rep_email = "johndoe#email.com";
$rep_subject = "Agent Contact: JDoe";
$rep_price = "39.95";
?>
I want to create an HTML page with a form that would generate this - would look something like this:
<form name="generatevariables" action="generate_variables_file.php" method="post">
Rep Name:<input name="rep_name" placeholder="John Doe"><br />
Rep Phone:<input name="rep_phone" placeholder="555-555-5555"><br />
Rep Email:<input name="rep_email" placeholder="johndoe#email.com"><br />
Rep Subject:<input name="rep_subject" placeholder="Agent Contact: JDoe"><br />
Rep Price:<input name="rep_price" placeholder="39.95">
</form>
and they would enter their information and click a button that says Generate. That would create the variables.php file and download it to their computer for them to upload via FTP:
<?php
$rep_name = "John Doe";
$rep_phone = "555-555-5555";
$rep_email = "johndoe#email.com";
$rep_subject = "Agent Contact: JDoe";
$rep_price = "39.95";
?>
which could then be uploaded and the variables be called throughout the site, just as I am currently calling the variables at the very top.
Does this make sense? I need for the rep to be able to generate their own variables.php file, the rest of the website depends on the variables.php file for all content that is specific to them.
Thanks.
You can set an appropriate header to force download, then just echo out the code in plain text:
<?php
//generate_variables_file.php
header('Content-disposition: attachment; filename=variables.php');
header('Content-type: text/plain');
echo '<?php';
echo '$rep_name = "' . $_POST['rep_name'] . '";';
echo '$rep_phone = "' . $_POST['rep_phone'] . '";';
echo '$rep_email = "' . $_POST['rep_email'] .'";';
echo '$rep_subject = "' . $_POST['rep_subject'] .'";';
echo '$rep_price = "' . $_POST['rep_price'] .'";'
echo '?>';
I'm have to build a "simple" application that will reads an xml file, prompts a user to choose a "response activity" in relation to what's on that file and send the whole thing (what was loaded + the activity chosen by the user) to a client over http in a new xml file.
So my questions is:
how can i add what's been loaded as well as the user chosen response activity onto a new xml file? and how do i send it to anyaddress.com?
i've also been told to use rest webservices, and although i have found a lot of information and examples online, nothing seem to be relevant to what i'm trying to do.
As you may have guessed, i'm new to all this. here' what i've done so far:
<?php
//reader.php
// Load the xml file and show what's on it
$xml = simplexml_load_file('xmlfile.xml')
or die("Could not open file!<hr /> ");
foreach($xml->children() as $child) {
foreach($child->children() as $young) {
echo $young->getName() . ": " . $young . "<br />";
}
}
// call the activity list according to what's on the xml file
if ($child->ACTIVITY == 'activity import') {
echo "<br/>" . file_get_contents('interface.php');
}
elseif($child->ACTIVITY == 'activity import special'){
echo "<br/>" . file_get_contents('interface1.php');
}
elseif($child->ACTIVITY == 'activity export'){
echo "<br/>" . file_get_contents('interface2.php');
}
else {
echo "<br/>" . 'incorrect activity';
}
// print the selected activity on page
if (isset($_POST['submit1'])) {
$selected_radio = $_POST['group1'];
print $selected_radio;
}
?>
this is one of the 3 forms i have for user input interface2.php
<form name="serv1" action="reader.php" method="POST">
<div align="left"><br>
<input type="radio" name="group1" value="OUTBOUND"> OUTBOUND<br/>
<input type="radio" name="group1" value="DONTPROCESS" checked> DON'T PROCESS<br/><br/>
<input type="submit" name="submit1" value="Return">
</div>
</form>
Any kind of help will be much appreciated.
You can perform edits on an XML file e.g. with SimpleXML or with DOMDocument.
You could post the result to another server with CURL.
I am using a drupal_http_request to an xml string from another web site I am currently trying to figure out how to grab this as an xml it does not seem to be working but when I run the exact same url in a browser it gives me back the information in xml format any ideas on how to do this Thought if I put something in like $headers = array("Content-Type: text/xml") when I execute $http_contents = drupal_http_request($url, $headers = array("Content-Type: text/xml")); it would give me the data in an xml format but it is not any ideas thanks in advance Below is my code
<form method="post">
<p>Last Name: <input type="text" name="lastname" /><br />
First Name: <input type="text" name="firstname" /></p>
<p><input type="submit" value="Send it!"></p>
</form>
<?php
if($_POST)
{
$url = "https://pdb-services-beta.nipr.com/pdb-xml-reports/hitlist_xml.cgi?customer_number=testlogin&pin_number=testpin&report_type=1";
$url = $url . "&name_last=" . $_POST['lastname'] ."&name_first=". $_POST['firstname'];
$result = grabData($url);
$xml=simplexml_load_file("$result.xml");
$nipr_id = $xml->NPN;
echo "Agent " . $_POST['firstname'] . " " . $_POST['lastname'] . " Id is:". $nipr_id . "<br />\n";
}
?>
<?php
function grabData($url)
{
$http_contents = drupal_http_request($url);
if (!isset($http_contents->data)) {
throw new RuntimeException("Cannot get contents from the URL");
}
if($replace_special_characters)
$http_contents_data = str_replace('&','&', $http_contents->data);
else
$http_contents_data = $http_contents->data;
$xml_parser = xml_parser_create();
xml_parse_into_struct($xml_parser, $http_contents_data, $result);
xml_parser_free($xml_parser);
echo "Display http_contents_data " . $http_contents_data . "<br />\n";
echo "Display result " . $result . "<br />\n";
return $result;
}
?>
here is what I am receiving
LISTsamplelastname, samplefirstname samplemiddlenamesampleidsampleidstateDOB
and when I run the url through the browser I get this
<?xml version='1.0' encoding='UTF-8'?>
<HITLIST>
<TRANSACTION_TYPE>
<TYPE>
LIST
</TYPE>
</TRANSACTION_TYPE>
<INDIVIDUAL>
<NAME>
samplelastname, samplefirstname samplemiddlename
</NAME>
<ID_ENTITY>
sampleid
</ID_ENTITY>
<NPN>
sampleid
</NPN>
<STATE_RESIDENT>
state
</STATE_RESIDENT>
<DATE_BIRTH>
dob
</DATE_BIRTH>
</INDIVIDUAL>
<INDIVIDUAL>
</INDIVIDUAL>
With the help of Supdley and My fellow worker John Salevetti I found the solution. Merely wrap the xml contents in htmlspecialchars the xml now displays
The answer to this was wrapping the xml content in question in a htmlspecialchars command this will override the suppression of non-html characters on the page. Would like to send a shoutout to Spudley who looked at this code and reminded me of the nonhtml character suppression Thanks Spudley for helping me not to go too far down that rabbit hole!
this was the original line ....
echo "Display http_contents_data " . $http_contents_data . "<br />\n";
and this is the modified line......
echo "Display http_contents_data " . htmlspecialchars($http_contents_data) . "<br />\n";
For example if I had the script:
<?php
$page = "My Page";
echo "<title>" . $page . "</title>";
require_once('header.php');
require_once('content.php');
require_once('footer.php');
?>
Is there something I can add to the bottom of that page to show the entire pre-compiled php?
I want to literally echo the php code, and not compile it.
So in my browser I would see the following in code form...
// stuff from main php
$page = "My Page";
echo "<title>" . $page . "</title>";
// stuff from require_once('header.php');
$hello = "Welcome to my site!";
$name = "Bob";
echo "<div>" . $hello . " " . $name . "</div>";
// stuff from require_once('content.php');
echo "<div>Some kool content!!!!!</div>";
// stuff from require_once('footer.php');
$footerbox = "<div>Footer</div>";
echo $footerbox;
Is this possible?
There's no way to do it native to PHP, but you could try to hack it if you just wanted something extremely simplistic and non-robust:
<?php
$php = file_get_contents($_GET['file']);
$php = preg_replace_callback('#^\s*(?:require|include)(?:_once)?\((["\'])(?P<file>[^\\1]+)\\1\);\s*$#m', function($matches) {
$contents = file_get_contents($matches['file']);
return preg_replace('#<\?php(.+?)(?:\?>)?#s', '\\1', $contents);
}, $php);
echo '<pre>', htmlentities($php), '</pre>';
Notes:
Warning: Allowing arbitrary file parsing like I've done with the fist line is a security hole. Do your own authentication, path restricting, etc.
This is not recursive (though it wouldn't take much more work to make it so), so it won't handle included files within other included files and so on.
The regex matching is not robust, and very simplistic.
The included files are assumed to be statically named, within strings. Things like include($foo); or include(__DIR__ . '/foo.php'); will not work.
Disclaimer: Essentially, to do this right, you need to actually parse the PHP code. I only offer the above because it was an interesting problem and I was bored.
echo '$page = "My Page";';
echo 'echo "<title>" . $page . "</title>";';
echo file_get_contents('header.php');
echo file_get_contents('content.php');
echo file_get_contents('footer.php');
For clarity I'd put the title generation in it's own file, then just use a series of echo file_get_contents()...
echo file_get_contents('title.php');
echo file_get_contents('header.php');
echo file_get_contents('content.php');
echo file_get_contents('footer.php');