Session variables lost in Popup window? - php

I have a bookmarklet that injects a button on a foreign webpage. When the button is clicked, a popup containing a page from my website appears.
I am using a PHP framework called Laravel, tested using Chrome browser
Problem: When I check whether the user is logged in from the page originating from my website which is within the popup window, it always returns that the user is not logged in.
if( Auth::guest() ) {
echo "Not logged in";
} else {
echo "Logged in";
}
However, when I visit the same page directly (not within a popup window opened from another website), I can see that I am logged in!
What is the issue here, and how can this be fixed?
Popup JS Code
var popupOptions = 'status=no,resizable=yes,scrollbars=yes,personalbar=no,directories=no,location=no,toolbar=no,menubar=no,width=632,height=295,left=0,top=0';
window.open(' http://www.domain.com/controllername/add?url='+url, '_blank', popupOptions);

You shouldn't be having two cookies with the same name. It looks like the popup window is setting another cookie with same name but different domain overwriting the valid one which should be for domain.com

Related

Session only registering when set directly from the login page

<?php
session_start();
if(isset($_SESSION['login_user'])) {
require_once('logged.html');
} else {
require_once('notlogged.html');
}
?>
This code works fine when I login directly from the login page, but when I start from the homepage, then a href to the login page, login, it still shows the notlogged.html.
But when I start from the login page, I can login and get to logged.html, go to the signout page and destroy my session, which lands me to the notlogged.html, then login again to the logged.html.
So basically, it works perfectly when I enter from login.php, but not when I enter from index.php. Any idea why this might be?
question isn't clear, 1st of all check whether session created while login from any page, its simple after creating session variable, make alert using JS
alert("$_SESSION['login_user']");

How to Reload a page from Iframe?

Iam just using an iframe for login and register.
and i need to reload the page when the message appears that he successfully registered/logged-in.
for example the iframe would be
when he click login in the iframe it reload other page called "login_success" this page send message"successfully logged in".
Now is the proplem i need the browser reload the page so that the session work in the page that loads the Iframe.
Thanks for responding.
You can use following script.
window.parent.location.reload();
Here it is
document.getElementById('ifarme_id').contentWindow.location.reload();
If it is in same domain you can try below
var myframe = document.getElementById('Ifrme_id');
myframe.src = myframe.src;

use fancybox iframe to login wordpress, then reload original page

On one of my sites I've added a custom div to the footer.php which goes to the login page for the wordpress site:
<p id="login" align="left"><?php if ( is_user_logged_in() ) { ?>
[-] logout
<?php } else { ?>
[+] members login
<?php } ?></p>
I use the "Fancybox for Wordpress" plugin to load iframes for contact forms and the like.
I was wondering how I can make the login show in an iframe, so that when the login is successful, the iframe closes and the page they were on reloads (so they're not taken to the cms).
I don't think you need an iframe to accomplish this. It sounds like you just want a login that leaves people on the current page. The problem with using an iframe is that the rest of the interaction will then happen inside that iframe. Try this instead: just instruct WordPress to return the user to the current page after logging them in.
Login
More info at http://codex.wordpress.org/Function_Reference/wp_login_url.

jquery signin and refresh

I have a main page in jquery-mobile which contains following code
<?php
if(isset($_SESSION['signed_in']))
{
if($_SESSION['signed_in']==true)
{
echo 'Signout ';
}
}
else
{
echo 'Signin ';
}
?>
The user is signed in or not is checked on server(obviously!)
But the problem is that after signing in, when the user goes to home page, "Signin" option
is shown. It is only when user refreshes page manually that "Signout" option is shown.
So how do I solve this error? How can I make jquery load page from server always and not store it in some cache or anything.
Make jQuery add the sign in or sign out button, in condition that the request was successful.
Use append to insert html to the page. It will make the page look if it was refreshed.

Allowing users to Refresh browser without the "Confirm Form Resubmission" pop-up

I have a login system, and while logged in, if I refresh the browser, Chrome shows a pop up window titled "Confirm Form Resubmission." I assume that the same thing would happen with other browsers.
How can I allow the browser to be refreshed without this confirmation pop-up window? Of course, I would also like to stay logged in while refreshing the browser.
After processing the POST page, redirect the user to the same page.
On http://test.com/test.php
header('Location: http://test.com/test.php');
This will get rid of the box, as refreshing the page will not resubmit the data.
Alright, so at the top of you login page, you can just have this:
<?php
if (isset($_POST['username'])) {
// Do you login stuff here....
if ($passed == true) {
header('Location: index.php');
} else {
echo "Invalid username/password!";
}

Categories