Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
PostPosted: Tue Aug 09, 2011 2:29 am 
Offline
Senior Newbie
User avatar

Joined: Tue Oct 26, 2010 11:14 am
Posts: 15
Hello,

For some reason, I can't get my function to work. Have looked to see if something was not set right in the php.ini file. I keep coming up with nothing, so maybe someone can see what I am blind to.

Function is to get templates from mysql. I am including it into another file. Nothing too fancy. It has always work on any server, and works on my localhost I used to develop with. But not my linode.

Ubuntu 10.04 lts, Apache 2, Php 5, Mysql(?).

Any help appreciated.


Top
   
 Post subject: To Add...
PostPosted: Tue Aug 09, 2011 2:32 am 
Offline
Senior Newbie
User avatar

Joined: Tue Oct 26, 2010 11:14 am
Posts: 15
I can take out the code in the function, put it on the page and it will load as it should. So I know mysql is good... just seems to be something up with functions?


Top
   
 Post subject:
PostPosted: Wed Aug 10, 2011 2:54 pm 
Offline
Senior Newbie
User avatar

Joined: Tue Oct 26, 2010 11:14 am
Posts: 15
functions.php >>
Code:
function mytemplate($templatename) {
   global $templatecache;
      if ($templatecache[$templatename]!="") {
         $template = $templatecache[$templatename];
      } else {
         $query = mysql_query("SELECT value FROM templates WHERE name='$templatename'");
         if (mysql_num_rows($query)!=0) {
            $template = mysql_result($query,"value");
            $template = str_replace("\"","\\\"",$template);
            $templatecache[$name] = $template;
         } else {
               $template = "<font style='color: #ff0000; font-size: 8pt; font-family: Verdana;'>No Template: <b>$templatename</b> Found!</font>";
            }
         }
   return $template;
}

And test.php >>
Code:
<?php
include("inc/functions.php");
//$query = mysql_query("SELECT value FROM templates WHERE name='tpl-a' LIMIT 1");
//$result = mysql_result($query, 0);
//echo $result;
//echo $testit;

$body = $welcome.$platform.$news.$calendar;
eval("echo \"".mytemplate("tpl-a")."\";");

?>

The lines above commented out (//) will work, but the function won't. Actually NO function will work...


Top
   
 Post subject:
PostPosted: Wed Aug 10, 2011 4:55 pm 
Offline
Senior Member

Joined: Wed Oct 20, 2010 12:11 pm
Posts: 142
Sanity check: is functions.php in the inc/ directory?


Top
   
 Post subject:
PostPosted: Wed Aug 10, 2011 5:18 pm 
Offline
Senior Newbie
User avatar

Joined: Tue Oct 26, 2010 11:14 am
Posts: 15
Yes functions.php is in /inc. I know it's including because I put in a variable in functions.php and it echos on test.php.


Top
   
 Post subject:
PostPosted: Thu Aug 11, 2011 1:34 am 
Offline
Senior Newbie

Joined: Sun Dec 20, 2009 1:57 am
Posts: 5
change
Code:
$templatecache[$name] = $template; 

to
Code:
$templatecache[$templatename] = $template; 


Top
   
 Post subject:
PostPosted: Fri Aug 12, 2011 2:16 pm 
Offline
Senior Newbie
User avatar

Joined: Tue Oct 26, 2010 11:14 am
Posts: 15
Thanks for your help guys. I tried changing $templatecache[$templatename] variable, but did not work.

I got looking over my installation and I followed the LAMP guide here @ the library. I did install php5-suhosin. So I have been looking into that as a possible.

In my /var/log/apache2/error.log >>
Code:
PHP Deprecated:  Comments starting with '#' are deprecated in /etc/php5/apache2/conf.d/mcrypt.ini on line 1 in Unknown on line 0
[Mon Aug 08 17:47:21 2011] [notice] Apache/2.2.14 (Ubuntu) PHP/5.3.2-1ubuntu4.9 with Suhosin-Patch mod_ssl/2.2.14 OpenSSL/0.9.8k configured -- resuming normal operations
[Mon Aug 08 17:49:08 2011] [notice] caught SIGTERM, shutting down

I corrected the # to a ; in mcrypt.ini. Also looked in my php.ini & suhosin.ini files... All of the lines in the suhosin.ini file were ';' commented out. I tried turning on: >>
Code:
suhosin.executor.disable_eval = off
suhosin.simulation = on

But it did not work. And I don't see any mention of suhosin in php.ini or apache2.conf anywhere. Think this suhosin extension isn;t configured properly and to blame?


Top
   
PostPosted: Fri Aug 12, 2011 2:27 pm 
Offline
Senior Newbie
User avatar

Joined: Tue Oct 26, 2010 11:14 am
Posts: 15
Code:
; configuration for php suhosin module
extension=suhosin.so

;;;;;;;;;;;;;;;;;;;
; Module Settings ;
;;;;;;;;;;;;;;;;;;;
; the following values are the internal default settings and set implicit
; feel free to modify to your needs
; documentation can be found at:
; http://www.hardened-php.net/suhosin/configuration.html

[suhosin]
; Logging Configuration
;suhosin.log.syslog =
;suhosin.log.syslog.facility = 9
;suhosin.log.syslog.priority = 1
;suhosin.log.sapi =
;suhosin.log.script = 0
;suhosin.log.phpscript = 0
;suhosin.log.script.name =
;suhosin.log.phpscript.name =
;suhosin.log.use-x-forwarded-for = off

; Executor Options
;suhosin.executor.max_depth = 0
;suhosin.executor.include.max_traversal = 0
;suhosin.executor.include.whitelist =
;suhosin.executor.include.blacklist =
;suhosin.executor.include.allow_writable_files = on
;suhosin.executor.func.whitelist =
;suhosin.executor.func.blacklist =
;suhosin.executor.eval.whitelist =
;suhosin.executor.eval.blacklist =
;suhosin.executor.disable_eval = off
;suhosin.executor.disable_emodifier = off
;suhosin.executor.allow_symlink = off

; Misc Options
;suhosin.simulation = on
;suhosin.apc_bug_workaround = off
;suhosin.sql.bailout_on_error = off
;suhosin.sql.user_prefix =
;suhosin.sql.user_postfix =
;suhosin.multiheader = off
;suhosin.mail.protect = 0
;suhosin.memory_limit = 0

; Transparent Encryption Options
;suhosin.session.encrypt = on
;suhosin.session.cryptkey =
;suhosin.session.cryptua = on
;suhosin.session.cryptdocroot = on
;suhosin.session.cryptraddr = 0
;suhosin.session.checkraddr = 0
;suhosin.cookie.encrypt = on
;suhosin.cookie.cryptkey =
;suhosin.cookie.cryptua = on
;suhosin.cookie.cryptdocroot = on
;suhosin.cookie.cryptraddr = 0
;suhosin.cookie.checkraddr = 0
;suhosin.cookie.cryptlist =
;suhosin.cookie.plainlist =

; Randomness
;suhosin.srand.ignore = on
;suhosin.mt_srand.ignore = on

; Filtering Options
;suhosin.filter.action =
;suhosin.cookie.max_array_depth = 100
;suhosin.cookie.max_array_index_length = 64
;suhosin.cookie.max_name_length = 64
;suhosin.cookie.max_totalname_length = 256
;suhosin.cookie.max_value_length = 10000
;suhosin.cookie.max_vars = 100
;suhosin.cookie.disallow_nul = on
;suhosin.get.max_array_depth = 50
;suhosin.get.max_array_index_length = 64
;suhosin.get.max_name_length = 64
;suhosin.get.max_totalname_length = 256
;suhosin.get.max_value_length = 512
;suhosin.get.max_vars = 100
;suhosin.get.disallow_nul = on
;suhosin.post.max_array_depth = 100
;suhosin.post.max_array_index_length = 64
;suhosin.post.max_name_length = 64
;suhosin.post.max_totalname_length = 256
;suhosin.post.max_value_length = 1000000
;suhosin.post.max_vars = 1000
;suhosin.post.disallow_nul = on
;suhosin.request.max_array_depth = 100
;suhosin.request.max_array_index_length = 64
;suhosin.request.max_totalname_length = 256
;suhosin.request.max_value_length = 1000000
;suhosin.request.max_vars = 1000
;suhosin.request.max_varname_length = 64
;suhosin.request.disallow_nul = on
;suhosin.server.encode = on
;suhosin.server.strip = on
;suhosin.upload.max_uploads = 25
;suhosin.upload.disallow_elf = on
;suhosin.upload.disallow_binary = off
;suhosin.upload.remove_binary = off
;suhosin.upload.verification_script =
;suhosin.session.max_id_length = 128
;suhosin.coredump = off
;suhosin.protectkey = 1
;suhosin.stealth = 1
;suhosin.perdir = "0"


Top
   
 Post subject:
PostPosted: Sat Aug 13, 2011 5:19 pm 
Offline
Junior Member

Joined: Thu Jun 16, 2011 12:49 am
Posts: 27
First, I believe the function mysql_result is incorrectly written. The second parameter of mysql_result is a row number, so...
Quote:
$template = mysql_result($query,"value");
should become something like
Quote:
$template = mysql_result($query,0,"value");


Secondly, why do you need to use an eval()? Can't you just do something like:
Quote:
echo mytemplate("tpl-a");


If all the suggestions above have been tried, have you tried doing an echo inside the function to check if the function runs in the first place? So, echoing out the value of $template within the function instead of returning the value.

Good luck!


Top
   
 Post subject:
PostPosted: Thu Aug 18, 2011 3:23 pm 
Offline
Senior Newbie
User avatar

Joined: Tue Oct 26, 2010 11:14 am
Posts: 15
Quote:
$template = mysql_result($query, 0, "value");

Fixed my issue. Thank you & everyone who helped me out.

I was using eval to use variables in my template (from the mysql db).


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group