By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,403 Members | 1,620 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,403 IT Pros & Developers. It's quick & easy.

Newbe with php - javascript problem

P: n/a
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=JavaScript>
function fonct_form(form)
{
<?php session_unregister( "uid" );
session_unregister( "lang" );
session_destroy();
session_start();
?>
document.location.href="http://www.mysite.com";
}
.....
<TD><input type='button' onClick='fonc_form(this.form)'
value='quit'></TD></TR>
......
But this doesn't work.
Thanks in advance for any help

Ralf
Jul 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Ralf Meuser wrote:
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=JavaScript>
function fonct_form(form)
{
<?php session_unregister( "uid" );
session_unregister( "lang" );
session_destroy();
session_start();
?>
document.location.href="http://www.mysite.com";
}
....
<TD><input type='button' onClick='fonc_form(this.form)'
value='quit'></TD></TR>
......
But this doesn't work.
Thanks in advance for any help

Ralf


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.
js*******@attglobal.net
==================
Jul 17 '05 #2

P: n/a
Jerry Stuckle,
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=JavaScript>
function fonct_form(form)
{
<?php session_unregister( "uid" );
session_unregister( "lang" );
session_destroy();
session_start();
?>
document.location.href="http://www.mysite.com";
}
....
<TD><input type='button' onClick='fonc_form(this.form)'
value='quit'></TD></TR>
......


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.

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
Jul 17 '05 #3

P: n/a
Ralf Meuser wrote:
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=JavaScript>
function fonct_form(form)
{
<?php session_unregister( "uid" );
session_unregister( "lang" );
session_destroy();
session_start();
?>
document.location.href="http://www.mysite.com";
}
....
<TD><input type='button' onClick='fonc_form(this.form)'
value='quit'></TD></TR>
......
But this doesn't work.
Thanks in advance for any help

Ralf


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.php">Logout Now</a>
<TD>

FILE: logout.php
<?php
session_unregister( "uid" );
session_unregister( "lang" );
session_destroy();
session_start();
header("Location: http://www.mysite.com");
?>
--
Kenneth Downs
Secure Data Software, Inc.
(Ken)nneth@(Sec)ure(Dat)a(.com)
Jul 17 '05 #4

P: n/a
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("Location:
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
Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.