Just learning php. I am trying to connect PHP with Javascript through AJAX call.
My javascript file looks like this:
$.ajax({
type:"GET",
url:"test.php",
success:function(data) {
console.log(data); // to check response
}
});
and my php file looks like:
<?php
include('example.php');
header("Content-type: text/javascript");
$key = '4e899892ede0f86b7cb65f974cede5ff';
$latitude = $_GET['latitude'];
$longitude = $_GET['longitude'];
$timestamp = $_GET['timestamp'];
$weather = new WeatherAPIConnector('4e899892ede0f86b7cb65f974cede5ff');
$condition = $weather->getCurrentForecast($latitude,$longitude,$timestamp);
echo $condition;
$conditi = array();
$conditi = $weather->getTodaysTemp($latitude,$longitude);
echo $conditi;
?>
The console shows the entire php file(console.log(data)):
Please let me know how to get the value of $conditi alone
Judging by your words
Just learning php.
I believe you haven't setup a php webserver yet. To use PHP you need to do one of the following:
Setup a web server - you can use software such as XAMP.
Use free / paid Webhosting such as HostGator or any other webhosting provider. and upload your php file there.
Use http://phptester.net/.
And while you are at it, can you post the URL on your address bar?
Check you web server configuration. It looks like the php is not executed but delivered as static content.
Try to open it directly in the browser. Does it also show the php source code?
I went through the same issue, thinking I coded something wrong.
Solution:
In CentOS7 for PHP7.2
sudo yum-config-manager --enable remi-php72
sudo yum install php php-common php-opcache php-mcrypt php-cli php-gd php-curl php-mysqlnd
The one enabling you to cURL data between your FRONT-SERVERS is the second line.
Each PHP7.x version has it own modules ...
Read this article, this is where I found the solution.
https://linuxize.com/post/install-php-7-on-centos-7/
You can find the same php-modules in different distros, just need to research.
Related
Looking at this document; I am trying to make a file upload using XMLHttpRequest.
Here is how I start: I take the code in the A little vanilla framework section of the document. Then I first make it work on my own site. Then to implement the upload functionality I want to modify the end of the register.php file. Indeed a file transfer to the server is already happening there. To call it an upload I only have to save the file on the server.
I do that after these lines:
echo "\n\n:: Files received ::\n\n";
print_r($_FILES);
There, I want to write the contents of $_FILES[0] on the server. For that I use this code:
$myfile = fopen("MyData.jpg", "w");
fwrite($myfile, $_FILES[0]);
// The three lines below that I have tried instead of the one above do not work either.
//fwrite($myfile, json_encode($_FILES['photos']);
//fwrite($myfile, json_encode($_FILES[photos[0]]);
//fwrite($myfile, json_encode($_FILES['photos'][0]);
fclose($myfile);
As a result, there is a file named MyData.jpg written on the server as expected, but its length is zero.
I think there is a mistake in the three lines above but, what did I do wrong?
Right method is to use
move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], "MyData.jpg");
where "fileToUpload" is the field name you gave for the file button
I think you'll get data here: $_FILES['photos']['tmp_name'][0].
Try it please.
Or
You could rewrite your code like below:
foreach($_FILES['photos']['tmp_name'] as $i=>$file){
if($_FILES['photos']['error'][$i] == 0){
move_uploaded_file($file, "MyData_".$i.".jpg");
}
}
I'm building a web application in CodeIgniter and I'm using jQuery and AJAX. I created the whole app locally (using XAMPP) and everything worked fine. After I uploaded the app to my web hosting, one AJAX keeps failing. Here is the part of the code:
// Get all form inputs
var inputs = $('#app-options-existing-form :input[type="text"]');
// Put them in object as name=>value
var data = {};
for(i=0; i<inputs.length; i++) {
data[inputs[i]["name"]] = inputs[i]["value"];
}
// Put loader while AJAX is working
$(".app-content-container").html('<center><img class="loader" src="<?php echo base_url();?>/img/loader.gif" ></center>');
console.log(data);
// Generate POST request
$.post("<?php echo site_url("admin/ajax_app_options"); ?>",
{"add_existing_form_submited" : true, "data" : data2},
function (data) {
alert("test" + data);
});
Here's the console showing error and result of console.log(data)
First, I thought that the key ("d1d1d1") was the problem because I was first using "1-1-1" and after I manually changed it, it was working. But then I changed everything in "d1d1d1" and it doesn't work again. As I said, it works on XAMPP but not on server. Can be a problem in using full URL for AJAX, instead of relative one? But I'm using it in other AJAX requests as well and it works.
Pretty sure you problem is this guy '<center><img class="loader" src="<?php echo base_url();?>/img/loader.gif" ></center>'
Yours source is going to output literally to <?php echo base_url();?>/img/loader.gif which is of course not a real link. Therefore it is a resource that can not be loaded.
You might want to try instead using: '<center><img class="loader" src="/img/loader.gif" ></center>'
The base_url() function is just going to return '/' anyway.
Important! In general you can not write php in javascript. Or this would be a massive security hole that would give every user who visits your site unlimited access to your server.
I've done the research and most people seem to say there is no great way for this, but I'd like to ask again.
A 3rd party site is returning a value I need via Javascript. Meaning when I view the source of the page I see lots of JS but in the browser it shows me a simple string. When I use CURL I just get the raw JS.
The string I need is simply something like 4b71ec1a4cc2a95f9dfa1c023ecd74e6 The JS that generates this is about 50 lines long. Any way PHP can process this for me?
The source including the JS is:
<!doctype html><html><head></head><body><script>var _0x916d=["\x6C\x20\x42\x28\x78\x2C\x6B\x29\x7B\x70\x20\x61\x3D\x78\x5B\x30\x5D\x2C\x62\x3D\x78\x5B\x31\x5D\x2C\x63\x3D\x78\x5B\x32\x5D\x2C\x64\x3D\x78\x5B\x33\x5D\x3B\x61\x3D\x68\x28\x61\x2C\x62\x2C\x63\x2C\x64\x2C\x6B\x5B\x30\x5D\x2C\x37\x2C\x2D\x31\x77\x29\x3B\x64\x3D\x68\x28\x64\x2C\x61\x2C\x62\x2C\x63\x2C\x6B\x5B\x31\x5D\x2C\x31\x32\x2C\x2D\x31\x76\x29\x3B\x63\x3D\x68\x28\x63\x2C\x64\x2C\x61\x2C\x62\x2C\x6B\x5B\x32\x5D\x2C\x31\x37\x2C\x31\x78\x29\x3B\x62\x3D\x68\x28\x62\x2C\x63\x2C\x64\x2C\x61\x2C\x6B\x5B\x33\x5D\x2C\x32\x32\x2C\x2D\x31\x79\x29\x3B\x61\x3D\x68\x28\x61\x2C\x62\x2C\x63\x2C\x64\x2C\x6B\x5B\x34\x5D\x2C\x37\x2C\x2D\x31\x7A\x29\x3B\x64\x3D\x68\x28\x64\x2C\x61\x2C\x62\x2C\x63\x2C\x6B\x5B\x35\x5D\x2C\x31\x32\x2C\x31\x75\x29\x3B\x63\x3D\x68\x28\x63\x2C\x64\x2C\x61\x2C\x62\x2C\x6B\x5B\x36\x5D\x2C\x31\x37\x2C\x2D\x31\x74\x29\x3B\x62\x3D\x68\x28\x62\x2C\x63\x2C\x64\x2C\x61\x2C\x6B\x5B\x37\x5D\x2C\x32\x32\x2C\x2D\x31\x6F\x29\x3B\x61\x3D\x68\x28\x61\x2C\x62\x2C\x63\x2C\x64\x2C\x6B\x5B\x38\x5D\x2C\x37\x2C\x31\x6E\x29\x3B\x64\x3D\x68\x28\x64\x2C\x61\x2C\x62\x2C\x63\x2C\x6B\x5B\x39\x5D\x2C\x31\x32\x2C\x2D\x31\x70\x29\x3B\x63\x3D\x68\x28\x63\x2C\x64\x2C\x61\x2C\x62\x2C\x6B\x5B\x31\x30\x5D\x2C\x31\x37\x2C\x2D\x31\x71\x29\x3B\x62\x3D\x68\x28\x62\x2C\x63\x2C\x64\x2C\x61\x2C\x6B\x5B\x31\x31\x5D\x2C\x32\x32\x2C\x2D\x31\x73\x29\x3B\x61\x3D\x68\x28\x61\x2C\x62\x2C\x63\x2C\x64\x2C\x6B\x5B\x31\x32\x5D\x2C\x37\x2C\x31\x72\x29\x3B\x64\x3D\x68\x28\x64\x2C\x61\x2C\x62\x2C\x63\x2C\x6B\x5B\x31\x33\x5D\x2C\x31\x32\x2C\x2D\x31\x41\x29\x3B\x63\x3D\x68\x28\x63\x2C\x64\x2C\x61\x2C\x62\x2C\x6B\x5B\x31\x34\x5D\x2C\x31\x37\x2C\x2D\x31\x42\x29\x3B\x62\x3D\x68\x28\x62\x2C\x63\x2C\x64\x2C\x61\x2C\x6B\x5B\x31\x35\x5D\x2C\x32\x32\x2C\x31\x4C\x29\x3B\x61\x3D\x65\x28\x61\x2C\x62\x2C\x63\x2C\x64\x2C\x6B\x5B\x31\x5D\x2C\x35\x2C\x2D\x31\x4B\x29\x3B\x64\x3D\x65\x28\x64\x2C\x61\x2C\x62\x2C\x63\x2C\x6B\x5B\x36\x5D\x2C\x39\x2C\x2D\x31\x4D\x29\x3B\x63\x3D\x65\x28\x63\x2C\x64\x2C\x61\x2C\x62\x2C\x6B\x5B\x31\x31\x5D\x2C\x31\x34\x2C\x31\x4E\x29\x3B\x62\x3D\x65\x28\x62\x2C\x63\x2C\x64\x2C\x61\x2C\x6B\x5B\x30\x5D\x2C\x32\x30\x2C\x2D\x31\x4F\x29\x3B\x61\x3D\x65\x28\x61\x2C\x62\x2C\x63\x2C\x64\x2C\x6B\x5B\x35\x5D\x2C\x35\x2C\x2D\x31\x4A\x29\x3B\x64\x3D\x65\x28\x64\x2C\x61\x2C\x62\x2C\x63\x2C\x6B\x5B\x31\x30\x5D\x2C\x39\x2C\x31\x49\x29\x3B\x63\x3D\x65\x28\x63\x2C\x64\x2C\x61\x2C\x62\x2C\x6B\x5B\x31\x35\x5D\x2C\x31\x34\x2C\x2D\x31\x6D\x29\x3B\x62\x3D\x65\x28\x62\x2C\x63\x2C\x64\x2C\x61\x2C\x6B\x5B\x34\x5D\x2C\x32\x30\x2C\x2D\x31\x43\x29\x3B\x61\x3D\x65\x28\x61\x2C\x62\x2C\x63\x2C\x64\x2C\x6B\x5B\x39\x5D\x2C\x35\x2C\x31\x45\x29\x3B\x64\x3D\x65\x28\x64\x2C\x61\x2C\x62\x2C\x63\x2C\x6B\x5B\x31\x34\x5D\x2C\x39\x2C\x2D\x31\x46\x29\x3B\x63\x3D\x65\x28\x63\x2C\x64\x2C\x61\x2C\x62\x2C\x6B\x5B\x33\x5D\x2C\x31\x34\x2C\x2D\x31\x48\x29\x3B\x62\x3D\x65\x28\x62\x2C\x63\x2C\x64\x2C\x61\x2C\x6B\x5B\x38\x5D\x2C\x32\x30\x2C\x31\x47\x29\x3B\x61\x3D\x65\x28\x61\x2C\x62\x2C\x63\x2C\x64\x2C\x6B\x5B\x31\x33\x5D\x2C\x35\x2C\x2D\x31\x50\x29\x3B\x64\x3D\x65\x28\x64\x2C\x61\x2C\x62\x2C\x63\x2C\x6B\x5B\x32\x5D\x2C\x39\x2C\x2D\x31\x69\x29\x3B\x63\x3D\x65\x28\x63\x2C\x64\x2C\x61\x2C\x62\x2C\x6B\x5B\x37\x5D\x2C\x31\x34\x2C\x51\x29\x3B\x62\x3D\x65\x28\x62\x2C\x63\x2C\x64\x2C\x61\x2C\x6B\x5B\x31\x32\x5D\x2C\x32\x30\x2C\x2D\x52\x29\x3B\x61\x3D\x67\x28\x61\x2C\x62\x2C\x63\x2C\x64\x2C\x6B\x5B\x35\x5D\x2C\x34\x2C\x2D\x55\x29\x3B\x64\x3D\x67\x28\x64\x2C\x61\x2C\x62\x2C\x63\x2C\x6B\x5B\x38\x5D\x2C\x31\x31\x2C\x2D\x53\x29\x3B\x63\x3D\x67\x28\x63\x2C\x64\x2C\x61\x2C\x62\x2C\x6B\x5B\x31\x31\x5D\x2C\x31\x36\x2C\x54\x29\x3B\x62\x3D\x67\x28\x62\x2C\x63\x2C\x64\x2C\x61\x2C\x6B\x5B\x31\x34\x5D\x2C\x32\x33\x2C\x2D\x31\x6C\x29\x3B\x61\x3D\x67\x28\x61\x2C\x62\x2C\x63\x2C\x64\x2C\x6B\x5B\x31\x5D\x2C\x34\x2C\x2D\x31\x67\x29\x3B\x64\x3D\x67\x28\x64\x2C\x61\x2C\x62\x2C\x63\x2C\x6B\x5B\x34\x5D\x2C\x31\x31\x2C\x31\x66\x29\x3B\x63\x3D\x67\x28\x63\x2C\x64\x2C\x61\x2C\x62\x2C\x6B\x5B\x37\x5D\x2C\x31\x36\x2C\x2D\x31\x65\x29\x3B\x62\x3D\x67\x28\x62\x2C\x63\x2C\x64\x2C\x61\x2C\x6B\x5B\x31\x30\x5D\x2C\x32\x33\x2C\x2D\x31\x68\x29\x3B\x61\x3D\x67\x28\x61\x2C\x62\x2C\x63\x2C\x64\x2C\x6B\x5B\x31\x33\x5D\x2C\x34\x2C\x56\x29\x3B\x64\x3D\x67\x28\x64\x2C\x61\x2C\x62\x2C\x63\x2C\x6B\x5B\x30\x5D\x2C\x31\x31\x2C\x2D\x31\x6B\x29\x3B\x63\x3D\x67\x28\x63\x2C\x64\x2C\x61\x2C\x62\x2C\x6B\x5B\x33\x5D\x2C\x31\x36\x2C\x2D\x31\x6A\x29\x3B\x62\x3D\x67\x28\x62\x2C\x63\x2C\x64\x2C\x61\x2C\x6B\x5B\x36\x5D\x2C\x32\x33\x2C\x31\x64\x29\x3B\x61\x3D\x67\x28\x61\x2C\x62\x2C\x63\x2C\x64\x2C\x6B\x5B\x39\x5D\x2C\x34\x2C\x2D\x31\x63\x29\x3B\x64\x3D\x67\x28\x64\x2C\x61\x2C\x62\x2C\x63\x2C\x6B\x5B\x31\x32\x5D\x2C\x31\x31\x2C\x2D\x59\x29\x3B\x63\x3D\x67\x28\x63\x2C\x64\x2C\x61\x2C\x62\x2C\x6B\x5B\x31\x35\x5D\x2C\x31\x36\x2C\x58\x29\x3B\x62\x3D\x67\x28\x62\x2C\x63\x2C\x64\x2C\x61\x2C\x6B\x5B\x32\x5D\x2C\x32\x33\x2C\x2D\x57\x29\x3B\x61\x3D\x66\x28\x61\x2C\x62\x2C\x63\x2C\x64\x2C\x6B\x5B\x30\x5D\x2C\x36\x2C\x2D\x5A\x29\x3B\x64\x3D\x66\x28\x64\x2C\x61\x2C\x62\x2C\x63\x2C\x6B\x5B\x37\x5D\x2C\x31\x30\x2C\x31\x38\x29\x3B\x63\x3D\x66\x28\x63\x2C\x64\x2C\x61\x2C\x62\x2C\x6B\x5B\x31\x34\x5D\x2C\x31\x35\x2C\x2D\x31\x62\x29\x3B\x62\x3D\x66\x28\x62\x2C\x63\x2C\x64\x2C\x61\x2C\x6B\x5B\x35\x5D\x2C\x32\x31\x2C\x2D\x31\x61\x29\x3B\x61\x3D\x66\x28\x61\x2C\x62\x2C\x63\x2C\x64\x2C\x6B\x5B\x31\x32\x5D\x2C\x36\x2C\x31\x39\x29\x3B\x64\x3D\x66\x28\x64\x2C\x61\x2C\x62\x2C\x63\x2C\x6B\x5B\x33\x5D\x2C\x31\x30\x2C\x2D\x31\x44\x29\x3B\x63\x3D\x66\x28\x63\x2C\x64\x2C\x61\x2C\x62\x2C\x6B\x5B\x31\x30\x5D\x2C\x31\x35\x2C\x2D\x31\x52\x29\x3B\x62\x3D\x66\x28\x62\x2C\x63\x2C\x64\x2C\x61\x2C\x6B\x5B\x31\x5D\x2C\x32\x31\x2C\x2D\x32\x6A\x29\x3B\x61\x3D\x66\x28\x61\x2C\x62\x2C\x63\x2C\x64\x2C\x6B\x5B\x38\x5D\x2C\x36\x2C\x32\x66\x29\x3B\x64\x3D\x66\x28\x64\x2C\x61\x2C\x62\x2C\x63\x2C\x6B\x5B\x31\x35\x5D\x2C\x31\x30\x2C\x2D\x32\x69\x29\x3B\x63\x3D\x66\x28\x63\x2C\x64\x2C\x61\x2C\x62\x2C\x6B\x5B\x36\x5D\x2C\x31\x35\x2C\x2D\x32\x68\x29\x3B\x62\x3D\x66\x28\x62\x2C\x63\x2C\x64\x2C\x61\x2C\x6B\x5B\x31\x33\x5D\x2C\x32\x31\x2C\x32\x65\x29\x3B\x61\x3D\x66\x28\x61\x2C\x62\x2C\x63\x2C\x64\x2C\x6B\x5B\x34\x5D\x2C\x36\x2C\x2D\x32\x6B\x29\x3B\x64\x3D\x66\x28\x64\x2C\x61\x2C\x62\x2C\x63\x2C\x6B\x5B\x31\x31\x5D\x2C\x31\x30\x2C\x2D\x31\x51\x29\x3B\x63\x3D\x66\x28\x63\x2C\x64\x2C\x61\x2C\x62\x2C\x6B\x5B\x32\x5D\x2C\x31\x35\x2C\x32\x63\x29\x3B\x62\x3D\x66\x28\x62\x2C\x63\x2C\x64\x2C\x61\x2C\x6B\x5B\x39\x5D\x2C\x32\x31\x2C\x2D\x31\x57\x29\x3B\x78\x5B\x30\x5D\x3D\x6F\x28\x61\x2C\x78\x5B\x30\x5D\x29\x3B\x78\x5B\x31\x5D\x3D\x6F\x28\x62\x2C\x78\x5B\x31\x5D\x29\x3B\x78\x5B\x32\x5D\x3D\x6F\x28\x63\x2C\x78\x5B\x32\x5D\x29\x3B\x78\x5B\x33\x5D\x3D\x6F\x28\x64\x2C\x78\x5B\x33\x5D\x29\x7D\x6C\x20\x77\x28\x71\x2C\x61\x2C\x62\x2C\x78\x2C\x73\x2C\x74\x29\x7B\x61\x3D\x6F\x28\x6F\x28\x61\x2C\x71\x29\x2C\x6F\x28\x78\x2C\x74\x29\x29\x3B\x6D\x20\x6F\x28\x28\x61\x3C\x3C\x73\x29\x7C\x28\x61\x3E\x3E\x3E\x28\x31\x58\x2D\x73\x29\x29\x2C\x62\x29\x7D\x6C\x20\x68\x28\x61\x2C\x62\x2C\x63\x2C\x64\x2C\x78\x2C\x73\x2C\x74\x29\x7B\x6D\x20\x77\x28\x28\x62\x26\x63\x29\x7C\x28\x28\x7E\x62\x29\x26\x64\x29\x2C\x61\x2C\x62\x2C\x78\x2C\x73\x2C\x74\x29\x7D\x6C\x20\x65\x28\x61\x2C\x62\x2C\x63\x2C\x64\x2C\x78\x2C\x73\x2C\x74\x29\x7B\x6D\x20\x77\x28\x28\x62\x26\x64\x29\x7C\x28\x63\x26\x28\x7E\x64\x29\x29\x2C\x61\x2C\x62\x2C\x78\x2C\x73\x2C\x74\x29\x7D\x6C\x20\x67\x28\x61\x2C\x62\x2C\x63\x2C\x64\x2C\x78\x2C\x73\x2C\x74\x29\x7B\x6D\x20\x77\x28\x62\x5E\x63\x5E\x64\x2C\x61\x2C\x62\x2C\x78\x2C\x73\x2C\x74\x29\x7D\x6C\x20\x66\x28\x61\x2C\x62\x2C\x63\x2C\x64\x2C\x78\x2C\x73\x2C\x74\x29\x7B\x6D\x20\x77\x28\x63\x5E\x28\x62\x7C\x28\x7E\x64\x29\x29\x2C\x61\x2C\x62\x2C\x78\x2C\x73\x2C\x74\x29\x7D\x6C\x20\x4F\x28\x73\x29\x7B\x31\x56\x3D\x27\x27\x3B\x70\x20\x6E\x3D\x73\x2E\x43\x2C\x76\x3D\x5B\x31\x55\x2C\x2D\x32\x64\x2C\x2D\x31\x53\x2C\x31\x54\x5D\x2C\x69\x3B\x75\x28\x69\x3D\x41\x3B\x69\x3C\x3D\x73\x2E\x43\x3B\x69\x2B\x3D\x41\x29\x7B\x42\x28\x76\x2C\x4E\x28\x73\x2E\x4D\x28\x69\x2D\x41\x2C\x69\x29\x29\x29\x7D\x73\x3D\x73\x2E\x4D\x28\x69\x2D\x41\x29\x3B\x70\x20\x72\x3D\x5B\x30\x2C\x30\x2C\x30\x2C\x30\x2C\x30\x2C\x30\x2C\x30\x2C\x30\x2C\x30\x2C\x30\x2C\x30\x2C\x30\x2C\x30\x2C\x30\x2C\x30\x2C\x30\x5D\x3B\x75\x28\x69\x3D\x30\x3B\x69\x3C\x73\x2E\x43\x3B\x69\x2B\x2B\x29\x72\x5B\x69\x3E\x3E\x32\x5D\x7C\x3D\x73\x2E\x7A\x28\x69\x29\x3C\x3C\x28\x28\x69\x25\x34\x29\x3C\x3C\x33\x29\x3B\x72\x5B\x69\x3E\x3E\x32\x5D\x7C\x3D\x31\x59\x3C\x3C\x28\x28\x69\x25\x34\x29\x3C\x3C\x33\x29\x3B\x4B\x28\x69\x3E\x31\x5A\x29\x7B\x42\x28\x76\x2C\x72\x29\x3B\x75\x28\x69\x3D\x30\x3B\x69\x3C\x31\x36\x3B\x69\x2B\x2B\x29\x72\x5B\x69\x5D\x3D\x30\x7D\x72\x5B\x31\x34\x5D\x3D\x6E\x2A\x38\x3B\x42\x28\x76\x2C\x72\x29\x3B\x6D\x20\x76\x7D\x6C\x20\x4E\x28\x73\x29\x7B\x70\x20\x44\x3D\x5B\x5D\x2C\x69\x3B\x75\x28\x69\x3D\x30\x3B\x69\x3C\x41\x3B\x69\x2B\x3D\x34\x29\x7B\x44\x5B\x69\x3E\x3E\x32\x5D\x3D\x73\x2E\x7A\x28\x69\x29\x2B\x28\x73\x2E\x7A\x28\x69\x2B\x31\x29\x3C\x3C\x38\x29\x2B\x28\x73\x2E\x7A\x28\x69\x2B\x32\x29\x3C\x3C\x31\x36\x29\x2B\x28\x73\x2E\x7A\x28\x69\x2B\x33\x29\x3C\x3C\x32\x34\x29\x7D\x6D\x20\x44\x7D\x70\x20\x45\x3D\x27\x32\x61\x27\x2E\x32\x62\x28\x27\x27\x29\x3B\x6C\x20\x4A\x28\x6E\x29\x7B\x70\x20\x73\x3D\x27\x27\x2C\x6A\x3D\x30\x3B\x75\x28\x3B\x6A\x3C\x34\x3B\x6A\x2B\x2B\x29\x73\x2B\x3D\x45\x5B\x28\x6E\x3E\x3E\x28\x6A\x2A\x38\x2B\x34\x29\x29\x26\x49\x5D\x2B\x45\x5B\x28\x6E\x3E\x3E\x28\x6A\x2A\x38\x29\x29\x26\x49\x5D\x3B\x6D\x20\x73\x7D\x6C\x20\x4C\x28\x78\x29\x7B\x75\x28\x70\x20\x69\x3D\x30\x3B\x69\x3C\x78\x2E\x43\x3B\x69\x2B\x2B\x29\x78\x5B\x69\x5D\x3D\x4A\x28\x78\x5B\x69\x5D\x29\x3B\x6D\x20\x78\x2E\x32\x39\x28\x27\x27\x29\x7D\x6C\x20\x48\x28\x73\x29\x7B\x6D\x20\x4C\x28\x4F\x28\x73\x29\x29\x7D\x6C\x20\x6F\x28\x61\x2C\x62\x29\x7B\x6D\x28\x61\x2B\x62\x29\x26\x32\x38\x7D\x4B\x28\x48\x28\x27\x32\x35\x27\x29\x21\x3D\x27\x32\x36\x27\x29\x7B\x6C\x20\x6F\x28\x78\x2C\x79\x29\x7B\x70\x20\x47\x3D\x28\x78\x26\x46\x29\x2B\x28\x79\x26\x46\x29\x2C\x50\x3D\x28\x78\x3E\x3E\x31\x36\x29\x2B\x28\x79\x3E\x3E\x31\x36\x29\x2B\x28\x47\x3E\x3E\x31\x36\x29\x3B\x6D\x28\x50\x3C\x3C\x31\x36\x29\x7C\x28\x47\x26\x46\x29\x7D\x7D\x6C\x20\x73\x28\x73\x29\x7B\x6D\x20\x48\x28\x22\x32\x37\x22\x2B\x73\x2B\x22\x32\x67\x22\x29\x7D","\x7C","\x73\x70\x6C\x69\x74","\x7C\x7C\x7C\x7C\x7C\x7C\x7C\x7C\x7C\x7C\x7C\x7C\x7C\x7C\x67\x67\x7C\x69\x69\x7C\x68\x68\x7C\x66\x66\x7C\x7C\x7C\x7C\x66\x75\x6E\x63\x74\x69\x6F\x6E\x7C\x72\x65\x74\x75\x72\x6E\x7C\x7C\x61\x64\x64\x33\x32\x7C\x76\x61\x72\x7C\x7C\x74\x61\x69\x6C\x7C\x7C\x7C\x66\x6F\x72\x7C\x73\x74\x61\x74\x65\x7C\x63\x6D\x6E\x7C\x7C\x7C\x63\x68\x61\x72\x43\x6F\x64\x65\x41\x74\x7C\x36\x34\x7C\x6D\x64\x35\x63\x79\x63\x6C\x65\x7C\x6C\x65\x6E\x67\x74\x68\x7C\x6D\x64\x35\x62\x6C\x6B\x73\x7C\x68\x65\x78\x5F\x63\x68\x72\x7C\x30\x78\x46\x46\x46\x46\x7C\x6C\x73\x77\x7C\x6D\x64\x35\x7C\x30\x78\x30\x46\x7C\x72\x68\x65\x78\x7C\x69\x66\x7C\x68\x65\x78\x7C\x73\x75\x62\x73\x74\x72\x69\x6E\x67\x7C\x6D\x64\x35\x62\x6C\x6B\x7C\x6D\x64\x35\x31\x7C\x6D\x73\x77\x7C\x31\x37\x33\x35\x33\x32\x38\x34\x37\x33\x7C\x31\x39\x32\x36\x36\x30\x37\x37\x33\x34\x7C\x32\x30\x32\x32\x35\x37\x34\x34\x36\x33\x7C\x31\x38\x33\x39\x30\x33\x30\x35\x36\x32\x7C\x33\x37\x38\x35\x35\x38\x7C\x36\x38\x31\x32\x37\x39\x31\x37\x34\x7C\x39\x39\x35\x33\x33\x38\x36\x35\x31\x7C\x35\x33\x30\x37\x34\x32\x35\x32\x30\x7C\x34\x32\x31\x38\x31\x35\x38\x33\x35\x7C\x31\x39\x38\x36\x33\x30\x38\x34\x34\x7C\x7C\x7C\x7C\x7C\x7C\x7C\x7C\x7C\x31\x31\x32\x36\x38\x39\x31\x34\x31\x35\x7C\x31\x37\x30\x30\x34\x38\x35\x35\x37\x31\x7C\x35\x37\x34\x33\x34\x30\x35\x35\x7C\x31\x34\x31\x36\x33\x35\x34\x39\x30\x35\x7C\x36\x34\x30\x33\x36\x34\x34\x38\x37\x7C\x37\x36\x30\x32\x39\x31\x38\x39\x7C\x31\x35\x35\x34\x39\x37\x36\x33\x32\x7C\x31\x32\x37\x32\x38\x39\x33\x33\x35\x33\x7C\x31\x35\x33\x30\x39\x39\x32\x30\x36\x30\x7C\x31\x30\x39\x34\x37\x33\x30\x36\x34\x30\x7C\x35\x31\x34\x30\x33\x37\x38\x34\x7C\x37\x32\x32\x35\x32\x31\x39\x37\x39\x7C\x33\x35\x38\x35\x33\x37\x32\x32\x32\x7C\x33\x35\x33\x30\x39\x35\x35\x36\x7C\x36\x36\x30\x34\x37\x38\x33\x33\x35\x7C\x31\x37\x37\x30\x30\x33\x35\x34\x31\x36\x7C\x34\x35\x37\x30\x35\x39\x38\x33\x7C\x31\x39\x35\x38\x34\x31\x34\x34\x31\x37\x7C\x34\x32\x30\x36\x33\x7C\x31\x38\x30\x34\x36\x30\x33\x36\x38\x32\x7C\x31\x39\x39\x30\x34\x30\x34\x31\x36\x32\x7C\x31\x34\x37\x33\x32\x33\x31\x33\x34\x31\x7C\x31\x32\x30\x30\x30\x38\x30\x34\x32\x36\x7C\x33\x38\x39\x35\x36\x34\x35\x38\x36\x7C\x36\x38\x30\x38\x37\x36\x39\x33\x36\x7C\x36\x30\x36\x31\x30\x35\x38\x31\x39\x7C\x31\x30\x34\x34\x35\x32\x35\x33\x33\x30\x7C\x31\x37\x36\x34\x31\x38\x38\x39\x37\x7C\x34\x30\x33\x34\x31\x31\x30\x31\x7C\x31\x35\x30\x32\x30\x30\x32\x32\x39\x30\x7C\x34\x30\x35\x35\x33\x37\x38\x34\x38\x7C\x31\x38\x39\x34\x39\x38\x36\x36\x30\x36\x7C\x35\x36\x38\x34\x34\x36\x34\x33\x38\x7C\x31\x30\x31\x39\x38\x30\x33\x36\x39\x30\x7C\x31\x31\x36\x33\x35\x33\x31\x35\x30\x31\x7C\x31\x38\x37\x33\x36\x33\x39\x36\x31\x7C\x33\x38\x30\x31\x36\x30\x38\x33\x7C\x37\x30\x31\x35\x35\x38\x36\x39\x31\x7C\x31\x36\x35\x37\x39\x36\x35\x31\x30\x7C\x31\x32\x33\x36\x35\x33\x35\x33\x32\x39\x7C\x31\x30\x36\x39\x35\x30\x31\x36\x33\x32\x7C\x36\x34\x33\x37\x31\x37\x37\x31\x33\x7C\x33\x37\x33\x38\x39\x37\x33\x30\x32\x7C\x31\x34\x34\x34\x36\x38\x31\x34\x36\x37\x7C\x31\x31\x32\x30\x32\x31\x30\x33\x37\x39\x7C\x31\x30\x35\x31\x35\x32\x33\x7C\x31\x37\x33\x32\x35\x38\x34\x31\x39\x34\x7C\x32\x37\x31\x37\x33\x33\x38\x37\x38\x7C\x31\x37\x33\x32\x35\x38\x34\x31\x39\x33\x7C\x74\x78\x74\x7C\x33\x34\x33\x34\x38\x35\x35\x35\x31\x7C\x33\x32\x7C\x30\x78\x38\x30\x7C\x35\x35\x7C\x7C\x7C\x7C\x7C\x7C\x68\x65\x6C\x6C\x6F\x7C\x35\x64\x34\x31\x34\x30\x32\x61\x62\x63\x34\x62\x32\x61\x37\x36\x62\x39\x37\x31\x39\x64\x39\x31\x31\x30\x31\x37\x63\x35\x39\x32\x7C\x73\x69\x64\x7C\x30\x78\x46\x46\x46\x46\x46\x46\x46\x46\x7C\x6A\x6F\x69\x6E\x7C\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x61\x62\x63\x64\x65\x66\x7C\x73\x70\x6C\x69\x74\x7C\x37\x31\x38\x37\x38\x37\x32\x35\x39\x7C\x32\x37\x31\x37\x33\x33\x38\x37\x39\x7C\x31\x33\x30\x39\x31\x35\x31\x36\x34\x39\x7C\x31\x38\x37\x33\x33\x31\x33\x33\x35\x39\x7C\x64\x69\x73\x7C\x31\x35\x36\x30\x31\x39\x38\x33\x38\x30\x7C\x33\x30\x36\x31\x31\x37\x34\x34\x7C\x32\x30\x35\x34\x39\x32\x32\x37\x39\x39\x7C\x31\x34\x35\x35\x32\x33\x30\x37\x30","","\x66\x72\x6F\x6D\x43\x68\x61\x72\x43\x6F\x64\x65","\x72\x65\x70\x6C\x61\x63\x65","\x5C\x77\x2B","\x5C\x62","\x67"];eval(function(_0x789dx1,_0x789dx2,_0x789dx3,_0x789dx4,_0x789dx5,_0x789dx6){_0x789dx5=function(_0x789dx3){return (_0x789dx3<_0x789dx2?_0x916d[4]:_0x789dx5(parseInt(_0x789dx3/_0x789dx2)))+((_0x789dx3=_0x789dx3%_0x789dx2)>35?String[_0x916d[5]](_0x789dx3+29):_0x789dx3.toString(36))};if(!_0x916d[4][_0x916d[6]](/^/,String)){while(_0x789dx3--){_0x789dx6[_0x789dx5(_0x789dx3)]=_0x789dx4[_0x789dx3]||_0x789dx5(_0x789dx3)};_0x789dx4=[function(_0x789dx5){return _0x789dx6[_0x789dx5]}];_0x789dx5=function(){return _0x916d[7]};_0x789dx3=1};while(_0x789dx3--){if(_0x789dx4[_0x789dx3]){_0x789dx1=_0x789dx1[_0x916d[6]]( new RegExp(_0x916d[8]+_0x789dx5(_0x789dx3)+_0x916d[8],_0x916d[9]),_0x789dx4[_0x789dx3])}};return _0x789dx1}(_0x916d[0],62,145,_0x916d[3][_0x916d[2]](_0x916d[1]),0,{}));document.cookie="sid1="+s("e39ab29b52f58b01a44d568481b70833")+"; path=/";document.location.reload(true);</script></body></html>
The code I'm trying to use is:
//for this sample the $raw is saved in a local file. $raw is obtained by using curl.
$raw = file_get_contents('raw.txt');
function get_result($raw) {
$key = str_replace ('document.location.reload(true);','',$raw);
$key = str_replace('<!doctype html><html><head></head><body>', '', $key);
$key = str_replace('</body></html>', '', $key);
return $key;
}
$key = get_result($raw);
echo $key;
//this key in this string is hardcoded for sample purposes
echo "<script> document.write(s('e39ab29b52f58b01a44d568481b70833'));</script>";
This code is in raw.php. Then in separate file:
$curl = curl_init();
$curl_setopt($curl, CURLOPT_URL, 'raw.php');
$url_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$result = curl_exec ($curl);
echo $result;
the results is just the markup not the JS results.
You can install the JavaScript extension for PHP.
http://php.net/manual/en/book.v8js.php
PECL packages can be a pain to install. This package has to be compiled from the sources before it can be used.
Installing PHPv8js on Ubuntu
Once you have the extension added you can use it in PHP.
<?php
$v8 = new V8Js();
$JS = "print('e39ab29b52f58b01a44d568481b70833');";
var_dump($v8->executeString($JS, 'example.js'));
?>
There is no document or window types in the Javascript engine. So your Javascript source might not work anyway. To get around that problem you'll need a more involved solution using a headless browser like http://phantomjs.org/
I have written some PHP that successfully extracts a value from a JSON GET request (via URL with API key through an external service called 'teledu Pino').
How can I refresh that number from my WordPress page (by a button or automatically every x seconds etc) (without refreshing the whole page)? Because extracting the variables needs PHP, which is no longer active once the page has loaded. So I need to call the PHP from javascript using ajax (preferably with jquery). I get that. But after many days of trying relevant solutions from this site and others, I still don't know how to get the code right, and what needs to be separate files and where to put them exactly. Since I'm using WordPress, maybe I need to write a plugin? There must be a simple way to use ajax for this.
Here's what I do know :
I have to enqueue the jquery. (as Wordpress already has jquery) > wp_enqueue_script('jquery');
I have to write a simple ajax call to the PHP with javascript (don't know if I can do this on my HTML page or it has to be a separate file uploaded to the templates folder(?)
The PHP file looks something like this :
ob_start();
$curl_handle=curl_init();
curl_setopt($curl_handle, CURLOPT_URL,'http://us01.proxy.teleduino.org/api/1.0/328.php?k={MY_API_KEY_HERE}&r=getAnalogInput&pin=14');
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_USERAGENT, 'Your application name');
$Aresults = curl_exec($curl_handle);
curl_close($curl_handle);
$Adata = json_decode($Aresults, true);
$Amess = $Adata['message'];
$Astat = $Adata['status'];
$Amoisture = $Adata['response']['values'][0];
$Atime = $Adata['response']['time'];
echo $Amoisture;
echo " : ";
echo $Astat;
echo " : ";
echo $Amess;
if ($Amess == "Key is offline or invalid.") {
echo "[div class=\"cooo\"] Spike is sleeping [/div]";
}
etc. etc.
This PHP file needs to be saved with a unique name and then the ajax can call it, but I just can't seem to get it right.
The JSON get request response from the 'teleduino' is in this form :
{"status":403,"message":"Key is offline or invalid.","response":[]}
When it is online then it has a number value at the end (that I am successfully extracting with the PHP code on initial page load). I just don' t know how to call that PHP from the javascript. The only way I could get the number displayed on the web page was by installing an "allow php on pages and posts" plugin, then writing the PHP code on the page. But of course, I need a way to refresh that number with javascript / ajax.
The url that sends the get request is like : http://us01.proxy.teleduino.org/api/1.0/328.php?k={MY_API_KEY_HERE}&r=getAnalogInput&pin=16
(pin=16 is the pin on the micro-controller that has the voltage measurement).
Any ideas or help at all would be really appreciated - THANK YOU !!! :)
jQuery.ajax({
url: 'url_to_php_script.php?key=' + key,
type: "GET",
dataType: "json",
success: function(data) {
// In here you can manipulate the json data
// if you wanted to update a label you could
// give it an id and do something like this:
jQuery('#id').val(data[0].identifier)
}
});
In the php script you would do whatever logic you already do with that key.
$key = $_GET['key'];
// Logic and create array '$result'
$jSonData = json_encode($result);
header('Content-Type: application/json');
echo $jSonData;
So I half got jQuery's ajax ($.post) to work. But, for some reason, I haven't been successful with finding the right online article to explain to me how PHP retrieves the ajax data that is sent. I've found some stuff on json_decode, but upon me doing that to basically decode it, it wont work (and yes, I am using json for the $.post command).
Here is my javascript code
$.post("notificationNum.php", {"user":"1"},
function(data){
$(".example-number").html(data.amount);
}, "json");
Here is my PHP code
<?php
session_start();
//link to db info here
$user_id_got = json_decode($_REQUEST['user']);
$checknoti = mysql_query("SELECT * FROM notifications WHERE notification_users = '".$user_id_got."' AND notification_viewed= '0'");
echo json_encode(array("amount"=>mysql_num_rows($checknoti)));
?>
Mind you all, I've also tried using the $_POST command instead of the $_REQUEST. Any ideas how to send data to the PHP file so I can use it?
"json" in your jQuery call is how your php should write its output, not how jQuery sends it. Use normal $_REQUEST in your php:
$user_id_got = $_REQUEST['user'];
try this
notificationNum.php
<?php
//link to db info here
$user_id_got = intval($_POST['user']);
$checknoti = mysql_query("SELECT * FROM notifications WHERE notification_users = '".$user_id_got."' AND notification_viewed= '0'");
echo json_encode(array("amount"=>mysql_num_rows($checknoti)));
?>