dt_gry Posted October 16, 2008 Share Posted October 16, 2008 Okay I have 2 files here, File1 logout.php calls File2 activityend.php. The problem is when I navigate via the browser to activityend.php it carries out its functions adds the record from ActiveUsers to ActivityLog and then deletes the record from ActiveUsers. However when I call for activityend.php in logout.php like include(activityend.php) $UserID is null(empty) and the none of the above is performed. I am at a loss to why it would work when navigating to it via the browser, and not when called from logout.php. Here is the code logout.php <?php include(activityend.php); session_start(); //Unset the variables stored in session unset($_SESSION['SESS_MEMBER_ID']); unset($_SESSION['SESS_FIRST_NAME']); unset($_SESSION['SESS_LAST_NAME']); ?> <?php include('includes/page_elements/global_navi.php'); ?> <h1 align="center">Logout </h1> <p align="center"> </p> <h4 align="center" class="err">You have been logged out.</h4> <p align="center">Click here to <a href="index.php?section=login">Login</a></p> activityend.php // set database connection information. // $host - the mysql server address. // $user - the username to access database. // $pass - the password to access database. // $database - the name of the database that is desired. // $table - the name of the desired table. // $CurDate - gets and stores the current date // $StartTm - gets and stores the current time // $IPadd - gets and stores the ip address of the client computer. // Gets required user data $CurDate = date('m-d-y'); $EndTm = date('H:i:s'); $IPadd = $_SERVER['REMOTE_ADDR']; if(isset($_COOKIE['UnameCookie'])) { $UserID = $_COOKIE['UnameCookie']; } // Database connection info $host = 'mysql.thegayestwebsiteever.com'; $user = 'thegayestever'; $pass = 'emit098nice054'; $database = 'useractivity_tgwse'; $Active_tbl = 'ActiveUsers'; $Log_tbl = 'ActivityLog'; // connect to the mysql database server. $connect = mysql_connect($host, $user, $pass) or die(mysql_error()); mysql_select_db($database) or die(mysql_error()); $add_info = "INSERT INTO $Log_tbl ( Uname,CurDate,StartTm,EndTm,IPadd ) SELECT Uname,CurDate,StartTm,'$EndTm',IPadd FROM $Active_tbl WHERE $Active_tbl.Uname ='$UserID'"; mysql_query($add_info) or die(mysql_error()); echo $add_info; $sql = "DELETE FROM $Active_tbl WHERE Uname = ('$UserID')"; echo $sql; mysql_query($sql); mysql_close($connect); Thanks in advance for the help guys, dt_gry Quote Link to comment Share on other sites More sharing options...
trq Posted October 16, 2008 Share Posted October 16, 2008 include expects a string. include('activityend.php'); Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted October 16, 2008 Share Posted October 16, 2008 Your include file also needs php tags in it to make it php code. Quote Link to comment Share on other sites More sharing options...
dt_gry Posted October 16, 2008 Author Share Posted October 16, 2008 Okay thorpe I fixed it and it still doesnt work. PFMaBiSmAd: they are in they just didnt copy I might have not had them highlight when I coppied it. I had it echo for me what it saw so I could see what was being held in $UserID I called activityend.php and I got a null(empty) result again. here is the revised code logout.php <?php include('activityend.php'); session_start(); //Unset the variables stored in session unset($_SESSION['SESS_MEMBER_ID']); unset($_SESSION['SESS_FIRST_NAME']); unset($_SESSION['SESS_LAST_NAME']); ?> <?php include('includes/page_elements/global_navi.php'); ?> <h1 align="center">Logout </h1> <p align="center"> </p> <h4 align="center" class="err">You have been logged out.</h4> <p align="center">Click here to <a href="index.php?section=login">Login</a></p> activityend.php <?php // set database connection information. // $host - the mysql server address. // $user - the username to access database. // $pass - the password to access database. // $database - the name of the database that is desired. // $table - the name of the desired table. // $CurDate - gets and stores the current date // $StartTm - gets and stores the current time // $IPadd - gets and stores the ip address of the client computer. // Gets required user data $CurDate = date('m-d-y'); $EndTm = date('H:i:s'); $IPadd = $_SERVER['REMOTE_ADDR']; if(isset($_COOKIE['UnameCookie'])) { $UserID = $_COOKIE['UnameCookie']; } // Database connection info $host = 'mysql.thegayestwebsiteever.com'; $user = 'thegayestever'; $pass = 'emit098nice054'; $database = 'useractivity_tgwse'; $Active_tbl = 'ActiveUsers'; $Log_tbl = 'ActivityLog'; // connect to the mysql database server. $connect = mysql_connect($host, $user, $pass) or die(mysql_error()); mysql_select_db($database) or die(mysql_error()); $add_info = "INSERT INTO $Log_tbl ( Uname,CurDate,StartTm,EndTm,IPadd ) SELECT Uname,CurDate,StartTm,'$EndTm',IPadd FROM $Active_tbl WHERE $Active_tbl.Uname ='$UserID'"; mysql_query($add_info) or die(mysql_error()); echo $add_info; $sql = "DELETE FROM $Active_tbl WHERE Uname = ('$UserID')"; echo $sql; mysql_query($sql); mysql_close($connect); ?> any more ideas what could be causing it? Thanks, dt_gry Quote Link to comment Share on other sites More sharing options...
trq Posted October 16, 2008 Share Posted October 16, 2008 Where do you set your cookie? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted October 16, 2008 Share Posted October 16, 2008 I'm going to guess those are your actual database username, password, and database name in the posts? Quote Link to comment Share on other sites More sharing options...
dt_gry Posted October 16, 2008 Author Share Posted October 16, 2008 set cookie durring login process, and the password has been changed for security. The rest is the actuall settings. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted October 16, 2008 Share Posted October 16, 2008 Add the following two lines immediately after your first <?php tag in your main file to get php to help you - ini_set ("display_errors", "1"); error_reporting(E_ALL); Quote Link to comment Share on other sites More sharing options...
dt_gry Posted October 16, 2008 Author Share Posted October 16, 2008 No bugs, or errors its just not doing it. Any more ideas? Thanks guys dt_gry Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted October 16, 2008 Share Posted October 16, 2008 Is logout.php a stand-a-lone file that you reach through clicking on a link or is it included in some other file, like your index.php? I'm going to guess this is a register globals problem and there is either a program/post/get/cookie/session variable by the name UnameCookie or UserID somewhere in the parts of the code we have not seen. Something specific that your code is going is either causing the cookie/$UserID to be empty or overwritten. If you want us to find this for you, you need to post all the files involved. Quote Link to comment Share on other sites More sharing options...
dt_gry Posted October 16, 2008 Author Share Posted October 16, 2008 Okay here is the break down when the user logs in set_cookie.php is run Set cookie.php <?php $Time = time() + 7200; //this adds 2 hours to cookie life// setcookie(LoginCookie, $Time); setcookie(UnameCookie, $login); ?> User clicks logout out button link logout.php is called <?php include('activityend.php'); session_start(); //Unset the variables stored in session unset($_SESSION['SESS_MEMBER_ID']); unset($_SESSION['SESS_FIRST_NAME']); unset($_SESSION['SESS_LAST_NAME']); ini_set ("display_errors", "1"); error_reporting(E_ALL); ?> <?php include('includes/page_elements/global_navi.php'); ?> <h1 align="center">Logout </h1> <p align="center"> </p> <h4 align="center" class="err">You have been logged out.</h4> <p align="center">Click here to <a href="index.php?section=login">Login</a></p> activityend.php is then called activityend.php <?php // set database connection information. // $host - the mysql server address. // $user - the username to access database. // $pass - the password to access database. // $database - the name of the database that is desired. // $table - the name of the desired table. // $CurDate - gets and stores the current date // $StartTm - gets and stores the current time // $IPadd - gets and stores the ip address of the client computer. // Gets required user data $CurDate = date('m-d-y'); $EndTm = date('H:i:s'); $IPadd = $_SERVER['REMOTE_ADDR']; if(isset($_COOKIE['UnameCookie'])) { $UserID = $_COOKIE['UnameCookie']; } // Database connection info $host = 'mysql.thegayestwebsiteever.com'; $user = 'thegayestever'; $pass = 'emit098nice054'; $database = 'useractivity_tgwse'; $Active_tbl = 'ActiveUsers'; $Log_tbl = 'ActivityLog'; // connect to the mysql database server. $connect = mysql_connect($host, $user, $pass) or die(mysql_error()); mysql_select_db($database) or die(mysql_error()); $add_info = "INSERT INTO $Log_tbl ( Uname,CurDate,StartTm,EndTm,IPadd ) SELECT Uname,CurDate,StartTm,'$EndTm',IPadd FROM $Active_tbl WHERE $Active_tbl.Uname ='$UserID'"; mysql_query($add_info) or die(mysql_error()); echo $add_info; $sql = "DELETE FROM $Active_tbl WHERE Uname = ('$UserID')"; echo $sql; mysql_query($sql); mysql_close($connect); ?> These are all the files that relate to this issue. Thanks for the help guys. dt_gry Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted October 16, 2008 Share Posted October 16, 2008 Your setcookie() does not have any path or domain settings set, so the cookie is only available at the path (folder) and domain (www.yourdomain.com or just yourdomain.com) where it was set at. I'm going to guess either that these files are in different folders or as you are browsing to them, some have urls like www.yourdomain.com/yourfile.php and some are just yourdomain.com/yourefile.php Quote Link to comment Share on other sites More sharing options...
dt_gry Posted October 16, 2008 Author Share Posted October 16, 2008 Okay, all these files are in the same directory, so should I maybe make the cookie global? Quote Link to comment Share on other sites More sharing options...
dt_gry Posted October 17, 2008 Author Share Posted October 17, 2008 Okay I solved my problem I had setcookie['mycookie'] and I needed setcookie['mycookie',['0',['/',['.mywebsite.com']]] Thanks guys. dt_gry Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.