Jump to content

[SOLVED] include statement is not working!


dt_gry

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
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.