This question already has answers here:
How to get client's IP address using JavaScript? [closed]
(31 answers)
Closed 7 years ago.
How to make function to get visitor ip?
I try fixed using related post below
Tracking visitor IP/Clicks in PHP
How to get client's IP address using javascript only?
but cannot fixed yet..
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Sample Tracking Visitor</title>
<script type="text/javascript">
function tracking_vistors(cid,url,curl,camp,type) {
var user_agent = getuseragent();
var ip = myIP(); // how to make this function track visitor ip
var publisher = "2000000001";
var data = "cid="+cid+"&curl="+curl+"&camp="+camp+"&type="+type+"&url="+url+"&ip="+ip+"&user_agent="+user_agent+"&publisher="+publisher;
$.ajax({
type: 'POST',
url: 'widget/clicktracker.php',
data: data
});
}
</script>
</head>
<body>
</body>
</html>
You can't find the IP from the javascript. You've to send the call to internet or any other service which can return your IP..
I'm adding one service url which will return your IP.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Sample Tracking Visitor</title>
<script type="text/javascript" src="http://l2.io/ip.js?var=myip"></script>
<script type="text/javascript">
function tracking_vistors(cid,url,curl,camp,type) {
var user_agent = getuseragent();
var ip = myip; // how to make this function track visitor ip
var publisher = "2000000001";
var data = "cid="+cid+"&curl="+curl+"&camp="+camp+"&type="+type+"&url="+url+"&ip="+ip+"&user_agent="+user_agent+"&publisher="+publisher;
$.ajax({
type: 'POST',
url: 'widget/clicktracker.php',
data: data
});
}
</script>
</head>
<body>
</body>
</html>
This line will send the request to l2.io domain and return the ip in myip variable which I used in the code above.
Related
I read this, but it did not solve my issue, and as it is old, I'm posting a new question.
I've the below code, that is recieving a SSE from GoLang server, but the Arabic script is not encoded probely:
<!DOCTYPE html>
<html lang="ar-AR">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://cdn.rawgit.com/davidshimjs/qrcodejs/gh-pages/qrcode.min.js"></script>
</head>
<body>
<div id="msg"></div>
</body>
<script src="socket.js" charset="utf-8" type="text/javascript"></script>
</html>
And
var source = new EventSource("http://localhost:1234/sse/signal");
source.onmessage = function (event) {
var message = event.data
document.querySelector('#msg').innerHTML = message;
}
And sample output I get is:
data: {
"IsFromMe": false,
"IsGroup": false,
"ID": "26DE3A6A0AEA98406D286E9C58C40114",
"PushName": "إدارة قطو٠و Øلا",
"Timestamp": "2022-07-05T09:45:46+03:00",
}
The PushName above should be Arabic script!
As mentioned by #slebetman in his comments, the correct answer is to send the data from the server as utf-8 which is done in my case as I'm sending data as streaming, by sending the Content-Type as text/event-stream; charset=utf-8
My code in the GoLang server became:
w.Header().Set("Content-Type", "text/event-stream; charset=utf-8")
I am using Google Distance Matrix API for my web application. When I tried loading the map, it shows me an error in the console log. I am new to the API and would appreciate any help. Many thanks! :)
Here is a screenshot of the errors in the console log
Below is my code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Carpark Demo Code</title>
<!--<link href="https://fonts.googleapis.com/css2?family=Poppins:wght#400;600&display=swap" rel="stylesheet">-->
<style>
</style>
</head>
<body>
<script src="https://code.jquery.com/jquery-3.4.1.min.js" type="text/javascript"></script>
<script type="text/json" src="https://maps.googleapis.com/maps/api/distancematrix/json?&key=AIzaSyAvlb7x4ZCfxvpxV90ha3g_YbaYfHPvfvk"></script>
<script>
$(function(){ // ready function
displayLiveData();
googleDistanceCalc();
});
function displayLiveData(){ // 1st Function - carpark details, address
$.ajax({
type: "GET",
url: 'https://maps.googleapis.com/maps/api/distancematrix/json?&key=AIzaSyAvlb7x4ZCfxvpxV90ha3g_YbaYfHPvfvk',
dataType: 'json'
})
.done(function(json) { /* same as ready function, when data finishes loading and do something after */
console.log("Successfully Loaded!");
})
.fail(function() {
console.log("Loading Error.");
});
}
</script>
</body>
</html>
Thanks for the help!
I have to generate a popup in flutter that is coming from backend in the html, css and javascript form
In my case I'm using a korean based software named Band that is going to provide me google, fb and band login.
It's working is something like passport.js just in my case I've to use band but the issue is that when I try to render the response, the flutter is treating javascript as string.
Band developers guide link
Using band api I have got the response in html and javascript, something like given below
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="utf-8">
<meta name="keywords" content="BAND" />
<meta name="description" content="밴드 방문을 환영합니다. 로그인하고 그룹 멤버들과 대화에 참여해 보세요." />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>로그인 | 밴드</title>
<script type="text/javascript">...</script>
</head>
<body>...</body>
</html>
Preview of response using postman software
Code snippet I'm using in flutter to render the response is given below
Future getJSONData() async
{
var redirectUri = Uri.encodeFull("apiredirection.php");
var response = await http.get(
Uri.encodeFull(
"https://auth.band.us/oauth2/authorize?redirect_uri={TEST_URL}" +
redirectUri),
headers: {"Accept": "application/text"});
this.setState(() {
data = response.body;
return data;
});
return data;
}
#override
Widget build(BuildContext context)
{
String html = data.toString();
return new MaterialApp(
home: new Scaffold(
body: new Container(
child: new HtmlView(
data: html),),),),
}
If the response that you need to display is in html String, you can use webview_flutter to render this on your app with a WebView.
// Let htmlData contain the html response
String htmlData = '''<!DOCTYPE html><html>...</html>''';
await webViewController.loadHtmlString(htmlData);
Then set webViewController as the WebViewController of your WebView.
I want to open the response that I get from my PHP server in the In App Browser in a new window.
I am creating an app using Ionic and using PHP as a back end. I have full control of the php server.
I am making the ajax call like so:
$(document).ready( function() {
$("#paybutton").click(function() {
var params = "projectpaymentoption=1197&id=",
usernamepay = window.localStorage.getItem("username"),
paymenturl = params + usernamepay;
$.ajax({
type: 'POST',
url: 'http://www.blabla.com/encode.php',
data: $.param({"paymenturl": paymenturl}),
success: function(output) {
window.open('output','_blank','location=no','closebuttoncaption=Zurück');
console.log(result);
}
});
});
});
Now I want to open the output in a new inappbrowser windows.
The output i am throwing out is as follows
<?php
ob_start();
include_once('includes/headers.php');
require_once('includes/connection.php');
require_once('includes/functions.php');
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
</head>
<?php
include($filePath);
?>
It is a dynamically generated php page. An not an url.
How can I show this page in the inappbrowser
I am trying to find a workaround for using POST request, because I cannot use form, pass parameter and redirect to another page without displaying the parameter in the URL. I heard it is possible to do that via XHR GET request but I am not sure how. I have also tried it with POST.
Index.jsp (Peter is my example of POST via form, which works, but I cannot use. George is my example of GET. I can see that the function HttpGet is called and the responseText is the html of helloworld.jsp. Sam is my example of POST. I can see that the parameter is passed to the controller and added to mv but it stops short of redirecting to helloworld.jsp.)
<%# page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Spring 4 MVC - HelloWorld Index Page</title>
<script type="text/javascript">
function httpGet(theUrl)
{
var xmlHttp = null;
alert('httpGet is called');
alert(theUrl);
xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", theUrl, false );
xmlHttp.send( null );
alert(xmlHttp.responseText);
return xmlHttp.responseText;
}
function doPost() {
var url = "http://localhost:8080/HelloWorld/hello";
var params = "name=Sam";
alert('Entered Sam');
var xhr = new XMLHttpRequest();
xhr.open("POST", url, true);
//Send the proper header information along with the request
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.send(params);
}
</script>
</head>
<body>
<h2>Hello World</h2>
<form action="hello" id="test" method="POST" style="display:none;">
<input type="hidden" name="name" value="Eric" />
<input type="hidden" name="lastname" value="Peters" />
<button>Go to user 123</button>
</form>
<a href="javascript:;" onclick="javascript:
document.getElementById('test').submit()">Eric Peters</a><br/>
George
Sam
</body>
</html>
Controller:
package com.programcreek.helloworld.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
#Controller
public class HelloWorldController {
String message = "Welcome to Spring MVC!";
#RequestMapping("/hello")
public ModelAndView showMessage(
#RequestParam(value = "name", required = true) String name,
#RequestParam(value = "lastname", required = false, defaultValue = "Doe") String lastname) {
System.out.println("in controller");
ModelAndView mv = new ModelAndView("helloworld");
mv.addObject("message", message);
mv.addObject("name", name);
mv.addObject("lastname", lastname);
return mv;
}
}
Helloworld.jsp
<%# page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Spring 4 MVC -HelloWorld</title>
</head>
<body>
<center>
<h2>Hello World</h2>
<h2>
${message} ${name} ${lastname}
</h2>
</center>
</body>
</html>
My questions are: 1) is it possible to use XHR get or post and not show the parameter in the URL? 2) which method (george or sam) is close, if any, and which files should I look at changing to make it redirect to helloworld.jsp (controller or index.jsp)? Thank you for your help.