help with understanding sessions and practical/correct usage

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Code: Select all

$sql = "SELECT street, city, state, phone FROM customer WHERE user_name = '{$_SESSION['logname']}'";
Notice the single quotes around the string.
User avatar
Obadiah
Forum Regular
Posts: 580
Joined: Mon Jul 31, 2006 9:13 am
Location: Ashland, KY
Contact:

Post by Obadiah »

everah and volka...thanks :) you guys are awsome!
[edited]

just one thing....what was the difference in the quotes i got to know?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

MySQL treats unquoted strings as field names (unless they are integers).
User avatar
Obadiah
Forum Regular
Posts: 580
Joined: Mon Jul 31, 2006 9:13 am
Location: Ashland, KY
Contact:

Post by Obadiah »

ok...im wanting to do a logout and i was wondering if i could (like a submit buttons action property) call a php function with anchor tag here is my log out function...or my attempt....firstly ill ask if ive done it right

Code: Select all

function clearsessionscookies() 
{ 
    unset($_SESSION['auth']); 
    unset($_SESSION['logname']); 
     
    session_unset();     
    session_destroy(); 
}
assuming thats done correctly how do i use a link to point to it?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Like always: Send a parameter within a new http request and let the script react on that parameter.

Code: Select all

<?php // whatever.php
function clearsessionscookies()
{
	unset($_SESSION['auth']);
	unset($_SESSION['logname']);

	session_unset();     
	session_destroy();
} 

if ( isset($_GET['action']) && 'logout'===$_GET['action'] ) {
	clearsessionscookies();
}
?>
<html>
	<head><title>...</title></head>
	<body>
		<a href="whatever.php?action=logout">logout</a>
	</body>
</html>
User avatar
Obadiah
Forum Regular
Posts: 580
Joined: Mon Jul 31, 2006 9:13 am
Location: Ashland, KY
Contact:

Post by Obadiah »

heres a weird question for you guys...say you want to populate a dropdown box with the file names in a specific folder...is their a way of doing that in php?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Have a look at the PHP Filesystem functions. Please note this is a little off-topic for session usage.
Post Reply