Asked  2 Years ago    Answers:  5   Viewed   32 times

I need to get the json data from, http://vortaro.us.to/ajax/epo/eng/ + 'word'+ "/?callback=?" working example (not enough reputation)

I know how to do it in javascript, But I need my php file to get this data, It needs to be server side, Thanks I'm new I have spent all day trying to figure this out. fopen and fread isn't working,

<?php
$vorto = $_GET['vorto']; // Get the Word from Outer Space and Search for it!

if (isset($vorto))
    {
    echo $vorto;
    } else {
        $Help = "No Vorto -> add ?vorto=TheWordYouWant to the end of this website";
        echo $Help;
    }
$url1 = "http://vortaro.us.to/ajax/epo/eng/"; 
$url2 = "/?callback=?";
$finalurl= $url1 . $vorto . $url2;

/*
PLEASE HELP

$v1 = fopen($finalurl ,"r");
echo $v1;


$frv1 = fread($v1,filesize($v1));
echo $frv1 ;

*/

?>

 Answers

3

file_get_contents() can be used on a URL. A simple and convenient way to handle http page download.

That done, you can use json_decode() to parse the data into something useful.

Monday, September 5, 2022
 
3

What a HORRENDOUS debug session.. well there's good news.. I figured it out..

I started looking at it using AJAX and logging it with Firebug... and it turns out json_decode (or eval by the way) cannot handle &quot;, which is what PHPUnit sends back (Come on Sebastian!), so to fix it:

$json = str_replace('&quot;', '"', $json);

Now I thought they were the same.. maybe someone can enlighten me..

Friday, December 23, 2022
3

Yes, it can be because it is an attacker controlled variable. It can lead to vulnerabilities such as xss.

<?php print $_SERVER['PHP_SELF']?>

http://localhost/self.php/<script>alert(1)</script>

If possilbe you should use a variable that the attacker can't control like $_SERVER["SCRIPT_FILENAME"]. There are a couple of others, just check the phpinfo().

Thursday, September 22, 2022
1

When dealing with jQuery AJAX using a data type of JSON, any notice, warning or error produced by the server side script will cause issues. The reason being is the outputted PHP errors break the JSON encoding that jQuery is expecting.

I suspect the two environments are not identical, perhaps a different PHP version, missing PHP extension or different settings in the php.ini file.

The best thing to do is to use the provided jQuery AJAX error callback to console log any errors allowing you to essentially troubleshoot any issues being thrown by the server side script.

!!! EDIT 3 !!!

Client Code

$.ajax({
    type: "POST",
    dataType: "json",
    url: "http://myurl.com/jsonpost.php", 
    data: data,
    success: function(response) {
        console.log(response);
    },
    error: function(xhr, status, error) {
       console.log(xhr);
       console.log(status);
       console.log(error);
    }
});

Server Side Code

header("Access-Control-Allow-Origin: *");
header('Content-Type: application/json');

echo json_encode(array('success' => 'yes'));

Using this bare bones version of your code I can successfully make a cross domain request and console log the response. If you implement this code and it still does not work there is something else at play at the server and/or network level.

Sunday, September 11, 2022
3

Debugging suggestion:

Check the output of json_last_error(). It should give you an exact reason why it doesn't work. Available from PHP 5.3.0 only, though.

The reason:

JSONP is not identical with JSON. It contains extra data that breaks json_decode().

Solution:

Remove the extra brackets using substr($AVDecode, 1, strlen($AVDecode)-2)

Thursday, December 1, 2022
 
vladfr
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :
 

Browse Other Code Languages