Have an account? Sign in
Login  Register  Facebook
Logout Button In PHP?
Hey guys,
Im new to php, and i was wondering how i could create a log out button for my page?
I have a logout.php page and i need a button to redirect to there when users click on logout.Any ideas?
Started: September 17, 2011 Latest Activity: September 17, 2011 php logout
2 Answers
if you want it as a button you must use form tag ok
this is the form:
<form action="logout.php" method="post">
    <input name="return" type="hidden" value="<?php echo urlencode($_SERVER["PHP_SELF"]);?>" />
    <input type="submit" value="logout" />
</form>
this is the logout code:
if (isset($_POST['return'])) {
    $return = urldecode('http://www.mysite.com'.$_POST['return']);
        header("Location: $return");
        exit;	
}

Posted: MacOS
In: September 17, 2011

its very easy like this logout.php?return=/home
logout.php
if (isset($_GET[\'return\'])) {
    $return = urldecode(\'http://www.mysite.com\'.$_GET[\'return\']);
        header(\"Location: $return\");
        exit;	
}
ok but how i can get the logout.php?return=/home in each page Automaticly there is too many ways just try this way
<a href=\"logout.php?return=<?php echo urlencode($_SERVER[\"PHP_SELF\"]);?>\">log out</a>

Posted: MacOS
In: September 17, 2011

I already have the code for logout.php.I just need to know how i can use a button instead of a hyperlink to actually log the user out.Like the login has a button but i want to know how to create a button to log the user out?
September 17, 2011

Your Answer

xDo you want to answer this question? Please login or create an account to post your answer