Jump to content

onclick functions.


Foser

Recommended Posts

I'm not sure if this exists, because I haven't heard of anything like this.

 

But I'm trying to do  logout function with session and want to do something like.

 

The only way I would think of doing it. would click send to a different page something like.

 

<?php

session_destroy();

if ($_SESSION['LOGGEDIN'] == FALSE){
header(Location: /login.php); exit;}

else { 
header(Location: /account.php);}

?>

 

is there a way so onclick of (this) will do {this function}?

 

or my way is the only way?

Link to comment
https://forums.phpfreaks.com/topic/57191-onclick-functions/
Share on other sites

yes here is how:

 

<?php
function logout() {
session_destroy();

if ($_SESSION['LOGGEDIN'] == FALSE){
header('Location: /login.php'); exit;}

else { 
header('Location: /account.php');
}
}
?>
<html>
//This is your form
<form id="form1" name="form1" method="post" action="">
  <label></label>
  <input type="submit" name="logout" id="logout" value="Logout" onClick="logout()" />
</form>
</html>

 

Please note that when you call the "HEADER" command it is always followed by (' and closed by '); so u would change

 header(Location: /login.php);

to

header('Location: /login.php');

Link to comment
https://forums.phpfreaks.com/topic/57191-onclick-functions/#findComment-282683
Share on other sites

Do this:

<?php

if ($_POST['submit']){

   session_destroy();

   if (!isset($_SESSION['LOGGEDIN'])){
      header('Location: /login.php'); 
   } else { 
      header('Location: /account.php');
   }
}


?>

<form method="post" action="<?=$_SERVER['PHP_SELF'] ?>">
  <input type="submit" name="logout" id="logout" value="Logout">
</form>

Link to comment
https://forums.phpfreaks.com/topic/57191-onclick-functions/#findComment-282688
Share on other sites

If you want to test for FALSE, I'm pretty sure you have to use ===.

 

Besides the fact that that is incorrect.. whats does it have to do with the op's question here?

 

WOO! I smell smoke. charlieholder was just trying to point out a flaw in their code....or trying to at least. No harm in that.

Link to comment
https://forums.phpfreaks.com/topic/57191-onclick-functions/#findComment-282715
Share on other sites

If you destory the session with session_destroy(), can you still store in the global variable $_SESSION?

 

0_0 Are you sure you just posted on the right thread? ...if you have a question totally unrelated to the topic, you should probably post your own thread for it.

Link to comment
https://forums.phpfreaks.com/topic/57191-onclick-functions/#findComment-282717
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.