I need to place my variable $theCompany into the end of a URI for a VoiceURI on Twilio. As you can see below I've managed to create the variable but I can't figure how to put it into the URI. When we submit the page the VoiceURI field in Twilio is www.ourdomain.com/.xml.
The same is also true for the xml file I'm trying to create which saves as $theCompany.xml
The code is below, help appreciated!
Here's the line I'm using to populate the VoiceURI in Twilio:
'VoiceUrl' => "http://www.ourdomain.com/$theCompany.xml",
And here's the line I'm using to save the xml file with a new name/ same name as passed from previous into Twilio
$doc->save('"$theCompany".xml');
It's probably really simple but this isn't my normal game, I'm more on the Infusionsoft side of things but the code and web guy is on Honeymoon!
Appreciate the assistance!
--EDIT--
Thanks for the answers so far, unfortunately they don't seem to be working. Here's the full code for the PHP xml creator:
<?php
session_start();
?>
<?php
$theCompany = $_SESSION['company'];
$doc = new DOMDocument( );
$ele = $doc->createElement( 'Root' );
$ele->nodeValue = 'This is a call for $_SESSION["company"] press any key to accept the call';
$doc->appendChild( $ele );
$doc->save("$theCompany.xml");
?>
I also need some help getting the $theCompany into the URL on the Buy Number PHP page seen below.
<?php
session_start();
?>
<?php
// this line loads the library
require('Services/Twilio.php');
$theCompany = $_SESSION['company'];
$account_sid = 'AC7841a99c892xxxbc8f7xxx';
$auth_token = 'a71cxx052080xx';
$client = new Services_Twilio($account_sid, $auth_token);
$phoneNumber = $client->account->incoming_phone_numbers->create(array(
'PhoneNumber' => $_SESSION["number"],
'VoiceUrl' => "http://www.ourdomain.com/"'$theCompany .'".xml",
));
echo $phoneNumber->sid;
?>
The pages follow like so:
1) We have a PHP page to find available numbers. This page then passes the information onto the PHP page (code directly above this one)
2) That page buys the number and adds it to the account along with the VoiceURI and once submitted the page passes to the XML creator page
I have a feeling I should switch the buy and xml pages around so we search for a number then create the XML file then buy the number but not sure if that matters?
Thanks for sticking with me!
--EDIT #2--
Hi guys, sorry about this I know you're all helping best you can. I'm still having trouble with this so I'm thinking it might be best to create the XML file and pass that as a variable to the PHP file that sends info into Twilio. If we were to create the XML with $doc->save($theCompany.'.xml'); how would we pass that as a variable to the next page in place of $doc->save($theCompany.'.xml');?
I think it makes more sense to create the variables then to add them in place of the URI which is attempting to be a hybrid of static and dynamic.
So I'd be looking at something like this:
$phoneNumber = $client->account->incoming_phone_numbers->create(array(
'PhoneNumber' => $_SESSION["number"],
'VoiceUrl' => $theXML,
));
Do you think that's a better option to the route I'm taking now?
Use this
$doc->save($theCompany.".xml");
If I haven't misunderstood, this seems like a really simple problem.
Either you can write variables in a string using double quotes, like this:
$doc->save("$theCompany.xml");
Or you use single quotes for clarity, making it easier to look at:
$doc->save($theCompany . '.xml');
On your first code bit you wrote this:
$ele->nodeValue = 'This is a call for $_SESSION["company"] press any key to accept the call';
You have to make sure the session variable is escaped, like this:
$ele->nodeValue = 'This is a call for ' . $_SESSION["company"] . ' press any key to accept the call';
And for your second code bit, your phoneNumber variable has to be properly escaped:
$phoneNumber = $client->account->incoming_phone_numbers->create(array(
'PhoneNumber' => $_SESSION["number"],
'VoiceUrl' => 'http://www.ourdomain.com/' . $theCompany . '.xml',
));
Related
So i am making a simple forum to learn some PHP with CodeIgniter, by simple i mean 1 page with posts and you can click on them to comment and view more info(Think of reddit). All the data is stored in a mySQL database. Anyways i got all the links to display on my page, but what i cant figure out is how to open a new page to show the description and comments of the post. I remember doing something similar with a long time ago, can't remember how i did that sadly.
<?php
foreach($records as $rec){
$test = $rec->PostName."<br/>";
Echo "<a href=#$test>$test</a>";
}
?>
<?php
echo '<div data-role="page" id="$test"></div>';
echo "THIS ISSSSS $test";
?>
So this is the part where i need help. Any suggestions are greatly appreciated
Well for starters you'll need to refactor your attempt at generating the links as that has issues as everyone has pointed out.
So I took the liberty to come up with some test code to demonstrate a few things.
So this is Part 1.
<?php
// Simulated Database results, an array of objects
//
// These may already be Slugs with First letter upper case, hyphenated between words
// But I will do that when generating the links.
$records = [
(object)['PostName'=>'Why I recommend reading more PHP Tutorials'],
(object)['PostName'=>'Why I should take heed of what others suggest and actually try them out before dismissing them'],
(object)['PostName'=>'What is the difference between using single and double quotes in strings'],
(object)['PostName'=>'Why everyone should know how to use their browsers View Source tool to inspect the generated HTML'],
];
foreach ( $records as $rec ) {
$test = $rec->PostName;
// This would make a good helper but Codeigniter might have something already.
// So you should go and read the manual.
echo "$test";
// The above uses " to wrap the string with escaped \" within the string
// cause you cant have both.
echo '<br>';
}
// This is only here for testing... I think.
echo '<div data-role="page" id="'.$test.'"></div>';
// The above uses single quotes to wrap the string.
echo "THIS ISSSSS $test";
Part of Part 2...
<?php
// Simulated Database results, an array of objects
//
//
// These may already be Slugs with First letter upper case, hyphenated between words
// But I will do that when generating the links.
$records = [
(object)[
'id'=>1,
'PostName'=>'Why I recommend reading more PHP Tutorials'],
(object)[
'id'=>2,
'PostName'=>'What is the difference between using single and double quotes in strings'],
];
foreach ( $records as $rec ) {
$name = $rec->PostName;
$id = $rec->id;
// The slug of the page isn't really being used here as
// we are providing the pages id for lookup via an AJAX Call.
echo "<a id=".$id." href=\"#".ucfirst(str_replace(' ','-',$name))."\">$name</a>";
echo '<br>';
}
// This is where the AJAX call fired by a click on an anchor, that sends the id
// which results in the fetching of the required details to plonk in our page-area div.
echo '<div class="page-area"></div>';
There are a number of ways to do this, but going totally basic, if we create a JS event for a click on an anchor.. Which fires an AJAX Call which posts the page id to our method that returns back the HTML of the results we want to display...
I'm trying to make the following form's GET function to be part of a predefined variable.
Any ideas? Thanks in advance!
Let me explain a little more of what I'm really trying to do. I currently run a website concentrating on the U.S. stock market. I've created an HTML form with a method=GET. This form is used like a search box to look up stock ticker symbols. With the GET method, it places the ticker symbol at the end of the URL, and I created a quotes.php page that captures this information and displays a stock chart based on what ticker symbol is keyed into the box. For the company names, I've created a page called company.php that declares all of the variables for the company names (which happens to be a $ followed by the ticker symbol). The file, company.php, is the only file included in quotes.php.
This is where this came in: ' . $$_GET["symbol"] . '
The above code changes the GET into the variable based on what was typed into the form. I've used "die" to display an error message if someone types something into the box that doesn't match a variable in the company.php page.
I've also added into the company.php page variables for each company that will display which stock exchange each stock is listed on. These variables begin with "$ex_". So, what I was trying to do was have the symbol keyed into the box appended to "$ex_" so that it would display the corresponding stock exchange.
My questions are:
Is there a way to have what is typed into the form added to "$ex_"?
Is this an insecure way to code something like this (can it be hacked)?
Thank you all!
Rather than prefixing your variables and using variable variables (that are potentially insecure especially with user input), try this:
$ex = array(
"foo" => "bar",
...
);
if( !isset($ex[$_GET['symbol']])) die("Error: That symbol doesn't exist!");
$chosen = $ex[$_GET['symbol']];
Here's another approach:
extract($_GET, EXTR_PREFIX_ALL, "ex");
Although it's better to use it like this just to make sure there is no security issues.
extract($_GET, EXTR_SKIP);
PHP's extract() does what exactly what you want, and you should specify "ex_" as the prefix you want.
However, there are security issues and unintended consequences to using such a function blindly, so read up on the additional paragraphs following the function parameters.
Will the below achieve what you need?
$myGetVariable = $_GET['symbol'];
$ex_{$myGetVariable} = "Something";
$_GET['symbol'] = 'APPL';
if (!empty($_GET)) {
foreach ($_GET as $k => $v) {
$var = 'ex_'.$k ;
$$var=$v;
}
}
var_dump($ex_symbol);
APPL
This is the first time I have came in contact with JSON, and I literally have no idea how to parse it with PHP. I know that functions to decode JSON exist in PHP, but I am unsure how to retrieve specific values defined in the JSON. Here's the JSON for my app:
http://itunes.apple.com/search?term=enoda&entity=software
I require a few values to be retrieved, including the App Icon (artworkUrl100), Price (price) and Version (version).
The things I am having issues with is putting the URL of the App Icon into an actual HTML image tag, and simply retrieving the values defined in the JSON for the Price and Version.
Any help/solutions to this would be fantastic.
Thanks,
Jack
Yeah, i have something similar, for my App review website, here is a bit code:
$context = stream_context_create(array('http' => array('header'=>'Connection: close')));
$content = file_get_contents("http://ax.phobos.apple.com.edgesuite.net/WebObjects/MZStoreServices.woa/wa/wsLookup?id=$appid&country=de");
$content = json_decode($content);
$array = $content->results["0"];
$version = $array->version;
$artistname = $array->artistName;
$artistid = $array->artistId;
Thats what I used to get Information from the AppStore, maybe you can change the link and some names and it would work for you.
I'm trying to build a little script that would let me do this:
http://example.com/appicons.php?id=284417350
and then display this in plain text
http://a3.mzstatic.com/us/r1000/005/Purple/2c/a0/b7/mzl.msucaqmg.png
This is the API query to get that information (artworkUrl512):
http://ax.itunes.apple.com/WebObjects/MZStoreServices.woa/wa/wsLookup?id=284417350
Any help and example code would be much appreciated!
I am not sure why you have jQuery in your tags, unless you want to make the request dynamically without a page refresh. However you can do this simply in PHP using the following example:
$request = array (
"app_id" => #$_GET["id"]
);
// parse the requests.
if (empty($request["app_id"])) {
// redirects back / displays error
}
else {
$app_uri = "http://ax.itunes.apple.com/WebObjects/MZStoreServices.woa/wa/wsLookup?id=" . $request["app_id"];
$data = file_get_contents ($app_uri);
$json = json_decode (trim($data));
print($json->results[0]->artworkUrl100);
}
$request = file_get_contents($itms_url);
$json = json_decode(trim($request));
echo $json[0]->artworkUrl512;
should work in PHP. Unless of course there is more than one hit to the search. A solution using jQuery is probably not very much more difficult.
I have somewhat of a knowledge of the PHP coding language and I would like to connect the Campaign Monitor API(Link) with my website, so that when the user enters something into the form on my site it will add it to the database on the Campaign Monitor servers. I found the PHP code example zip file, but it contains like 30 files, and I have no idea where to begin.
Does anyone know of a tutorial anywhere that explains how to connect to the API in a step-by-step manner? The code files by themselves include to much code that I may not need for simply connecting to the database and adding and deleting users, since I only want to give the user the power to add and delete users from the Mailing List.
This actually looks pretty straightforward. In order to use the API, you simply need to include() the CMBase.php file that is in that zip file.
Once you've included that file, you can create a CampaignMonitor object, and use it to access the API functions. I took this example out of one of the code files in there:
require_once('CMBase.php');
$api_key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$client_id = null;
$campaign_id = null;
$list_id = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$cm = new CampaignMonitor( $api_key, $client_id, $campaign_id, $list_id );
//This is the actual call to the method, passing email address, name.
$result = $cm->subscriberAdd('joe#notarealdomain.com', 'Joe Smith');
You can check the result of the call like this (again taken from their code examples):
if($result['Result']['Code'] == 0)
echo 'Success';
else
echo 'Error : ' . $result['Result']['Message'];
Since you're only interested in adding a deleting users from a mailing list, I think the only two API calls you need to worry about are subscriberAdd() and subscriberUnsubscribe():
$result = $cm->subscriberAdd('joe#notarealdomain.com', 'Joe Smith');
$result = $cm->subscriberUnsubscribe('joe#notarealdomain.com');
Hope that helps. The example files that are included in that download are all singular examples of an individual API method call, and the files are named in a decent manner, so you should be able to look at any file for an example of the corresponding API method.