I'm doing an advertising network as a project for BS degree.
I;m trying to identify the same user across multiple websites. I have a USER table in my database with ID as an auto_increment number.
In the websites i'm tracking i included the following Javascript :
function OnLoad()
{
var requestURI = window.location;
var resolution = screen.width + 'x' + screen.height;
var colorDepth = screen.colorDepth;
var query = '?requestURI=' + encodeURIComponent(requestURI)
+ '&resolution=' + encodeURIComponent(resolution)
+ '&websiteid=' + encodeURIComponent(id);
document.getElementById("body").innerHTML = "<img src ='http://dan-vaio:8080/licenta/bannerimg.gif'" + query + " width = 500 height = 200 />"; // this is the place where i want to display my banner
}
On the server side A banner choosing algorithm is called and i get a queue of 5 banners that i want to display to this user. (only if the user acceseses the first time this website, otherwise i'd have to display the remaining banners in the queue. Haven't figured out how to do this either, could i keep the queue in a session ? ).
The question is : If i add a cookie to the response in the servlet, will it be avaiable when the same user acceses another website ?
i have this :
Cookie cookie = new Cookie("DisplayedBanners",visitedBanners); //
response.addCookie(cookie);
How can i uniquely identify an user? How to generate a unique ID to keep in the cookie and in the database, so when the same user accesses another website and calls my servlet i will know who he is.
Thanks a lot.
Banner queue will not work either if you use session for this. Session is maintained on the server. If you go to other site the same old session will not work here.
I would suggest that you keep this information in database.
So keep the last_shown_banner_tag with a user_id in a single table.
This table should be common among the websites.
Here it is explained how to do multidomain cookies, but in PHP (requires tweaking the Apache)
http://www.tutorialized.com/tutorial/Implementing-Cross-Domain-Cookies/372
Related
In Java, is there a way to make a client/server system for a game without having to enter ips (like in Minecraft).
But instead, have it automatically connect the user to a game when he requests to join one (like in Fortnite, or surviv.io).
The only method I current know for client/server is having to give each user a server ip to connect to (like in Minecraft), so I was wondering if I could do it this way.
Thanks in advance.
IMHO, I think in all ".io" games, they are only hiding the registration processing. In my case, the previous game I made had a feature calls "Quick Play".
When a player uses that playing method and first time joins the game, I get his device's ID (for example in Android) then use it as a unique ID for that player in-game (I'm not sure about iOS but you can get that unique value in Android).
You can see the example below:
_on(TEvent.CONNECTION_SUCCESS, args -> {
var connection = Connection.convert(args[0]);
var message = TObject.convert(args[1]);
info("CONNECTION", connection.getAddress());
// Allow the connection login into server (become a player)
String username = message.getString("u");
// Should confirm that credentials by data from database or other services, here
// is only for testing
_playerApi.login(new PlayerLogin(username), connection);
return null;
});
Now when a new user login, he will send his device's ID and I can treat him a new player and make that ID as his name (or making a randomized name for him)
You can see more detail in the link below:
Login Example
I'm writing an integration API in Java for IBM Domino 10, I want to perform resource (room) reservations, fetch and update them from an external source.
So far, I successfully created an entry in current user's calendar (current session) and the reservation is also successfull, however I want to create reservations as certain users (personification), since only one user is configured to use my API database. So the main user is used to do everything, but I'd like to pass him the credentials of other users and he should create the events & reservations in their calendars. I can verify if an user exists & if his password is correct, but I don't know how could I open his calendar because it's session based.
My current code:
Database mdb = session.getDbDirectory(session.getServerName()).openMailDatabase();
NotesCalendar cal = session.getCalendar(mdb);
java.text.SimpleDateFormat datefmt = new java.text.SimpleDateFormat("yyyyMMdd'T'HHmmss'Z'");
String dStart = datefmt.format(dtStart);
String dEnd = datefmt.format(dtEnd);
Name nnOrganizer = session.createName(session.getEffectiveUserName());
String iCalEntry = "BEGIN:VCALENDAR\n" +
"PRODID:-//Test//Reservation API//EN\n" +
"VERSION:2.0\n" +
"BEGIN:VEVENT\n" +
"DTSTART:" + dStart + "\n" +
"DTEND:" + dEnd + "\n" +
"SUMMARY:Sample Meeting\n" +
"DESCRIPTION:TEST\n" +
"ORGANIZER;CN=admin/O=Corp:mailto:test#test.test\n" +
"ATTENDEE;ROLE=CHAIR;PARTSTAT=ACCEPTED;" + nnOrganizer.getCanonical() + ";RSVP=false:mailto:test#test.test\n" +
"ATTENDEE;CUTYPE=ROOM;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;" + nnResource.getCanonical() + ";RSVP=true:mailto:room#test.test\n" +
"END:VEVENT\n" +
"END:VCALENDAR\n";
NotesCalendarEntry entry = cal.createEntry(iCalEntry);
System.out.println("calendar uid " + entry.getUID());
How could I make this work with any user I want? So it's not using session.getCalendar() but something else, so I could create an entry in another user's calendar.
Also, how can I programatically get the organizer's & room's email addresses? As for now, they are hardcoded. I know I could do a directory lookup, but sometimes the email (internet address) isn't configured, and lookupNames returns nothing. Notes client somehow bypasses that and creates an email like Name_Surname/server#Corp, is it enough?
Edit
I achieved what I wanted by using the REST Service (CustomServiceBean) and NotesCalendar for creating/updating/deleting reservations, paired with direct document access to check for conflicts and read detailed room & reservation data. Everything works fine so far, reservations are visible in both user's calendar and the dtabase. However when I re-installed the server from scratch and added the database with rest service, I couldn't access the api with my default admin user (403 forbidden, You are forbidden to perform this operation ) server logs:
HTTP JVM: CLFAD0229E: Security exception occurred servicing request for: /db.nsf/services.xsp/api - HTTP Code: 403. For more detailed information, please consult error-log-0.xml
When I added the admin user to Configuration->Current Server Document->Security->Sign or run unrestricted methods and operations, it starts working correctly, even when accessing the API with newly registered users (that weren't assigned any groups, permissions, nothing at all just an internet password & address and they were created by the admin account)
Will this work correctly? I need to access the API from accounts of normal users, because I need to create entries in user's calendars.
I have two user: X and Y. And one page: Page Z. To access page Z I have a link.
If page Z is already open in user X browser I want the link to be disabled and denied the access to the page to user Y.
How can I do that?
Which language is the most apropriate to do that (jQuery, Php, etc)?
do not listen to any of these answers.
you can do this(although it is true that its kind of awkward)
you need PHP javascript (use j-query) and mysql. Your going to want to create a php script that gives the first user on a variable session, and every couple seconds or so your ajax will keep sending the db a script with php time(); when the second user comes on the php page will ask the db if there are any refreshes within 4 seconds, meaning that if the first user is still logged on there will be no more than a three second delay from the db time. and if there isn't that means the user is idle or has gone off the page and you can allow access. to redirect with php you can user the header function. If you are interested in EXACTLY how to do this upgrade my response and reply because it is pretty long and i do not want to write it for no reason.
this is the page you want people to go on:
$times = time();
$num = $times + 10000;
mysql_connect("localhost", "dbname", "password") or
die("Could not connect: " . mysql_error());
mysql_select_db("dbname");
$result = mysql_query("SELECT FROM $tablename WHERE areloggedin > $num);
$num=mysql_numrows($result);
if( $num < 0 ){
header('Location: http://redirectpage.html');
}else{
$times = time();
$con = mysql_connect("localhost","username","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("dbname", $con);
$qry = mysql_query("UPDATE
$tbalename SET
`areloggedin`= '$times'
WHERE id = $variable_seession_foruser ");
$result = #mysql_query($qry);
}
?>
(your html)
function ok(){
$.get("php/foo.php" , function(data) {
});
setIntreval(ok,3000);
//sepearate php file named foo.php
What you can is that create a boolean variable on server side and track it. When user if page Z is accessed by someone then set this variable true and while someone else is trying to open that link then check if boolean variable is true then stop them to redirect to that page and if it is false then take them to page Z. Once user left the page then set boolean variable to false.
This could be one way to achieve it but still I do not think that it is that straight forward. You will face many obstacles while implementing it.
just trying to come up with a quick implementation/workaround for something like this:
What you need
System-wide cache, (APC or SESSIONS won't do). You need something like memcached or redis so that multiple threads can access the same cache.
OR just a database+crontabs I guess (but cache is preferred)
PHP/Server-side scripting
Javscript-enabled clients
Strategy
Javascript makes an HTTP request every X (TTL) seconds. This request sets the key 'occupied' (in your chosen cache) to the clients IP with a cache-ttl of X+5 seconds. (If you opt for DB you'll need a cronjob reseting the entry every X seconds)
If a user tries to access the page and the 'key' !== their IP address, deny access.
Caveats
ONLY allow users to edit if they have JS enabled, display warning otherwise
Puts the trust in your users, they can bypass this easily.
Summary
Basically described an artificial keep-alive session using JS + cache, you can set the TTL to as long or as short as you want, depending on how actively the page is going to be edited.
During the Application startup , using the login Id of the User , i am making a Database call and loading all of his accounts and setting them in the session as shown
session.setAttribute("userinfo",userinfo);
and i am using this accounts information in the service layer to do a check before making a call to the Database
Now the problem is that if a User (who is having multiple accounts ) logs simulatunosly into a same browser , its creating same sessionid , as a result the session is having only the information of the last logged in user .
is there anyway i can solve this , may be the way i am storing data
please help
May not be the best solution but this will help to solve the problem.
What you could do would be to associate the userid with the sessionid and on every pageload / clicks, you will check if the sessionid matches the login user's userid. If it matches, disregard and run the page as usual else you can fetch the user info from the database and reassign the variables again.
You can use URL rewrite instead of cookies. The downside is that the session ID is exposed in the URL.
Is there any way I can get the latest tweet/status update of multiple Twitter-friends in a single request
An API call for the same would look as below
latestStatus = getLatestStatus(new long[]{userId1, userId2, userId3});
So as I pass in the input array of user id's (or screennames), I get the latest status update (or the status id) as an output.
I can do this one request per user, but then it exceeds the Rate Limit.
Language no barrier, even an HTTP Get request algorithm is good enough.
Check out Twitter4j.
You can use the lookupUsers(long[]) method. This will return information (including latest status) from up to 100 users at once. Check out: http://twitter4j.org/en/javadoc/twitter4j/api/UserMethods.html#lookupUsers(long[]) for more details.
example:
Twitter twitter = new TwitterFactory().getInstance();
ResponseList<User> userInfo = twitter.lookupUsers(new long[]{userId1, userId2, userId3});
for(User u: userInfo){
System.out.println(u.getScreenName() + ": " + u.getStatus().getText());
}