Jump to content

Recommended Posts

Is $_POST required prior to using $_GET?

 

I have a hyperlink which is index.php?action=logout

 

When that link is clicked Im trying to get it to unset the logged in session variable.

 

I have this code:

 

if ($_GET['action'] = logout)

 

which unsets the variable if its true, however $_GET['action'] does not ever seen to equal anything. I've been trying to print it to see what the problem is as no error is generated and I get nothing. Am I going about this the wrong way?

Link to comment
https://forums.phpfreaks.com/topic/172618-_get-not-working/
Share on other sites

Indeed you guys are awesome ;) I'm still a beginner. Finally made a system of logging in that works great, validates and crypts but some simple stuff like this still trips me up. I am now returning the proper value however I have a feeling im using unset improperly. the rest of the code is as follows:

 

if ($_GET['action'] == "logout")

{

unset ($_SESSION['loggedin']);

 

It dosnt seem to actually unset that variable when the link is clicked or page refreshed.

Link to comment
https://forums.phpfreaks.com/topic/172618-_get-not-working/#findComment-909906
Share on other sites

Hrm I switched it to session_destoy() and had both the unset and session destroy and neither one logged the person out. It removed the variables indicating username and whatnot but the logged in session variable remains. I even had it print the session variable right after session_destroy and that variable remains

Link to comment
https://forums.phpfreaks.com/topic/172618-_get-not-working/#findComment-909909
Share on other sites

Might be better if I post the whole code of what I'm trying to do:

 

<?php
require("header.php"); // The banner logo and ad app. Also begins the overall page table.

if ($_GET['action'] == "logout")
{
unset ($_SESSION['loggedin'];
session_destroy();
require("sidebar.php"); // The app that determines if you're logged in, if logged in displays sidebar menu, if not offers login/signup
require("announcements.php"); // Gives main page with announcements
require("footer.php"); // Copyright info and ties up the overall page table.
}
else
{
require("sidebar.php"); // The app that determines if you're logged in, if logged in displays sidebar menu, if not offers login/signup
require("announcements.php"); // Gives main page with announcements
require("footer.php"); // Copyright info and ties up the overall page table.
}

 

sidebar.php is where the login box is and it starts off with:

 

if ($_SESSION[loggedin] = yes)

{

 

and on from there

Link to comment
https://forums.phpfreaks.com/topic/172618-_get-not-working/#findComment-909916
Share on other sites

Hrm I switched it to session_destoy() and had both the unset and session destroy and neither one logged the person out. It removed the variables indicating username and whatnot but the logged in session variable remains. I even had it print the session variable right after session_destroy and that variable remains

Do you have session_start() at the beginning of the file you are using this code at?

 

Edited: Apparently not. Add it and both, unset and session_destroy() should work.

Link to comment
https://forums.phpfreaks.com/topic/172618-_get-not-working/#findComment-909920
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.