How can I run a block of PHP code every so often? - javascript

I am creating a website where the goal is to have only one session per user, I managed to do this with some validations and adding fields to my DB, then suppose that if the user enters with his username and password in Chrome he can navigate without problem, if the The same user in another browser either Firefox enters with his username and password, in the Chrome session when reloading the page or going to another page directly the session is closed, but what I want to do is log out instantly the moment the other session is started or if it is not possible then that this be done in a certain time so as not to wait for the page to reload or change to another.
This is my PHP code where I have the validation, I investigated that I can do it with ajax, but I don't understand how to do it, someone could guide me on this please. I thank you in advance.
$userById = $connection_s->getUsers($_SESSION["id_user"]);
if ($userById["fecha_acceso"] <> $_SESSION["fecha_acceso"]) {
echo"<script>location.href='logout.php';</script>";
}
I don't know what else I could put in code, this is my validation.

Related

Bypass/change the 'Changes that you made may not be saved' prompt

I need to log a user out of an application automatically if there is no interaction for a period of time.
However, when I perform the redirect to log the user out, the browser prompts 'Are you sure you want to leave' when changes are made to a Stimulsoft report.
How can I bypass this? If changes are made, then the user forgets to log out and save their changes, a malicious user could just come and press the cancel and have access to all the data in the system without allowing this auto-logout to occur.
Hope that you are fine!
I suggest you to make ajax request to log out link and then refresh the page after success.
$.get('url/of/logout/', function(){location.reload()})
with jquery. You can look for equivalent on axios or ajax primitiv function

how to pop up a Notice Span when user just log in (but not just refresh to the home page)?

I do not know how to detect it is the first time that user login the web.
I thought i should write a pop-up span on the jsp that user firstly saw when he login.but the issue is then he refresh the page,the notic will show again,that is ridiculous.
I need detect if it is first login means to detect if the user JUST LOGIN or NOT REFRESH the page
how and where shall I detect if it is the first time user login ? and then i can make mind if the notice span pop up.
and I think it should use cookies or session,but which one should i use?
Maintain a field in database table that check if it is first login than show a popup and after that change the value of that field so that Popup do not appear next time.
Ex:
if($data['first_login'] == 1)
{
// show popup
}
If you want to show it only to the new user (the time user registers) you can use a table column in database where you can use it to check if the user if logging in for the first time (e.g firtsLogin the column name = 1 ). If he is logging in for the first time you show the pop-up and change the value of the field to 0.
Otherwise if you want to show to users that are logged in to a specific device for the first time you should use cookies.
I suppose that you want to detect the user logging in to your web-site the first time. There are multiple ways that you can do it depending on your desire to spend additional time writing the code, the location of your logging-in logic (client or server side), security that you want to have while proving your users with login functionality. In all cases - you would have to store the data whether the user has logged in for the first time. I think you are seeking a fast solution that will work without a big care for privacy or security as working with client-side cookies isn't the safest way to store data. The alternatives to cookies are web tokens, url query string, server-side sessions and data-base (RDBMS) storage.
Storing and retrieving the data on the client-side using COOKIES. They are the pieces stored in the user's web browser. Cookies were created to help servers remember the data about the user next time he enters the web-site. The most common usages are: to store location (if accepted by user), web-site locale (language in which the user was browsing the site), products added to cart, etc. Following that approach you can create cookie after the user has logged in to your web-site as follows:
This should be run by your JavaScript.
document.cookie = "firstLogin=true";
After having done that, you would have to add JavaScript logic that will hook-up to user's/client's COOKIE data and read up whether he has logged in the first time before.
This would probably look like a simple JavaScript cookie look-up.
var cookieData = document.cookie;
This will return all of your user's cookies that has been previously stored when he visited your web-site. It will return it as a string concatenated with "; ". If we had previously stored only one cookie, we would get firstLogin=true;
In case if you have multiple cookies set before, you would have to parse the cookie string and extract the data either imperatively by plain procedural JavaScript code or by writing the function which will be able to do that repeatedly. Detailed examples of writing such functions could be found here.

Trying to save Multi-Value Form on server for users to call up during another session

been searching here for a while on how to save form information to be re-called later.
Here is my site: http://d3barb.com
The purpose is people fill out the 100+ fields in the form and it will generate numbers corresponding to the game Diablo 3. The formulas all work perfectly, and sometimes the cookie will save the information, but I'm trying to figure out a way to save the entire "page", so users can call them up during a different session.
I've tried for about 6 hours to get setCookie / getCookie functiond to create a cookie with all the values saved, but can't seem to get it to work. Even if it was working, it would only allow the user to load their last seission when re-visiting the site.
How I would like it perform:
1.) User inputs information for the form to calculate.
2.) User fills out a "name" text field and hits a "Save" button (I have these on my test page, but don't want it live until its working), which will save the values on my server containing all the form information as they've entered it.
3.) The next time that User visits the page, they would hit "Load" to call up a previous session.
I'd like to avoid user-account log-ins, so if possible I'd like the server to save the sessions by IP address & user submitted session name, something like: 142.105.103.125.fire crusader
Currently, the page is html with js calculating everything. I can convert it php for server interaction, but if there is another way, I'm all ears.
I'm not looking for handouts, so any links to tutorials would be greatly appreciated. If someone has done something similar to this and wouldn't mind sharing that page or code with me, I can do my best to frankenstein it for my page. (pretty much how I do all my websites haha!)
Have you tried/considered HTML 5 local storage?
http://www.sitepoint.com/html5-web-storage/
should get you started :)

Session value not update after redirect the page

I have a form, when i submit that form it post to another page, on that page i will set value of post in session, on that time session show current value which is right, after executing the script, it will submit to another third arty tool, the response of this third party tool going to another page which is belong to our app, at that time session display past value, when I load or refresh the page, then it shows current value? I am stuck there, don't know why it's happening and what is the solution of that, I research lot but didn't get any success? if some one help me, I would be very thank full to him.
The third party response is in post the code of that page is
if (isset($_POST)){
var_debug($_SESSION['reservation']);
exit();
}
on that script it shows past values, when I refresh or reload the page then it shows current session value
Maybe you can provide a code snippet? Or maybe make your question a bit clearer (about the third party tool). Or maybe you can check this http://prajapatinilesh.wordpress.com/2007/09/14/how-to-solve-php-session-problem/
Hope this works!

How to login to a website using login popup made by using javascript?

In my website, there is a login button. When a user clicks on that a popup pops up which asks for username and password from a user. Now i want that popup to work like following:
1- if user gives wrong username and password then popup disappears and an alert comes to tell user that wrong username or password is entered. try again.
2- if username and password is right then popup should be disappeard and main page should be redirected to user home page.
How can i do that using javascript.
Thanks in advance.
You're looking for some Ajax stuff. I think your login data is in a database (if not, then it doesn't make any sense, because everyone could simply read the login data)
I recommend you to search for some Ajax tutorials. Ajax is a technique to load content dynamically via javascript. Which means: after sending username + password to a server, it will response with success or failure, which you can use on your current page to display the error or success message.
Jquery is an easy-to-use javascript framework, which also supports Ajax calls.
You want whole code? Or just conception?

Categories

Resources