Newbe with php - javascript problem

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

    Newbe with php - javascript problem

    Hi there

    I'm trying to create a button which will exit my php-session un go to my
    main page.
    I thought of some thing like this:

    ....
    <script language=JavaSc ript>
    function fonct_form(form )
    {
    <?php session_unregis ter( "uid" );
    session_unregis ter( "lang" );
    session_destroy ();
    session_start() ;
    ?>
    document.locati on.href="http://www.mysite.com" ;
    }
    .....
    <TD><input type='button' onClick='fonc_f orm(this.form)'
    value='quit'></TD></TR>
    ......


    But this doesn't work.
    Thanks in advance for any help

    Ralf


  • Jerry Stuckle

    #2
    Re: Newbe with php - javascript problem

    Ralf Meuser wrote:[color=blue]
    > Hi there
    >
    > I'm trying to create a button which will exit my php-session un go to my
    > main page.
    > I thought of some thing like this:
    >
    > ...
    > <script language=JavaSc ript>
    > function fonct_form(form )
    > {
    > <?php session_unregis ter( "uid" );
    > session_unregis ter( "lang" );
    > session_destroy ();
    > session_start() ;
    > ?>
    > document.locati on.href="http://www.mysite.com" ;
    > }
    > ....
    > <TD><input type='button' onClick='fonc_f orm(this.form)'
    > value='quit'></TD></TR>
    > ......
    >
    >
    > But this doesn't work.
    > Thanks in advance for any help
    >
    > Ralf
    >
    >[/color]

    Won't work because php is server-side and your button click is
    client-size.

    The easiest way would probably be an unregister.php script which is
    called when your button is pushed and then redirects to your home page.


    --
    =============== ===
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    • Mike Willbanks

      #3
      Re: Newbe with php - javascript problem

      Jerry Stuckle,
      [color=blue][color=green]
      >> I'm trying to create a button which will exit my php-session un go to
      >> my main page.
      >> I thought of some thing like this:
      >>
      >> ...
      >> <script language=JavaSc ript>
      >> function fonct_form(form )
      >> {
      >> <?php session_unregis ter( "uid" );
      >> session_unregis ter( "lang" );
      >> session_destroy ();
      >> session_start() ;
      >> ?>
      >> document.locati on.href="http://www.mysite.com" ;
      >> }
      >> ....
      >> <TD><input type='button' onClick='fonc_f orm(this.form)'
      >> value='quit'></TD></TR>
      >> ......[/color]
      >
      > Won't work because php is server-side and your button click is client-size.
      >
      > The easiest way would probably be an unregister.php script which is
      > called when your button is pushed and then redirects to your home page.[/color]


      There is also another way. You could actually have javascript load an
      image into the page such like an image that executes the logout script.

      Mike

      Comment

      • Kenneth Downs

        #4
        Re: Newbe with php - javascript problem

        Ralf Meuser wrote:
        [color=blue]
        > Hi there
        >
        > I'm trying to create a button which will exit my php-session un go to my
        > main page.
        > I thought of some thing like this:
        >
        > ...
        > <script language=JavaSc ript>
        > function fonct_form(form )
        > {
        > <?php session_unregis ter( "uid" );
        > session_unregis ter( "lang" );
        > session_destroy ();
        > session_start() ;
        > ?>
        > document.locati on.href="http://www.mysite.com" ;
        > }
        > ....
        > <TD><input type='button' onClick='fonc_f orm(this.form)'
        > value='quit'></TD></TR>
        > ......
        >
        >
        > But this doesn't work.
        > Thanks in advance for any help
        >
        > Ralf[/color]

        Ouch, you can't put PHP inside of javascript. Javascript is executing in
        the browser, and PHP on the web server. Perhaps this would be the idea:

        The page has this somewhere:

        <TD>
        <a href="logout.ph p">Logout Now</a>
        <TD>

        FILE: logout.php
        <?php
        session_unregis ter( "uid" );
        session_unregis ter( "lang" );
        session_destroy ();
        session_start() ;
        header("Locatio n: http://www.mysite.com" );
        ?>


        --
        Kenneth Downs
        Secure Data Software, Inc.
        (Ken)nneth@(Sec )ure(Dat)a(.com )

        Comment

        • zygomatic

          #5
          re:Newbe with php - javascript problem

          Ralf,

          I don't know if you figured out your problem or not yet, but you can't
          run PHP on the client side like Javascript. PHP is compiled on the
          server side. You can use PHP to redirect anyway by using:

          header("Locatio n:
          http://www.mysite.com" );

          You can have a button run that PHP code with the new addition the same
          way a submit button would.
          http://eye.cc -php- web design

          Comment

          Working...