Destroying a session from a JavaScript function.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Pete

    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="JavaS cript">
    function btnResetFormCli ck(orderform)
    {
    orderform.reset ();
    var i;
    for(i=0;i<docum ent.orderform.e lements.length; i++)
    {
    if(document.ord erform.elements[i].type=="checkbo x" &&
    document.orderf orm.elements[i].checked==true)
    {
    document.orderf orm.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.

  • Pedro Graca

    #2
    Re: Destroying a session from a JavaScript function.

    Pete wrote:[color=blue]
    > 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 :[/color]
    (snip)[color=blue]
    > Any ideas on how to do this? If this a JavaScript issue then please say
    > so and I'll post in the JS group.[/color]

    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



    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 =--

    Comment

    • Pete

      #3
      Re: Destroying a session from a JavaScript function.

      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=orderc ompleted" 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:[color=blue]
      > Pete wrote:
      >[color=green]
      >>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="wind ow.print();">
      >>
      >>or when the order form is reset using a JavaScript function :[/color]
      >
      > (snip)
      >[color=green]
      >>Any ideas on how to do this? If this a JavaScript issue then please say
      >>so and I'll post in the JS group.[/color]
      >
      >
      > 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
      >
      > https://www.example.com/destroy_sess...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.[/color]

      Comment

      • R. Rajesh Jeba Anbiah

        #4
        Re: Destroying a session from a JavaScript function.

        Pete <skredding_no_s pam_you_tw@s_ne tscape.net> wrote in message news:<xML%b.862 4$lk3.7419@news-binary.blueyond er.co.uk>...[color=blue]
        > 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="JavaS cript">
        > function btnResetFormCli ck(orderform)
        > {
        > orderform.reset ();
        > var i;
        > for(i=0;i<docum ent.orderform.e lements.length; i++)
        > {
        > if(document.ord erform.elements[i].type=="checkbo x" &&
        > document.orderf orm.elements[i].checked==true)
        > {
        > document.orderf orm.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.[/color]

        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

        Comment

        Working...