Loading from jenkins job to PHP - javascript

I am able to use the Jenkins API to get information about my build via the url http://localhost:1111/job/api/json
What is inside this jenkins doesn't matter.
When I use json file on my PC I can get values for example in a way:
$string = file_get_contents($fileName.'.json');
$json_a = json_decode($string, true);
echo $json_a['something']['somethingdeeper'];
I'm looking for something like, but of course instead of file an URL:
$string = file_get_contents('http://localhost:1111/job/api/json');
$json_a = json_decode($string, true);
echo $json_a['something']['somethingdeeper'];
Any ideas? Didn't find a right solution, thanks.

If this is the url of your Jenkins job
http://localhost:1111/job/projectx
you should add the api/json add the end of the url.
This wil do the trick
$string = file_get_contents('http://localhost:1111/job/projectx/api/json');
$json_a = json_decode($string, true);
var_dump($json_a);
//echo $json_a['something']['somethingdeeper'];

Related

Process a POST request with PHP from a JS fetch [duplicate]

I’m trying to receive a JSON POST on a payment interface website, but I can’t decode it.
When I print :
echo $_POST;
I get:
Array
I get nothing when I try this:
if ( $_POST ) {
foreach ( $_POST as $key => $value ) {
echo "llave: ".$key."- Valor:".$value."<br />";
}
}
I get nothing when I try this:
$string = $_POST['operation'];
$var = json_decode($string);
echo $var;
I get NULL when I try this:
$data = json_decode( file_get_contents('php://input') );
var_dump( $data->operation );
When I do:
$data = json_decode(file_get_contents('php://input'), true);
var_dump($data);
I get:
NULL
The JSON format is (according to payment site documentation):
{
"operacion": {
"tok": "[generated token]",
"shop_id": "12313",
"respuesta": "S",
"respuesta_details": "respuesta S",
"extended_respuesta_description": "respuesta extendida",
"moneda": "PYG",
"monto": "10100.00",
"authorization_number": "123456",
"ticket_number": "123456789123456",
"response_code": "00",
"response_description": "Transacción aprobada.",
"security_information": {
"customer_ip": "123.123.123.123",
"card_source": "I",
"card_country": "Croacia",
"version": "0.3",
"risk_index": "0"
}
}
}
The payment site log says everything is OK. What’s the problem?
Try;
$data = json_decode(file_get_contents('php://input'), true);
print_r($data);
echo $data["operacion"];
From your json and your code, it looks like you have spelled the word operation correctly on your end, but it isn't in the json.
EDIT
Maybe also worth trying to echo the json string from php://input.
echo file_get_contents('php://input');
If you already have your parameters set like $_POST['eg'] for example and you don't wish to change it, simply do it like this:
$_POST = json_decode(file_get_contents('php://input'), true);
This will save you the hassle of changing all $_POST to something else and allow you to still make normal post requests if you wish to take this line out.
It is worth pointing out that if you use json_decode(file_get_contents("php://input")) (as others have mentioned), this will fail if the string is not valid JSON.
This can be simply resolved by first checking if the JSON is valid. i.e.
function isValidJSON($str) {
json_decode($str);
return json_last_error() == JSON_ERROR_NONE;
}
$json_params = file_get_contents("php://input");
if (strlen($json_params) > 0 && isValidJSON($json_params))
$decoded_params = json_decode($json_params);
Edit: Note that removing strlen($json_params) above may result in subtle errors, as json_last_error() does not change when null or a blank string is passed, as shown here:
http://ideone.com/va3u8U
Use $HTTP_RAW_POST_DATA instead of $_POST.
It will give you POST data as is.
You will be able to decode it using json_decode() later.
Read the doc:
In general, php://input should be used instead of $HTTP_RAW_POST_DATA.
as in the php Manual
$data = file_get_contents('php://input');
echo $data;
This worked for me.
You can use bellow like..
Post JSON like bellow
Get data from php project user bellow like
// takes raw data from the request
$json = file_get_contents('php://input');
// Converts it into a PHP object
$data = json_decode($json, true);
echo $data['requestCode'];
echo $data['mobileNo'];
echo $data['password'];
Quite late.
It seems, (OP) had already tried all the answers given to him.
Still if you (OP) were not receiving what had been passed to the ".PHP" file, error could be, incorrect URL.
Check whether you are calling the correct ".PHP" file.
(spelling mistake or capital letter in URL)
and most important
Check whether your URL has "s" (secure) after "http".
Example:
"http://yourdomain.com/read_result.php"
should be
"https://yourdomain.com/read_result.php"
or either way.
add or remove the "s" to match your URL.
If all of the above answers still leads you to NULL input for POST, note that POST/JSON in a localhost setting, it could be because you are not using SSL. (provided you are HTTP with tcp/tls and not udp/quic)
PHP://input will be null on non-https and if you have a redirect in the flow, trying configuring https on your local as standard practice to avoid various issues with security/xss etc
The decoding might be failing (and returning null) because of php magic quotes.
If magic quotes is turned on anything read from _POST/_REQUEST/etc. will have special characters such as "\ that are also part of JSON escaped. Trying to json_decode( this escaped string will fail. It is a deprecated feature still turned on with some hosters.
Workaround that checks if magic quotes are turned on and if so removes them:
function strip_magic_slashes($str) {
return get_magic_quotes_gpc() ? stripslashes($str) : $str;
}
$operation = json_decode(strip_magic_slashes($_POST['operation']));
I got "null" when I tried to retrieve a posted data in PHP
{
"product_id": "48",
"customer_id": "2",
"location": "shelf", // shelf, store <-- comments create php problems
"damage_types":{"Pests":1, "Poke":0, "Tear":0}
// "picture":"jhgkuignk" <-- comments create php problems
}
You should avoid commenting JSON code even if it shows no errors
I'd like to post an answer that also uses curl to get the contents, and mpdf to save the results to a pdf, so you get all the steps of a tipical use case. It's only raw code (so to be adapted to your needs), but it works.
// import mpdf somewhere
require_once dirname(__FILE__) . '/mpdf/vendor/autoload.php';
// get mpdf instance
$mpdf = new \Mpdf\Mpdf();
// src php file
$mysrcfile = 'http://www.somesite.com/somedir/mysrcfile.php';
// where we want to save the pdf
$mydestination = 'http://www.somesite.com/somedir/mypdffile.pdf';
// encode $_POST data to json
$json = json_encode($_POST);
// init curl > pass the url of the php file we want to pass
// data to and then print out to pdf
$ch = curl_init($mysrcfile);
// tell not to echo the results
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1 );
// set the proper headers
curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Content-Type: application/json', 'Content-Length: ' . strlen($json) ]);
// pass the json data to $mysrcfile
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
// exec curl and save results
$html = curl_exec($ch);
curl_close($ch);
// parse html and then save to a pdf file
$mpdf->WriteHTML($html);
$this->mpdf->Output($mydestination, \Mpdf\Output\Destination::FILE);
In $mysrcfile I'll read json data like this (as stated on previous answers):
$data = json_decode(file_get_contents('php://input'));
// (then process it and build the page source)

Server error 500 in PHP

So today I have another small little issue with my PHP, that is causing me to get a server error. You see, I have this javascript function:
$.post('script.php', { limit: str }, function(result) {
console.log(result);
});
which of course makes a call to my php file:
require_once("../data/db-settings.php");
require_once("../data/file.php");
global $pdo;
$list = array();
$limit = $_POST["limit"];
chop($limit, ";");
$stmt = $pdo->prepare("SELECT cust_id, cust_addr FROM project WHERE " . $limit . " = cust_id");
$stmt->execute();
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$list[] = $row;
}
echo $list;
The point of the php is to grab some information from a database that a user can dynamically change and use. The issue, I'm assuming, is with how I'm using PDO, because the code I'm using is in working order in another section. I also know that my function call is sending data and working properly, because when I check for just what I send, it sends properly.
Thanks for any help guys.
Check your query FROMproject can not be together.
Your query should look like this:
$pdo->prepare("SELECT cust_id, cust_addr FROM project WHERE " . $limit . " = cust_id");
It is an unobvious error!
So you step by step following the : http://pcsupport.about.com/od/findbyerrormessage/a/500servererror.htm
PDO doesn't throw Internal server error. Must be require_once.
checkout db-settings.php and file.php files. Require_once throws 500 error if it can't find files.
If the paths are correct, then check out included files.
proper way: check your log files.

PHP Curl - Possible to retrieve Javascript results?

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/

how to create a dynamic redirect link with js and php?

PHP has no relation and behavior with browsers and in some times it makes some mistake. For example we can't set for header function to redirect to a page in a blank page. Because it has no relation with the browsers and for doing this, we should use JS .Now I'm mixing these two languages to reaching the goal.
<?php
$word = $_POST["tagTxt"];
$tag = "https://www.example.com/" . $word;
echo '<script>window.open("Location: <?php $search;?>");</script>';
?>
The goal is this code but it doesn't work. I want get a string from a first page then post it with post method and then past it to a static address for redirecting with blank target. Thanks.
I think you are trying to open a new url when the page is loaded.
So if you trying to do this check the code below.
This way you are mixing the parameters received from client, processing them and them sending back to the client.
Then you use the javascript with the window.onload function to execute the redirect page when the page is loaded with the received parameter.
<?php
$word = "1";
$tag = "www.yahoo.com/" . $word;
echo '<script text="text/javascript">window.onload = function(){window.open("'.$tag.'");} </script>';
?>
Not sure I fully understood your question, but have you tried something like this:
<?php header("Location: $search");
If you are "changing" the web page. Do not use window.open
Use window.location = 'http://www.google.com/';
in your example do this
<?php
$word = $_POST["tagTxt"];
$tag = "https://www.example.com/" . $word;
echo "<script>window.location = '$tag';</script>";
?>
(copy the code above, and it should work perfectly for what you're asking for)
I fount the way.
thanks all.
<?php
$word = $_POST["tagTxt"];
$tag = "https://www.example.com/" . $word;
echo "<script>window.open( '$tag' );</script>";
?>

PHP json_encode then getJSON issue in javascript

Sorry if this is still another thread on the subject but I am struggling since hours but could not find the solution.
I am trying to get data from a Mysql database, create a JSON with php, then parse this JSON in javascript.
Here is my json.php
<?php
$link = mysql_pconnect("localhost", "root", "") or die("Could not connect". mysql_error());
mysql_select_db("people") or die("Could not select database");
$arr = array();
$rs = mysql_query("SELECT * FROM nom");
while($obj = mysql_fetch_object($rs)) {
$arr[] = $obj;
}
echo '{"users":',json_encode($arr),'}';
/*
//The json object is :
{"users":[{"id":"1","prenom":"Alain","age":"23"},{"id":"2","prenom":"Bruno","age":"24"}]}
*/
?>
Then I try to parse it into java
<div id="placeholder6"></div>
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script>
$.getJSON('http://localhost/json.php', function(data) {
var output="<ul>";
for (var i in data.users) {
output+="<li>" + data.users[i].id + " " + data.users[i].prenom + "--" + data.users[i].age+"</li>";
}
output+="</ul>";
document.getElementById("placeholder6").innerHTML=output;
});
</script>
when I replace localhost/json.php by the result in a file data.json, it works, when I open localhost/json.php with firefox, I can see the JSON table...so I do not know why it does not work with localhost/json.php.
Is my php code or javascript code wrong ?
Thanks in advance for your help !
Try this method
var users= data.users;
$.each(users,function(index,users){
console.log(users.prenom); /// and users.id etc
})
Try This in php
while($obj = mysql_fetch_object($rs)) {
$arr[] = $obj;
}
$return = new stdClass();
$return ->users = $arr;
echo json_encode($return);
I think your web application server (like Apache or nginx) sends Content-Type: text/html by default or something of that sort for your json.php file. On the other hand, it looks like $.getJSON method requires a application/json content type field.
Try adding:
header("Content-Type: application/json");
to the top of the json.php file.
Edit - additional info:
I couldn't find in the original documentation of the $.getJSON method whether it, in fact, requires the specific Content-Type so I looked into the source code:
https://github.com/jquery/jquery/blob/1.7.1/src/ajax.js#L294
Here is the line of source code for jQuery 1.7.1 (which is the version you said that you use, I hope) for getJSON and as you can see, it calls jQuery.get with the last argument set to "json".
In turn, the jQuery.get documentation reveals that this argument means:
The type of data expected from the server. Default: Intelligent Guess (xml, json, script, or html).
from: http://api.jquery.com/jQuery.get/
Thus, when you call $.getJSON("/url/to/file", ...) that first argument is expected to be a JSON. If you add the PHP code from the top of my answer, your web application server will mask the output of the php file as a JSON.

Categories