This topic is locked
[SOLVED]

 manage logout

1/12/2016 10:23:53 AM
PHPRunner General questions
F
Francesco_5000 author

hi
I read this tip:
http://www.asprunner.com/forums/topic/22343-how-to-make-single-project-connect-to-different-databases-passing-database-name-via-url/
and it works very well, unfortunately I've some difficulties to manage the logout. the code of the connection is this



function strip_it($stringa){

$stringa=stripslashes($stringa);

$stringa=strip_tags($stringa);

$stringa=htmlspecialchars($stringa);

$stringa=htmlentities($stringa, ENT_QUOTES) ;

return $stringa;

}
if($_GET["customer"]) {
$customer=strip_it($_GET["customer"]);
$_SESSION["customer"]=$customer;
if ($customer=='customer1')
$_SESSION["dbname"]='db_customer1';
else if ($customer=='customer2')
$_SESSION["dbname"]='db_customer2';
else if ($customer=='customer3')
$_SESSION["dbname"]='db_customer3';



else if ($customer=='customer4')
$_SESSION["dbname"]='db_customer4';
else if ($customer=='customer5')
$_SESSION["dbname"]='db_customer5';



}
$host="localhost";

$user="root";

$pwd="pwd";

$port="3306";

$sys_dbname=$_SESSION["dbname"];


I edited the login.php source code in this way



if(postvalue("a")=="logout")

{
//$pageObject->Logout(true);
$dbname=$_SESSION["dbname"];

$customer_0=$_SESSION["customer"];


unset($_SESSION["customer"]);

unset($_SESSION["dbname"]);

unset($_SESSION["UserName"]);

unset($_SESSION["UserID"]);

unset($_SESSION["GroupID"]);

unset($_SESSION["language"]);

unset($_SESSION["AccessLevel"]);





header('Location: https://mysite/esperanto/login.php?customer='.$customer_0);



exit();



}


if I do the logout from any page, other than the menu page, after the redirection to the login page I see a "Fatal error: No database selected"

Admin 1/13/2016

What is the exact URL of the page where you get "Fatal error: No database selected" error message.

F
Francesco_5000 author 1/13/2016

If I do the logout from the menu page , I'm redirected to:
https://mysite/esperanto/login.php?logout=a&customer=customer_name'>https://mysite/esperanto/login.php?logout=a&customer=customer_name
and I don't see any error. That's right, I edited the login.php source code in this way



if(postvalue("a")=="logout")

{
//$pageObject->Logout(true);
$dbname=$_SESSION["dbname"];

$customer_0=$_SESSION["customer"];


unset($_SESSION["customer"]);

unset($_SESSION["dbname"]);

unset($_SESSION["UserName"]);

unset($_SESSION["UserID"]);

unset($_SESSION["GroupID"]);

unset($_SESSION["language"]);

unset($_SESSION["AccessLevel"]);





header('Location: https://mysite/esperanto/login.php?customer='.$customer_0'>https://mysite/esperanto/login.php?customer='.$customer_0);



exit();



}


If I do the logout from any page, other than the menu page, I'm redirected to
https://mysite/esperanto/login.php
without the query string, than I have the: "Fatal error: No database selected"

Admin 1/13/2016

Not sure what else I can say without having the access to the whole application. I guess you need to troubleshoot your app to see what exactly is happening when you logout from one of the list pages. It looks like your code in login.php is not executed in this scenario.

F
Francesco_5000 author 1/14/2016

in the end, I solved the problem by editing MySQLConnection.php in this way


if (!$this->conn || !mysql_select_db($this->sys_dbname, $this->conn))

{

/*

unset( $_SESSION["myqsladdress"] );

trigger_error( mysql_error(), E_USER_ERROR );

*/



header('Location: logout.html');

exit();

}


it's not perfect but it works, and the session variables, related with the login, are unset in someway.