Jump to content

function by reference not executing


phpJoeMo

Recommended Posts

OK, so I have the following file that has database functions:

 

<?php

 

function dbDelete($param){

$conDelete = mysql_connect($url,'username','password',true);

mysql_select_db('my_db',$conDelete);

mysql_query($param,$conDelete);

mysql_close();

if(isset($conDelete)){

mysql_close($conDelete);

}

}

?>

 

I include the above file in a session handling file.  But for some reason the new file can't call the above function as follows:

<?php

include_once 'the above stated file';

function timeOut(){

        dbDelete("DELETE FROM acctussessi WHERE acctussessi_usid = '$sessius[0]'");

$_SESSION = array();

setcookie(session_name(),'',time()-4200);

session_destroy();

}

//CHECK FOR TIMEOUT REQUEST

switch($_GET['xyz']){

case 'timeout':

timeOut();

header("Location: /?xyz=timedout");

break;

case 'logout':

timeOut();

header("Location: /?xyz=loggedout");

break;

case 'refresh':

dbUpdate("UPDATE acctussessi SET acctussessi_time = ".time()." WHERE acctussessi_unid ='".$token."'");

break;

}

?>

 

dbDelete isn't being called inside of the TimeOut() function.  The only way it works is by doing the following:

 

<?php

function timeOut(){

$_SESSION = array();

setcookie(session_name(),'',time()-4200);

session_destroy();

}

//CHECK FOR TIMEOUT REQUEST

switch($_GET['xyz']){

case 'timeout':

dbDelete("DELETE FROM acctussessi WHERE acctussessi_usid = '$sessius[0]'");

timeOut();

header("Location: /?xyz=timedout");

break;

case 'logout':

dbDelete("DELETE FROM acctussessi WHERE acctussessi_usid = '$sessius[0]'");

timeOut();

header("Location: /?xyz=loggedout");

break;

case 'refresh':

dbUpdate("UPDATE acctussessi SET acctussessi_time = ".time()." WHERE acctussessi_unid ='".$token."'");

break;

}

?>

But this is annoying and repetitive.  What is going on?

 

Thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/230440-function-by-reference-not-executing/
Share on other sites

Are you including the file using a file system path? That's (generally) the only way to get php code to be included into another file. Given that you didn't post what you were using in the include_once statement, I suspect you are actually using a URL, which won't work.

I should specify that the issue isn't in the include path.  I gave an arbitrary value.

 

I can call dbDelete() when it is outside of the timeOut() function.  But when I include dbDelete() inside of the timeOut() function and attempt to execture dbDelete() by calling timeOut() nothing happens.

 

My goal here is to include dbDelete() inside of timeOut() so any call to timeOut() takes care of completely destroying the session.

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.