Click here to Skip to main content
16,012,116 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to clear all session in php when a page unload so that after that I can hide and show some html element.
please help me
thanks in advance.
Posted
Updated 25-Nov-11 21:09pm
v2

1 solution

Its depend upon the condition which is that how you are going to keeping the session? either you are using PHP's built in session management or a custom session management.
Have a look there[^] for nice solution which gives you idea how to clear based on condition.
 
Share this answer
 
Comments
naren programmers 26-Nov-11 4:34am    
what i want that i have a form,when user fill the form the form hide and downloads link get shown . after that when use leave this page and user visit again this particular page user must not see the download link but he must see the form again please not that other page are made in html please see and reply
RaviRanjanKr 26-Nov-11 8:49am    
Ah! ok thanks for share it.
naren programmers 29-Nov-11 4:17am    
in firefox this is not working on some computer please help me out i am also using jquery

this is the full code


the link is here

http://shaktimachinerystore.com/downloads.php

in this page i am using the code of jquery which will fire on unload of page
<script type="text/javascript">
window.onunload = dostuff();
function dostuff() {
$.get("http://shaktimachinerystore.com/clear.php");
$.ajax({url:"http://shaktimachinerystore.com/clear.php?", async:false});
alert('bye');


}
</script>
in clear.php i wrote
<!--?php session_start();
session_unset();
session_destroy();
??-->


and in downloads page to hide and show the forms and links i used


<!--?php
if(isset($_SESSION['temp'])){
echo '<div style="display:none;"?-->';
}
?>
<form name="frm1" method="post" action="downloadsmail.php" >
<!--?php
if(isset($_SESSION['temp'])){
echo '</div?-->';
}
?>

i am giving only the form tag to be precise

and below is table in variable $tableshow which will echo if session have any value


<!--?php $tableshow='<table class="maintab" border="0" cellpadding="0" cellspacing="0" style="width: 100%"?-->
<tr>
<td style="width: 40%; height: 90px; text-align: center">

<img border="0" src="images/pdfownimg_23.jpg" />
</td>
<td style="width: 31%; height: 90px; text-align: center">
<img border="0" src="images/pdfownimg_25.jpg" />
</td>
<td style="width: 33%; height: 90px; text-align: center">
<img border="0" src="images/pdfownimg_27.jpg" /></td>
</tr>
<tr>
<td style="width: 40%; height: 76px; text-align: center">
<img border="0" src="images/pdfownimg_32.jpg" /> </td>
<td style="width: 31%; height: 76px; text-align: center">
<img border="0" src="images/pdfownimg_34.jpg" /> </td>
<td style="width: 33%; height: 76px">
</td>
</tr>
<tr>
<td colspan="3" style="width: 40%;text-align:center; font-size:12px;">
Don’t have PDF reader. Click here to Download Pdf Reader.
</td>
</tr>
</table>';




if(isset($_SESSION['temp'])){

echo $tableshow;
}
?>
naren programmers 30-Nov-11 5:42am    
this is final solution

if(count($_POST)>0)
{
do whatever you want with user information - save in db or mail etc
& show download contents here
}
else
{
show form(with Post method) here, action will be downloads.php

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900