I would try to approach this as a multi-tiered menu level where you can query (group by) PID, then group by cPID for further refinement. Two tables will help with. Hopefully, that gets the gears turning.
michael.dewitt.716 15 Newbie Poster
Thanks cereal, once you said that it was jsonp, i was able to refine my search. In the end, i came across this function that seem to work really well:
function jsonp_decode($jsonp, $assoc = false) { // PHP 5.3 adds depth as third parameter to json_decode
if($jsonp[0] !== '[' && $jsonp[0] !== '{') { // we have JSONP
$jsonp = substr($jsonp, strpos($jsonp, '('));
}
return json_decode(trim($jsonp,'();'), $assoc);
}
print_r(jsonp_decode($res, true));
This was a featured post when i donated, but i dont know why its not showing as one. Thanks again for all your help and pointing me in the right direction.
cereal commented: You're welcome! +15
michael.dewitt.716 15 Newbie Poster
I know this title is rather confusing, but here it goes.
I have a PHP cURL request and the return is in a string. Normally i can easily echo specific objects from the JSON response, but i have never dealt with string returns.
Here is my php
<?php
$url = "http://profile.combatarms.nexon.net/en/api/ProfilePlayerV2/OG_KneeGro__";
$ch = curl_init($url);
$headr = array();
$headr[] = "Host: profile.combatarms.nexon.net";
$headr[] = "User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:54.0) Gecko/20100101 Firefox/54.0";
$headr[] = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
$headr[] = "Accept-Language: en-US,en;q=0.5";
$headr[] = "Cookie: i18next=en; _ls_bid=__new__; device_id=a2b3c270-bb08-4afd-8839-4c794e71dded; fingerprintv1=655870065693bdf4ced7825e4fee1f7c4e7f8a37; ccc=US";
$headr[] = "Connection: keep-alive";
$headr[] = "Upgrade-Insecure-Requests: 1";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headr);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$res = curl_exec($ch);
echo "<pre>";
echo var_dump($res);
echo "</pre>";
curl_close($ch);
?>
which return this:
string(5283) "executeParce({"d":{"nickname":"xxxxxxx","userstatus":"ACTIVE","createdate":"05/07/2013","nationcode":"US","gradelevel":"55","charactergender":"2","totrank":"5,606",alot more data,}});"
since this is not a JSON return, how do i get the nickname?
Here is the request header and response header from firefox.
Response:
Cache-Control "private"
Content-Type "application/x-javascript; charset=utf-8"
Server "Microsoft-IIS/7.5"
X-AspNetMvc-Version "5.2"
X-AspNet-Version "4.0.30319"
Set-Cookie "pageLan=1nDyHvJz5W8=; domain=…n; domain=.nexon.net; path=/"
x-powered-by "ASP.NET"
Date "Sun, 06 Aug 2017 05:50:51 GMT"
Content-Length "5283"
Request:
Host "profile.combatarms.nexon.net"
User-Agent "Mozilla/5.0 (Windows NT 10.0;… Gecko/20100101 Firefox/54.0"
Accept "text/html,application/xhtml+x…lication/xml;q=0.9,*/*;q=0.8"
Accept-Language "en-US,en;q=0.5"
Accept-Encoding "gzip, deflate"
Cookie "i18next=en; _ls_bid=__new__; …825e4fee1f7c4e7f8a37; ccc=US"
DNT "1"
Connection "keep-alive"
Upgrade-Insecure-Requests "1"
Cache-Control "max-age=0"
michael.dewitt.716 15 Newbie Poster
diafol, by god ole' chap you have done it again... lol i just forgot to put a = ? in the prepared statement for that col. I caught it when i switched the update statement to a string. Thanks again man.
michael.dewitt.716 15 Newbie Poster
have you tried performing a var_dump on the json_encode on line 27? Also how are you calling the function in the js file when its not linked to your page?
have you tried ajax?
michael.dewitt.716 15 Newbie Poster
Hello all,
i have been searching and now i am coming here to ask for some help.
can i use a php function in bind_param? If so, how can i go about doing it?
my function does have a return in it rather than an echo and when i echo the variable the function is bound to, it works.
$test = calc($var1,$var2);
echo $test;
function calc($var1,$var2) {
blah blah
return $somevar;
}
michael.dewitt.716 15 Newbie Poster
Hi,
im assuming this is javascript and not php.
Second, do you want to call a function every xx minutes via ajax? If so, just set the interval and call the function in it.
setInterval(ajaxCall, 300000); //300000 MS == 5 minutes
function ajaxCall() {
//do your AJAX stuff here
}
or delete line 16 since its an extra bracket and move the miliseconds to line 17 between the parenthesis and bracket
}, 15000);
post back and let us know.
michael.dewitt.716 15 Newbie Poster
Just want to say thanks diafol. Given the above output from above, i will work on this and post what ever i come up with.
i guess for night now, i can use each $k=>$v, but im still gonna tinker around. Thanks for the reply.
michael.dewitt.716 15 Newbie Poster
Ok sorry, it was late last night when i posted this. Here is the JSON response from clash of clans website:
<?php
["items"]=>
array(45) {
[0]=>
array(10) {
["tag"]=>
string(9) "#VGLVGVVJ"
["name"]=>
string(5) "ariel"
["role"]=>
string(8) "coLeader"
["expLevel"]=>
int(203)
["league"]=>
array(3) {
["id"]=>
int(29000020)
["name"]=>
string(15) "Titan League II"
["iconUrls"]=>
array(3) {
["small"]=>
string(94) "https://api-assets.clashofclans.com/leagues/72/llpWocHlOoFliwyaEx5Z6dmoZG4u4NmxwpF-Jg7su7Q.png"
["tiny"]=>
string(94) "https://api-assets.clashofclans.com/leagues/36/llpWocHlOoFliwyaEx5Z6dmoZG4u4NmxwpF-Jg7su7Q.png"
["medium"]=>
string(95) "https://api-assets.clashofclans.com/leagues/288/llpWocHlOoFliwyaEx5Z6dmoZG4u4NmxwpF-Jg7su7Q.png"
}
}
["trophies"]=>
int(4427)
["clanRank"]=>
int(1)
["previousClanRank"]=>
int(1)
["donations"]=>
int(1281)
["donationsReceived"]=>
int(907)
}
[1]=>
array(10) {
["tag"]=>
string(9) "#90UVCJUU"
["name"]=>
string(9) "Satanillo"
["role"]=>
string(6) "leader"
["expLevel"]=>
int(171)
["league"]=>
array(3) {
["id"]=>
int(29000018)
["name"]=>
string(17) "Champion League I"
["iconUrls"]=>
array(3) {
["small"]=>
string(94) "https://api-assets.clashofclans.com/leagues/72/9v_04LHmd1LWq7IoY45dAdGhrBkrc2ZFMZVhe23PdCE.png"
["tiny"]=>
string(94) "https://api-assets.clashofclans.com/leagues/36/9v_04LHmd1LWq7IoY45dAdGhrBkrc2ZFMZVhe23PdCE.png"
["medium"]=>
string(95) "https://api-assets.clashofclans.com/leagues/288/9v_04LHmd1LWq7IoY45dAdGhrBkrc2ZFMZVhe23PdCE.png"
}
}
["trophies"]=>
int(3936)
["clanRank"]=>
int(2)
["previousClanRank"]=>
int(3)
["donations"]=>
int(247)
["donationsReceived"]=>
int(318)
}
}
?>
Just want to get the name and tag of each member and return them with json_encode back to page1.php.
i re-added the dataType: "json", and with your answer i was able to get a success response. Thanks alot on that.
I have been looking about about trying to loop through multidimenstional associative array, but without using foreach - from my level of knowledge - i wont be able to return them all without actually having the build the structure.
crude example:
echo "{"
for($i=0;$i<51;$i++)
echo "\"tag\"=>".$array = array_column($data['items'], 'tag').",";
echo "}";
michael.dewitt.716 15 Newbie Poster
Hi everyone,
i have a page that uses jquery ajax to get json from another page. However, instead of the ajax using sucess, it goes directly to error. I have a debug on the error to see what is the issue and i get "Parsing JSON Request failed."
page 1.php
$("#validate").click(function() {
var tags = $("#coc_tag").val();
var type = $("#type").val();
var cleantag = tags.replace(/#/, "%23");
switch(type) {
case 'clan':
$.ajax({
url: "/coc/mirror.php?tag="+cleantag+"&type="+type,
method: "GET",
//dataType: "json",
cache: false,
success: function(data, textStatus){
//for testing.
alert("good");
$.each(data,function( key, value ) {
alert( key + ": " + value );
})
},
error:function(x,e) {
if (x.status==0) {
alert('You are offline!!\n Please Check Your Network.');
} else if(x.status==404) {
alert('Requested URL not found.');
} else if(x.status==500) {
alert('Internel Server Error.');
} else if(e=='parsererror') {
alert('Error.\nParsing JSON Request failed.');
} else if(e=='timeout'){
alert('Request Time out.');
} else {
alert('Unknow Error.\n'+x.responseText);
}
}
});
break;
}
});
here is the php page the outputs the json.
mirror.php
<?php
header('Content-type: application/json');
// extra curl stuff that i took out
$headr = array();
$headr[] = "Accept: application/json";
$headr[] = "Authorization: Bearer ".$token;
curl_setopt($ch, CURLOPT_HTTPHEADER, $headr);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$res = curl_exec($ch);
$data = json_decode($res, true);
$items = $data["items"];
class item {
public $tag = "";
}
$test = new item();
foreach($items as $item) {
$test->tag = $item["tag"];
echo json_encode($test);
}
curl_close($ch);
?>
The output looks like this
{"tag":"#VGLVGVVJ"}{"tag":"#Y0G8PC2G"}{"tag":"#90UVCJUU"}{"tag":"#LG9L8GJG"}{"tag":"#J80R2VLJ"}{"tag":"#9PP298LR"}{"tag":"#Q0JYV8JU"}{"tag":"#9JY2U2YY"}{"tag":"#LPUUG2Y9"}{"tag":"#GL9929UC"}{"tag":"#PG0QQJ09"}{"tag":"#9PLR09G0"}{"tag":"#GCJPQ92Y"}{"tag":"#UC00RCLJ"}{"tag":"#2LR8UVLJ0"}{"tag":"#RVUYGCPV"}{"tag":"#2LJLQGYGG"}{"tag":"#RQ22PJYC"}{"tag":"#PP0P9VUL"}{"tag":"#8RVCV0RV"}{"tag":"#QL88L9CJ"}{"tag":"#RUCLLUV"}{"tag":"#2Q0PQCPV"}{"tag":"#RYLJJU02"}{"tag":"#GVGJLQU9"}{"tag":"#L8VLQGC9"}{"tag":"#2288P98Q8"}{"tag":"#2CG22U002"}{"tag":"#VGJQYQQ9"}{"tag":"#2ULCPY2G0"}{"tag":"#229GP9C09"}{"tag":"#82RPULG2"}{"tag":"#VU82QUCY"}{"tag":"#202JCRL9"}{"tag":"#VCR8PY2V"}{"tag":"#8YLC2LJCR"}{"tag":"#GUQJQU90"}{"tag":"#RPQ0U2Y0"}{"tag":"#2LLGC8C8V"}{"tag":"#22CPJRPPQ"}{"tag":"#UCUL0RR0"}{"tag":"#2LC82CL8"}{"tag":"#2RJQ9P28C"}{"tag":"#2QPCYY9U"}{"tag":"#P2VU8YG0"}{"tag":"#20RGCLCL"}{"tag":"#2YJG2R88C"}
Again, im getting the error trigger on the jQuery ajax.
michael.dewitt.716 15 Newbie Poster
So i found out what it was, the endpoint address was address="web", so i changed it to address="Sumit". Works now with the client.
Now im getting another error from the client (computer a) posting the data: The remote server returned an unexpected response: (405) Method Not Allowed.
Ill have to submit a thread for this one, because i definetly cannot figure it out.
michael.dewitt.716 15 Newbie Poster
Here is my host service app.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="mexBehaviour">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="mexBehaviour">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<!-- name is from HelloService.cs namespace.class. behaviorConfiguration is from the endpoint address.-->
<service name="ItemService.ItemService" behaviorConfiguration="mexBehaviour">
<endpoint name="web" address="web" binding="webHttpBinding" behaviorConfiguration ="mexBehaviour" contract="ItemService.IItemService"></endpoint>
<host>
<baseAddresses>
<!--// For basicHttpBinding endpoint (where the web address will enter)-->
<add baseAddress="http://localhost/ItemService" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
</configuration>
Program.cs for the host service
namespace ItemServiceHost
{
class Program
{
static void Main()
{
using (ServiceHost host = new ServiceHost(typeof(ItemService.ItemService)))
{
host.Open();
Console.WriteLine("Host Started @ " + DateTime.Now.ToString());
Console.ReadLine();
}
}
}
}
when i had the endpoint address as "http://localhost/ItemService" instead of "web", i was able to view the servcie. However, when i did /Submit, i got an error saying "endpoint not found". If i change the endpoint to web, i put in the address with /Submit and i get a big white blank screen.
The IItemService.cs to recieve the url parameters.
using System.ServiceModel;
using System.ServiceModel.Web;
namespace ItemService
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IItemService" in both code and config file together.
[ServiceContract]
public interface IItemService
{
[OperationContract]
string Submit(string itemData);
}
}
The ItemService.cs
namespace ItemService
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "ItemService" in both code and config file together.
public class ItemService …
michael.dewitt.716 15 Newbie Poster
So what you are saying is that i need to create a website -> WCF Service in VS? or actually create a website via xampp or apache and have it listen on that port?
The code that i posted will be running on computer A (client) posting the info to computer B (server)
Im using a console application to run a service host on computer B, so do i just need to add the endpoint there? or am i way off the mark?
michael.dewitt.716 15 Newbie Poster
Good morning all,
i have a somewhat complicated question; which i am trying to learn to answer myself.
I have a couple of questions about what it is that i am trying to accomplish, ie is that a RESTful or WCF action that im trying to accomplish.
So for the most part, i bought the O'Reilly book "Programming WCF Services" and i didnt seem to really answer what i am trying to do, however learned some good knowledge of things.
So for my question:
Q 1) So What is the difference between RESTful and WCF?
I have learned how to set up a WCF Application via VS and load it in the URL: ex localhost:1111/myservice.svc/dothis, but whenever i google or look at tutorials, they have localhost/dothis and again i cant really find out how to pass parameters from computer A to computer B and computer B spits it out.
When i launch a program to run the below code, i get an error saying that
[Connector] There was no endpoint listening at http://localhost/Submit that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
Computer A has a program that is running this code and gathering the respected info and posting it. Keep in mind that i got this from someone, but still have some knowledge of whats going on.
Service Contract for ItemService.cs
using System.ServiceModel; …