Hello everone,
I have a webpage that have a form in iframe now the form submit in iframe and check from database and if found the username and password it start session and when i go to another page the session is lost, now how i can maintain session in iframe and parent widnow the session is start in child window means(iframe) and want to save in parent window to access other pages of website.

<html>
<head>
    <title>parent window</title>
</head>
<body>
<a href'home.php'>Home</a>
<a href'home1.php'>Home1</a>
<a href'home2.php'>Home2</a>
<a href'home3.php'>Home3</a>

<iframe src='login.php'>(after login session starts in this iframe)</iframe>

</body>
</html

After session start when i click on home1 or any other link the session lost
How i can prevent this

Regards

Member Avatar for LastMitch

if found the username and password it start session and when i go to another page the session is lost, now how i can maintain session in iframe and parent widnow the session is start in child window means(iframe) and want to save in parent window to access other pages of website.

Did you include session start() function on top of your iFrame but also did include the connection file that connected tht database?

yes i have include the session_start(); in iframe, database file and also in parent window session started successflly and when it checks from database and then set the value in session and i echo the session it show the value but when i goto anyother page it lost the session

Member Avatar for diafol

Are the iframe contents and the parent page on the same domain?

Member Avatar for LastMitch

yes i have include the session_start(); in iframe, database file and also in parent window session started successflly and when it checks from database and then set the value in session and i echo the session it show the value but when i goto anyother page it lost the session

So you have something like this:

<?php 
session_start();
include("folder/database.php");
?>

and it still lost session?

That is weird.

Like what diafol mention are the iframe and parent page on the same domain?

You can take a look at this (it has some code which you can add to your own code):

http://phpmaster.com/writing-custom-session-handlers/

http://phpmaster.com/php-sessions/

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.