PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Sun Oct 21, 2018 2:09 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Fri Dec 15, 2017 4:09 pm 
Offline
Forum Commoner

Joined: Thu Aug 10, 2017 4:48 pm
Posts: 32
Hi,

Here is another json question. The code is the same but for a diferent service. The idea is to fetch the IPs and show to the user by getting the string "ip_str". Also if this is done right is it possible to save every "ip_str" as a individual string that can be called later?

Quote:
IP: <a id='show'></a>

<script>
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var myObj = JSON.parse(this.responseText);
document.getElementById("show").innerHTML = myObj.matches.ip_str;
}
};
xmlhttp.open("GET", "https://api.shodan.io/shodan/host/search?key=CevVNIYrV6gUzMoxiMhcaO3JIJOmpCY1&facets=&query=xampp", true);
xmlhttp.send();
</script>


Thanks
I'm a noob i know. If possible include a few references/examples to how Json works.


Top
 Profile  
 
PostPosted: Fri Dec 15, 2017 4:25 pm 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6617
Location: WA, USA
myObj.matches is an array, not an object. Use a loop.


Top
 Profile  
 
PostPosted: Sat Dec 16, 2017 6:38 am 
Offline
Forum Commoner

Joined: Thu Aug 10, 2017 4:48 pm
Posts: 32
Fixed thanks...

Also another question not related to json but with XMLHttp. I want to send basic http auth header using XMLHttp and make an action afterwards.

I will have to use a code similar to the below, right?
Quote:
<script>
var xmlhttp = new XMLHttpRequest();
xmlhttp.setRequestHeader("Authorization", "Basic" + btoa("username:password"));
xmlhttp.open("GET", "http://127.0.0.1", true);
xmlhttp.send();

// And after authentication
xmlhttp2.open("GET", "http://127.0.0.1/test.php?add=entry", true);
xmlhttp2.send();
</script>


(I know that the code is not correct, how van i make it run?)


Top
 Profile  
 
PostPosted: Sat Dec 16, 2017 7:54 am 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6617
Location: WA, USA
setRequestHeader() goes after open() and before send(), but otherwise yes.


Top
 Profile  
 
PostPosted: Sat Dec 16, 2017 1:54 pm 
Offline
Forum Commoner

Joined: Thu Aug 10, 2017 4:48 pm
Posts: 32
Quote:
<input type="submit" name="submit" onclick=open();>
<script>
function = open() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "http://127.0.0.1", true);
xmlhttp.setRequestHeader("Authorization", "Basic" + btoa("username:password"));
xmlhttp.send();

// And after authentication
xmlhttp2.open("GET", "http://127.0.0.1/test.php?add=entry", true);
xmlhttp2.send();
}
</script>


I have made the adjustments but it doesn't fetch the page. I have tried with two different http servers and check the logs and it isn't nothing there. Do you know what is wrong with?

Thanks


Top
 Profile  
 
PostPosted: Sat Dec 16, 2017 6:42 pm 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6617
Location: WA, USA
1. Your Javascript syntax for a function is wrong.
2. There needs to be a space between the "Basic" and the encoded username and password
3. xmlhttp2 is undefined.
4. You don't seem to be passing or receiving any data.


Top
 Profile  
 
PostPosted: Sat Oct 06, 2018 10:36 am 
Offline
Forum Commoner

Joined: Thu Aug 10, 2017 4:48 pm
Posts: 32
@requinix - I found the solution...

Thanks for help provided


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: Exabot [Bot] and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group