Current location: Hot Scripts Forums » Programming Languages » PHP » define issues, I think


define issues, I think

Reply
  #1 (permalink)  
Old 11-17-09, 02:06 AM
connor connor is offline
Wannabe Coder
 
Join Date: Apr 2005
Location: Knob Noster, Mo
Posts: 228
Thanks: 1
Thanked 0 Times in 0 Posts
Hazard define issues, I think

Ive been looking at the code for like an hour and then even started over to see if I messed something up, but I am getting the same result, and thats nothing. Most these pages are stolen from scripts that I have made before, but the defines are something I have changed...

index.php
PHP Code:

<?PHP

session_start
();
define('__sn'1);
include 
"config.php";
$layout->head();
if(isset(
$_SESSION['UINFOSTAFF'])){
    echo 
"hello";
}else{
    echo 
"hello";
}
$layout->foot();
?>
config.php
PHP Code:

<?PHP

defined
('__sn') or die();
define('__sn'1);
$CONF['__THEME']="opening";
$MYSQL['__HOST']="localhost";
$MYSQL['__DBAS']="XXXXXXXX";
$MYSQL['__USER']="XXXXXXXX";
$MYSQL['__PASS']="XXXXXXXXXXXX";
$SITE['__NAME']="SoldiersNet";
$SITE['__MAINURL']="http://soldiersnet.net/"//Must include trailing "/"
###############################
# DO NOT EDIT BELOW THIS LINE #
###############################
$CONF['__VERSION']="1.0a";
include 
"includes/db.php";
    
$db=new db($MYSQL['__HOST'],$MYSQL['__USER'],$MYSQL['__PASS'],$MYSQL['__DBAS']);
    
$db->newconn();
include 
"includes/layout.php";
    
$layout=new layout($db);
include 
"includes/functions.php";
    
$user=new user($db);
    
$app=new app($db);
?>
includes/db.php
PHP Code:

<?PHP

defined
('__sn') or die(); 
class 
db{
    var 
$host      "";
    var 
$user      "";
    var 
$pass      "";
..... 
too big of a file....
includes/layout.php
PHP Code:

<?PHP

defined
('__sn') or die();
define('__sn'1);
include 
"../config.php";
class 
layout{
    function 
layout($db){
        
$this->db=$db;
    }
    function 
head(){
.... 
too big of a file....
includes/functions.php
PHP Code:

<?PHP

defined
('__sn') or die();
class 
user {
    
$db=0;
    function 
user($db){
        
$this->db=$db;
    }
}
class 
app {
    
$db=0;
    function 
app($db){
        
$this->db=$db;
    }
    function 
userApps($ui){
        echo 
"<!-- APP LOADER: Loading Apps-->";
        
$uinfo=explode("|",$ui);
        
$this->db("SELECT * FROM users WHERE id='".$uinfo[0]."'");
        while(
$row=$this->db->fetch_array()){
            
$uperm=explode(",",$row['permissions']);
            if(
$uperm=="(*)"){
                    
            }else{
                
$permid=explode(",",$uperm);
                foreach(
$permid as $value){
                    
$this->db->query("SELECT * FROM apps WHERE id='".$value."'");
                    while(
$rowa=$this->db->fetch_array()){
                        if (
file_exists("<acronym title="JavaScript">js</acronym>/apps/".$rowa['location']."/index.<acronym title="JavaScript">js</acronym>.php")){
                            echo 
"
                            <!-- Loaded: "
.$rowa['name']." -->";
                            echo 
"
                            <script type=\"text/javascript\" src=\"apps/"
.$rowa['location']."/index.<acronym title="JavaScript">js</acronym>.php\"></script>";
                        }else{
                            echo 
"
                            <!-- Error: "
.$rowa['name']." does not exist! -->";
                        }
                    }
                }
            }
        }
        unset(
$uinfo,$row,$rowa,$uperm,$permid,$value);
    }
}
?>
__________________
Connor Strandt
JCS Photography
www.JCStrandt.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 11-18-09, 10:33 PM
Jcbones Jcbones is offline
Aspiring Coder
 
Join Date: Mar 2009
Location: North Carolina, USA
Posts: 516
Thanks: 5
Thanked 47 Times in 44 Posts
Turn on your error checking, and echo out mysql_error() to see if your queries are failing.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 11-19-09, 08:25 PM
connor connor is offline
Wannabe Coder
 
Join Date: Apr 2005
Location: Knob Noster, Mo
Posts: 228
Thanks: 1
Thanked 0 Times in 0 Posts
The database script was working fine until I added the defines..
__________________
Connor Strandt
JCS Photography
www.JCStrandt.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 11-20-09, 01:33 AM
connor connor is offline
Wannabe Coder
 
Join Date: Apr 2005
Location: Knob Noster, Mo
Posts: 228
Thanks: 1
Thanked 0 Times in 0 Posts
On all the pages after removing the define I am getting this error and am not sure what to change to make it work.
Quote:
Originally Posted by alphaServer
Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 19456 bytes) in /home/sn/public_html/staff/includes/db.php on line 38
__________________
Connor Strandt
JCS Photography
www.JCStrandt.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 11-20-09, 05:33 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,074
Thanks: 11
Thanked 88 Times in 83 Posts
You can not re-define constants. That would defeat the purpose. Define it once in the index.php (and other MAIN) pages, and do the check only on the included pages.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 11-20-09, 08:02 AM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,516
Thanks: 20
Thanked 109 Times in 106 Posts
You might have a circular include with layout.php.

You could change from include to include_once.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 11-28-09, 09:39 AM
connor connor is offline
Wannabe Coder
 
Join Date: Apr 2005
Location: Knob Noster, Mo
Posts: 228
Thanks: 1
Thanked 0 Times in 0 Posts
Arrow

Ok, Ive changed some stuff around and still am having no luck, here are the current files and I know there is a lot of stuff commented out, Ive been doing some troubleshooting trying to find out what file is messed up, at least...

index.php
PHP Code:

<?PHP

session_start
();
//define('__sn', 1);
include('config.php'); // Include all config vars.
include('inc.php'); // Include all classes and functions.
$layout->headStart();
if(isset(
$_SESSION['UINFOSTAFF'])){
    echo 
"hello";
}else{
    echo 
"hello";
}
$layout->footStart();
?>
inc.php
PHP Code:

<?PHP

//defined('__sn') or die();
//define('__sn', 1);
include('config.php');
//include('includes/db.php');
//    $db=new db($MYSQL['__HOST'],$MYSQL['__USER'],$MYSQL['__PASS'],$MYSQL['__DBAS']);
//    $db->newconn();
include('includes/layout.php');
    
$layout = new layout();
//include "includes/functions.php";
//    $user=new user($db);
//    $app=new app($db);
?>
config.php
PHP Code:

<?PHP

//defined('__sn') or die();
//define('__sn', 1);
$CONF['__THEME']="opening";
$CONF['__DEBUG']="1"// 0=OFF; 1=ON
$MYSQL['__HOST']="localhost";
$MYSQL['__DBAS']="XXXXXXXX";
$MYSQL['__USER']="XXXXXXXX";
$MYSQL['__PASS']="XXXXXXXXXXXXXXXXXXXX";
$SITE['__NAME']="SoldiersNet";
$SITE['__MAINURL']="http://soldiersnet.net/"//Must include trailing "/"
###############################
# DO NOT EDIT BELOW THIS LINE #
###############################
$HARD['__VERSION']="1.0a";
?>
include/backend.php
PHP Code:

<?PHP

//defined('__sn') or die();
//define('__sn', 1);
include "../config.php";
include 
"../inc.php";
switch(
$_GET['op']){
    case
'login':
        
$un=$_POST['userName'];
        
$pw=$_POST['userPassword'];
        
$db->query("SELECT * FROM users WHERE username='".$un."'");
        if(
$db->num_rows()>0){
            while(
$row=$db->fetch_array()){
                if(
$row['password']==md5($pw)){
                    
// Login passed.
                    
$l_login=time();
                    if(
$db->query("UPDATE users SET last_login='".$l_login."', last_ip='".$_SERVER['REMOTE_ADDR']."'")){
                        
$user_info=array($row['id'],$row['username'],$row['password']);
                        
$_SESSION['UINFOSTAFF']=implode("|",$user_info);
                        
$result["success"] = true;
                    }else{
                        
$result["success"] = false;
                        
$result["errors"]["reason"] = "The database denied the request, please try again. [backend.php?op=login:103]";
                    }
                }else{
                    
// Login failed because the passwords didn't match.
                    
$result["success"] = false;
                    
$result["errors"]["reason"] = "Your password didn't match the one in the database. [backend.php?op=login:102]";
                }
            }
        }else{
            
// Login failed because email wasn't in the db.
            
$result["success"] = false;
            
$result["errors"]["reason"] = "That email wasn't in the database. [backend.php?op=login:101]";
        }
        echo 
json_encode($result);
    break;
    case
'logout':
        if(isset(
$_SESSION['UINFOSTAFF'])){
            
$_SESSION['UINFOSTAFF']=="";
            echo 
"Logged out";
        }else{
            echo 
"never logged in";
        }
    break;
}
?>
include/db.php
PHP Code:

<?PHP

//defined('__sn') or die();
//define('__sn', 1);
class db{
    var 
$host      "";
    var 
$user      "";
    var 
$pass      "";
    var 
$datb      "";
    var 
$errordesc "";
    var 
$errorno   "";
    
// Query vars
    
var $queryid 0;
    var 
$results = array();
    function 
db($host,$user,$pass,$datb){
        
$this->host=$host;
        
$this->user=$user;
        
$this->pass=$pass;
        
$this->datb=$datb;
    }
    
// Create Database Connection \\
    
function newconn(){
        
$this->connection = @mysql_connect($this->host$this->user$this->pass);
        if(!
$this->connection){
            
$this->error("Couldn't connect to host: ".$this->host."");
        }else
        if(!@
mysql_select_db($this->datb$this->connection)){
            
$this->error("Couldn't connect to database: ".$this->datb."");
        }
    }
    
// Create a Database Query \\
    
function query($query){
        
$this->queryid = @mysql_query($query$this->connection);
        return 
$this->queryid;
    }
    
// Count Rows \\
    
function num_rows(){
        
$this->num=mysql_num_rows($this->queryid);
        return 
$this->num;
    }
    
// Fetch an array out of a database \\
    
function fetch_array($id=-1){
        if(
$id==-1){
            
$res=@mysql_fetch_array($this->queryid);
        }else{
            
$res=@mysql_fetch_array($id);
        }
        return 
$res;
    }
    
// Insert into a table \\
    
function insert($table$data){
        
    }
    
// Update a table \\
    
function update($table$data$where){
    }
    
// Delete out of a table \\
    
function delete($table$where){
        
    }
    
// Output errors \\
    
function error($str=""){
        
$this->errordesc=mysql_error();
        
$this->errorno=mysql_errno();
        if(
$CONF['__DEBUG']=="1"){
            echo 
"<b>Error Message:</b>&nbsp;".$str."<br><br><b>MySQL Error (#".$this->errorno."):</b>&nbsp;".$this->errordesc."";
        }else{
            echo 
"<b>Error Type:</b>&nbsp;Configuration Error<br><br><b>There was an error on the $conf['debug'] line in your config file.";
        }
    }
}
?>
include/functions.php
PHP Code:

<?PHP

//defined('__sn') or die();
//define('__sn', 1);
include "../config.php";
include 
"../inc.php";
class 
user {
    var 
$db=0;
    function 
user($db){
        
$this->db=$db;
    }
}
class 
app {
    var 
$db=0;
    function 
app($db){
        
$this->db=$db;
    }
    function 
userApps($ui){
        echo 
"<!-- APP LOADER: Loading Apps-->";
        
$uinfo=explode("|",$ui);
        
$this->db("SELECT * FROM users WHERE id='".$uinfo[0]."'");
        while(
$row=$this->db->fetch_array()){
            
$uperm=explode(",",$row['permissions']);
            if(
$uperm=="(*)"){
                    
            }else{
                
$permid=explode(",",$uperm);
                foreach(
$permid as $value){
                    
$this->db->query("SELECT * FROM apps WHERE id='".$value."'");
                    while(
$rowa=$this->db->fetch_array()){
                        if (
file_exists("js/apps/".$rowa['location']."/index.js.php")){
                            echo 
"
                            <!-- Loaded: "
.$rowa['name']." -->";
                            echo 
"
                            <script type=\"text/javascript\" src=\"apps/"
.$rowa['location']."/index.js.php\"></script>";
                        }else{
                            echo 
"
                            <!-- Error: "
.$rowa['name']." does not exist! -->";
                        }
                    }
                }
            }
        }
        unset(
$uinfo,$row,$rowa,$uperm,$permid,$value);
    }
}
?>
include/layout.php
PHP Code:

<?PHP

//defined('__sn') or die();
//define('__sn', 1);
include('../config.php');
class 
layout {
    
//function layout(){
        //$this->db=$db;
    //}
    
function headStart(){
        global 
$SITE,$CONF;
        echo 
"<html>
        <head>
            <meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">
            <title>"
.$SITE['__NAME']." - Staff Portal</title>
            <link rel=\"shortcut icon\" href=\"images/favicon.ico\">
            <!-- CSS -->
            <link rel=\"stylesheet\" type=\"text/css\" href=\"../lib/ext/resources/css/ext-all.css\">
            <!-- <link rel=\"stylesheet\" type=\"text/css\" href=\"../theme/"
.$CONF['theme']."/style.css\"> -->
            <!-- GC -->
            <!-- LIBS -->
            <script type=\"text/javascript\" src=\"../lib/ext/adapter/ext/ext-base.js\"></script>
            <script type=\"text/javascript\" src=\"../lib/ext/adapter/ext/ext-all.js\"></script>
            <!-- ENDLIBS -->
            <script type=\"text/javascript\" src=\"../lib/ext/ext-all-debug.js\"></script>"
;
            
//if(isset($_SESSION['UINFOSTAFF'])){
            //    $app->userApps($_SESSION['UINFOSTAFF']);
            //}
        
echo "</head>
        <body scroll=\"no\" bgcolor=\"#B7BBBE\">"
;
    }
    function 
footStart(){
        global 
$CONF;
        echo 
"<div align=\"right\" style=\"color:#666666; margin-bottom:0px; margin-right:0px;\">Version: ".$HARD['__VERSION']."</div>";
        if(
$CONF['__DEBUG']==1){
            echo 
"<div align=\"center\" style=\"color:#666666; margin-bottom:0px; margin-right:0px;\">&lt;&gt;&lt;&gt; CONFIG IS SET TO DEBUG &lt;&gt;&lt;&gt;</div>";
        }
        echo 
"</body>
        </html>"
;
    }
}
?>
Any help will be greatly appreciated, I really am just looking to push forward in this project.
__________________
Connor Strandt
JCS Photography
www.JCStrandt.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #8 (permalink)  
Old 11-28-09, 10:04 AM
Jcbones Jcbones is offline
Aspiring Coder
 
Join Date: Mar 2009
Location: North Carolina, USA
Posts: 516
Thanks: 5
Thanked 47 Times in 44 Posts
Where are you defining your constants?


I don't see that, I may be blind.

or is your only constant "__sn" ?


Edit: When testing or developing, you should have all error reporting turned on. I noticed you have some error suppression in your scripts. I would take all of that out. Something is getting sent. It always is. The error's are getting dropped due to suppression.

Last edited by Jcbones; 11-28-09 at 10:19 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #9 (permalink)  
Old 11-28-09, 10:10 AM
connor connor is offline
Wannabe Coder
 
Join Date: Apr 2005
Location: Knob Noster, Mo
Posts: 228
Thanks: 1
Thanked 0 Times in 0 Posts
On the page that is including the other page, but __SN isn't active right now because I took them out. I dont think that the defines are the problem anymore, now Im clueless to what is wrong...
__________________
Connor Strandt
JCS Photography
www.JCStrandt.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #10 (permalink)  
Old 11-28-09, 10:26 AM
Jcbones Jcbones is offline
Aspiring Coder
 
Join Date: Mar 2009
Location: North Carolina, USA
Posts: 516
Thanks: 5
Thanked 47 Times in 44 Posts
Run this and see what happens.

index.php
PHP Code:

<?PHP
session_start
();
error_reporting(E_ALL);
//define('__sn', 1);
include('config.php'); // Include all config vars.
include('inc.php'); // Include all classes and functions.
$layout->headStart();
if(isset(
$_SESSION['UINFOSTAFF'])){
    echo 
"hello";
}else{
    echo 
"hello";
}
$layout->footStart();
?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Item Database Issues The Knowing PHP 15 11-19-09 06:42 PM
define() and include problem darkcarnival PHP 15 04-23-07 10:36 AM
difference between typedef and #define KSB C/C++ 1 10-09-06 05:34 PM
Include problem in C bkbenson C/C++ 4 02-08-05 05:24 AM
Constants, define(), and HTML Amulet PHP 5 01-10-05 05:55 PM


All times are GMT -5. The time now is 12:27 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.