Refreshing two iframes in one click - javascript

I have two iframes named "header" and "content". When the index page is loaded, the "header" contains a link to the Home Page, and another link to the Login Page. While the "context" displays stuff about the page and all that.
Now the problem is, after I log in, I want both of the frames to reload. I can change "context" because this is the iframe where I will do the logging in so there's no problem.
What I am tyring to do now is to find out how I could also change the "header" iframe. After logging in, I want it to display a link for Home Page for his tasks, and a link that would display the username of the logged in user for his profile.
Is there any way I could do this? I am using PHP, by the way.
Thank you in advance. :)

it would be better if you share your codes with us, its hard to answer by this way, you can try using php sessions for check a user logged in or not. after the code which you checking login, if login is success create the session and define $_SESSION['userName'] or userID as you wish and you check if session userName set on your header or content.
<?php if($_SESSION['userName']): ?>
// your html codes goes here for logged in user
<?php else: ?>
// your html codes goes here for non-user
<?php endif; ?>

Related

How can I make the page to show success message on submission to telegram and redirect? [duplicate]

I'm trying to create a Session-Based flash message in PHP:
In register.php page, I set the session as follow:
$_SESSION['flash'] = 'Registered';
Then, after redirecting user to the home page, I printed the flash message:
if (isset($_SESSION['flash'])) {
echo $_SESSION['flash'];
unset($_SESSION['flash']);
}
The session is started in both pages.
The problem is:
I get the flash message in the home page only if I remove the unset function, and then the message is always printed.
I wrote a library just for this type of issues: https://github.com/tamtamchik/simple-flash.
Once you have it installed you can do this:
// put message not session
flash('Some error message', 'error');
// print it after redirect
echo flash()->display();
It'll generate Bootstrap friendly alert messages.
I just solved my problem by adding exit after redirecting user to escape the execution of the register page, so the session won't be unset in the current page before using it in the next page.
Please note that session_unset just clears out the sesison for usage. The session is still on the users computer. Note that by using session_unset, the variable still exists.
Using session_unset in tandem with session_destroy however, is a much more effective means of actually clearing out data. As stated in the example above, this works very well, cross browser:
<?php
session_unset();
session_destroy();
?>

Stopping the use of a URL to get to the site

So I have a website which redirects to another part of the site ie, when pressing a button on "www.test.com" it reditects to "www.test.com/anotherpage". Now my problem is that I only want users to be able to access the second page when using the button and not just typing in "www.test.com/anotherpage" into the search bar.
So, is there any way to setup my page such that it cannot be accessed by the url but only redirected from another part of the website?
document.referrer
The value is an empty string if the user navigated to the page directly (not through a link, but, for example, via a bookmark). Since this property returns only a string, it does not give you DOM access to the referring page.
You need use Php code to login users and check sessions example like exaplain here: Login form and session example
of course you need basic know about Php
You could use a client or a server side technique.
Example of client side is Javascript, reading the document.referrer in the called page as #Barmar pointed out, and redirecting to the home in case the referrer is not from your home page.
The server side way could make use of parameters passed to the page, like a SESSION identifier that will be generate on the home page, for example and checked in the called page.
Actually there are a different ways to accomplish your goal.
You should provide some more info about the environment so we can help.
You can usee PHP. Simply put your button between form tags
<form action="http://www.test.com/anotherpage" method="POST">
<input name="mybutton" type="submit" value="Go to another page">
</form>
and on anotherpage
<?php
if (!isset($_POST['mybutton'])) { //check if the button was clicked
header('Location: index.html'); //forward to index if not
}
?>

Session login (back arrow of chrome)

I have basic login code system that every values of the textboxes(user inputs) will store in a SESSIONS. After the user's login, my HOME.php showed. And in a HOME.php, The user clicked the back arrow of google chrome, and it seemed the page is going back to the INDEX.php where user logged-in. I was trying if the sessions in index.php are exist. if not go back to home.php?
How could I prevent if the user try to click the back arrow of chrome and still remain in home.php?,
You should check whether the session has set in the index.php and if it was set then you should redirect the user to home.php else to remain same in the index.php
So, In your index.php you should have this code
if(isset($_SESSION['user']))
{
header("Location: home.php");
}
else
{
#Ask for credentials using your form
}
Note : I am using $_SESSION['user'] you should the name that you are using.
I am not exactly sure what the problem is, but I think you want to check if the user session exists in your index.php page. If it does, redirect automatically to home.php and if it does not, show the page contents / login form.

Keep SESSION php after 3° pages refresh

i have a issue with my SESSIONS, on the first page the user clicks on a anchor, then if the user is logged in will be redirected without problem, but if not, first he will pass through login page, but when the user reach thelogin page, the variables are missing. (The login page occurs after the redirect page). So i have saved the SESSIONS with $_GET parameters.
How i can keep the current SESSIONS to redirect the user after the login?
Thanks!
EDITED
Page: retailer.php (this page is where its fired the parameters)
<a href="/go2store.php?rid=<?php echo $row['slug_title']; ?>&c=<?php echo $row_coupons['coupon_id']; ?>" onclick="javascript:window.location.href='<?php echo $row_coupons['logout_url']; ?>';" target="_blank">
Page: go2store.php (this page is where i'm saving the SESSION)
$_SESSION["myCupon"] = "/go2store.php?rid=".$_GET['rid']."&c=".$_GET['c'];
Page: redirect.php (This page its checking if the user is logged in, if yes, redirect to the URL on the SESSION, if not will send to login.php)
Page: login.php (here i have this on top of the code)
session_start();
$_SESSION["myCupon"] = "/go2store.php?rid=".$_POST['rid']."&c=".$_POST['c'];
But it comes empty, its not returning any values after the redirect.php page.
As noted by a user in the comments, you need to include:
session_start();
At the top of each page to carry session variables across pages, otherwise it won't recognise the vars you set initially.
We don't know how you're organising your code, but this needs to be present both before and after potential login.
You can easily set/get $_SESSION variables prior to login or indeed set/get upon login from other vars you might use in pages that aren't yet authenticated.

Show logout notice on login page only once

On a password protected website (ajax-php-jquery login system), a fadeIn/fadeOut alert confirms that the user just logged out. The user is sent back to the login page and I do a document.referrer to check if he comes from a page of the site (if so it means that he just logged out so I can display the message). But of course if the user refreshes the page he will get the notice again.
I was thinking of changing the document.referrer but the property is read-only. Any idea how I could display the message only once if the user did log out?
You could do a conditional with PHP:
if(isset($_SESSION['justLoggedOut'])){
print '<script type="text/javascript"> ..notification code.. </script>';
unset($_SESSION['justLoggedOut']);
}
You just have to set the session from within the authenticated area (or the logout page which redirects to the index page [I'm assuming.])
Using a cookie would be easiest route. Simply add a cookie when they log out, and then delete it after the notification has been shown. This cookie could contain all of the information you want about the log out: e.g. the time the logged out and the URL from which they initiated the log out.
Of course, that is assuming your clients are allowing cookies on your site. A server side alternative would be to use session data. Your notification would then send an AJAX call back to the server to clear the indicator that the notification should be shown.

Categories