473,498 Members | 1,793 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Destroying a session from a JavaScript function.

I have a site which is using sessions to pass data from one page through
to the next. The problem that I have is that there are only two places
where the session could/should be destroyed. This is where a form is
printed using :

<input type="button" name="Button" value="Print Order"
onClick="window.print();">

or when the order form is reset using a JavaScript function :

<SCRIPT LANGUAGE="JavaScript">
function btnResetFormClick(orderform)
{
orderform.reset();
var i;
for(i=0;i<document.orderform.elements.length;i++)
{
if(document.orderform.elements[i].type=="checkbox" &&
document.orderform.elements[i].checked==true)
{
document.orderform.elements[i].checked=false;
}
}
//Just thought - will code an automatic "reload main page" bit here
}

The reset has to be done like this because some of the checkboxes are
built with a default value of checked which is determined by a PHP
session variable passed through from the previous page.

So I want to destroy the session at one of these two points but I can't
see how to do it. On button calls an inline function to print and the
other button calls a JavaScript function.

Any ideas on how to do this? If this a JavaScript issue then please say
so and I'll post in the JS group.

Thanks.

Jul 17 '05 #1
3 18446
Pete wrote:
I have a site which is using sessions to pass data from one page through
to the next. The problem that I have is that there are only two places
where the session could/should be destroyed. This is where a form is
printed using :

<input type="button" name="Button" value="Print Order"
onClick="window.print();">

or when the order form is reset using a JavaScript function : (snip) Any ideas on how to do this? If this a JavaScript issue then please say
so and I'll post in the JS group.


Only php can destroy the session. There is no way to achieve that with
JavaScript. However ...

if (I don't know JavaScript) you can make the browser request a URL
inside those places you want to destroy the session, just have it do
that and redirect to the same page. The URL could be something like

http://www.example.com/destroy_sessi...to/current.php

where destroy_session.php would destroy the session and redirect to
$_GET['return']
or open a new window with the destroy_session.php and have JavaScript
close it immediately after it loads; with no need for the redirect.
*Warning*:
in either case, the user can request the destroy_session.php at any
time (by writing the URL in the address bar) and have the session
destroyed when you do not expect it to happen.
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #2
I think that certainly gives me a possibility to explore. I suppose I
could call the current page and pass through a discreet action/variable
in the URL like "?action=ordercompleted" and when the page receives this
then it could destroy the session and go back to the main page. I'm
pretty sure this could be done in JavaScript.

Thanks for the advice.

Pete.

Pedro Graca wrote:
Pete wrote:
I have a site which is using sessions to pass data from one page through
to the next. The problem that I have is that there are only two places
where the session could/should be destroyed. This is where a form is
printed using :

<input type="button" name="Button" value="Print Order"
onClick="window.print();">

or when the order form is reset using a JavaScript function :


(snip)
Any ideas on how to do this? If this a JavaScript issue then please say
so and I'll post in the JS group.

Only php can destroy the session. There is no way to achieve that with
JavaScript. However ...

if (I don't know JavaScript) you can make the browser request a URL
inside those places you want to destroy the session, just have it do
that and redirect to the same page. The URL could be something like

http://www.example.com/destroy_sessi...to/current.php

where destroy_session.php would destroy the session and redirect to
$_GET['return']
or open a new window with the destroy_session.php and have JavaScript
close it immediately after it loads; with no need for the redirect.
*Warning*:
in either case, the user can request the destroy_session.php at any
time (by writing the URL in the address bar) and have the session
destroyed when you do not expect it to happen.


Jul 17 '05 #3
Pete <skredding_no_spam_you_tw@s_netscape.net> wrote in message news:<xM*****************@news-binary.blueyonder.co.uk>...
I have a site which is using sessions to pass data from one page through
to the next. The problem that I have is that there are only two places
where the session could/should be destroyed. This is where a form is
printed using :

<input type="button" name="Button" value="Print Order"
onClick="window.print();">

or when the order form is reset using a JavaScript function :

<SCRIPT LANGUAGE="JavaScript">
function btnResetFormClick(orderform)
{
orderform.reset();
var i;
for(i=0;i<document.orderform.elements.length;i++)
{
if(document.orderform.elements[i].type=="checkbox" &&
document.orderform.elements[i].checked==true)
{
document.orderform.elements[i].checked=false;
}
}
//Just thought - will code an automatic "reload main page" bit here
}

The reset has to be done like this because some of the checkboxes are
built with a default value of checked which is determined by a PHP
session variable passed through from the previous page.

So I want to destroy the session at one of these two points but I can't
see how to do it. On button calls an inline function to print and the
other button calls a JavaScript function.

Any ideas on how to do this? If this a JavaScript issue then please say
so and I'll post in the JS group.


I think, the problem is with your design. You may not need JS to
fiddle with some PHP operations.

Answer to your question of destroying session from JS:
- You cannot do it directly from JS
- If the session is cookie based, you may reset (delete) the
session cookie using JS. But, it is not "destroying"; it will just
generate a new session.

--
"Success is not what you achieve, but it is what you die for"
If you live in USA, please support John Edwards.
Email: rrjanbiah-at-Y!com
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
4664
by: Marcus | last post by:
I know from php.net that when register_globals is turned on, session_start(); session_unset(); session_destroy(); will succeed in unsetting all session variables and then destroying the...
2
1616
by: STEPHEN GOODE | last post by:
I have a need to notice when a user leaves a site so I can implement destructors for objects. I know that PHP doesn't supply an object destructor. I can code that myself. What I don't know how to...
0
1394
by: SteveS | last post by:
Hello, this problem is driving me nuts! I am using the Content Ratings (RSACi) for my website. The settings strictly "G" rated - No violence, sex, nudity or offensive language. I have a user...
6
1568
by: -D- | last post by:
I'm trying to accomplish the following. I'm trying to get the values for the table rows that are dynamically created to persist through a redirect. Referring URL:...
3
12378
by: Enoch Chan | last post by:
I would like to set a Session variable to a value. In Vbscript it should be Session("ZoomValue")=500 How can I set this session variable by using Javascript? Thanks
6
2552
by: Nedu N | last post by:
Hi, I am trying to design a Home page for my applicatiion in which i want show the links for for some itms... I tried to put the following <td> <font face="Arial, Helvetica, sans-serif" ...
7
3340
by: le0 | last post by:
Hello Guys, I have this problem on my page. Im doing my "Logoff" portion, everytime I click "Logoff" then click the Back button in my browser the previous page still appears. Heres my code...
7
7304
by: Rob | last post by:
Hi, I'm getting an error on my login page when using Javascript session object. It works on the development server so I'm wondering if there is a setting in IIS to allow using sessions on the...
6
5120
by: =?Utf-8?B?U2hhd24gU2VzbmE=?= | last post by:
Greetings! I was researching AJAX to provide a solution to displaying status messages while a long process executed. I found several examples online and was able to use their code to get a quick...
0
7004
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7167
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6890
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7379
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4915
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4593
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3085
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1423
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
292
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.