jamesxg1 Posted March 4, 2009 Share Posted March 4, 2009 <?php error_reporting (E_ALL | E_NOTICE); error_reporting(E_ALL | E_STRICT); require("db/db.php"); $sql = "SELECT * FROM `settings`"; $query = mysql_query($sql); while ($settings = mysql_fetch_assoc($query)) { $siteurl = $settings['siteurl']; } function smiley($text) { $text = ereg_replace("", "<img src='$siteurl/template/images/smiley/cheesy.gif'>", $text); $text = ereg_replace(":@", "<img src='$siteurl/template/images/smiley/angry.gif'>", $text); $text = ereg_replace("", "<img src='$siteurl/template/images/smiley/cool.gif'>", $text); $text = ereg_replace(":'\(", "<img src='$siteurl/template/images/smiley/cry.gif'>", $text); $text = ereg_replace(":-\[", "<img src='$siteurl/template/images/smiley/embarrassed.gif'>", $text); $text = ereg_replace("", "<img src='$siteurl/template/images/smiley/grin.gif'>", $text); $text = ereg_replace(":-X", "<img src='$siteurl/template/images/smiley/lipsrsealed.gif'>", $text); $text = ereg_replace("", "<img src='$siteurl/template/images/smiley/rolleyes.gif'>", $text); $text = ereg_replace(":\(", "<img src='$siteurl/template/images/smiley/sad.gif'>", $text); $text = ereg_replace("", "<img src='$siteurl/template/images/smiley/shocked.gif'>", $text); $text = ereg_replace("", "<img src='$siteurl/template/images/smiley/smiley.gif'>", $text); $text = ereg_replace("", "<img src='$siteurl/template/images/smiley/tongue.gif'>", $text); $text = ereg_replace(":\/", "<img src='$siteurl/template/images/smiley/undecided.gif'>", $text); $text = ereg_replace("", "<img src='$siteurl/template/images/smiley/wink.gif'>", $text); return $text; } ?> Here's the error's: Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 16 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 17 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 18 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 19 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 20 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 21 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 22 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 23 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 24 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 25 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 26 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 27 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 28 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 29 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 16 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 17 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 18 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 19 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 20 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 21 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 22 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 23 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 24 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 25 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 26 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 27 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 28 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 29 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 16 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 17 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 18 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 19 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 20 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 21 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 22 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 23 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 24 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 25 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 26 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 27 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 28 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 29 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 16 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 17 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 18 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 19 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 20 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 21 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 22 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 23 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 24 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 25 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 26 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 27 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 28 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 29 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 16 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 17 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 18 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 19 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 20 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 21 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 22 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 23 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 24 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 25 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 26 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 27 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 28 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 29 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 16 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 17 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 18 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 19 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 20 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 21 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 22 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 23 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 24 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 25 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 26 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 27 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 28 Notice: Undefined variable: siteurl in C:\xampp\htdocs\simple\smiley.php on line 29 Quote Link to comment https://forums.phpfreaks.com/topic/148010-solved-notice-undefined-variable-can-someone-help-me-with-this-please-s/ Share on other sites More sharing options...
corbin Posted March 5, 2009 Share Posted March 5, 2009 It means that the variable isn't defined..... In other words, you never set a value to siteurl. Is the code that you posted with your post the code that you're actually using? Quote Link to comment https://forums.phpfreaks.com/topic/148010-solved-notice-undefined-variable-can-someone-help-me-with-this-please-s/#findComment-776857 Share on other sites More sharing options...
jamesxg1 Posted March 5, 2009 Author Share Posted March 5, 2009 It means that the variable isn't defined..... In other words, you never set a value to siteurl. Is the code that you posted with your post the code that you're actually using? yes and all i get are them errors :S, its being included by another script and it will show the images in ereg_replace on the script that is including it but when it shows the images they are broken links because the $siteurl var is not actually printing its data :S Quote Link to comment https://forums.phpfreaks.com/topic/148010-solved-notice-undefined-variable-can-someone-help-me-with-this-please-s/#findComment-776862 Share on other sites More sharing options...
sasa Posted March 5, 2009 Share Posted March 5, 2009 variable $siteurl doesn't exist inside function Quote Link to comment https://forums.phpfreaks.com/topic/148010-solved-notice-undefined-variable-can-someone-help-me-with-this-please-s/#findComment-776865 Share on other sites More sharing options...
corbin Posted March 5, 2009 Share Posted March 5, 2009 I don't know what the structure of your settings table is, but: $sql = "SELECT * FROM `settings`"; $query = mysql_query($sql); while ($settings = mysql_fetch_assoc($query)) { $siteurl = $settings['siteurl']; } looks like it's probably wrong. Oh wait! Just looked at your function code again, and apparently I missed the $siteurl part in it earlier some how. You're trying to use a variable globally. You either need to add global $siteurl; to the function or not rely on global variables. Generally global variables are bad. Quote Link to comment https://forums.phpfreaks.com/topic/148010-solved-notice-undefined-variable-can-someone-help-me-with-this-please-s/#findComment-776867 Share on other sites More sharing options...
jamesxg1 Posted March 5, 2009 Author Share Posted March 5, 2009 variable $siteurl doesn't exist inside function ok, is there anyway i can use the data from $siteurl in a function ? Quote Link to comment https://forums.phpfreaks.com/topic/148010-solved-notice-undefined-variable-can-someone-help-me-with-this-please-s/#findComment-776871 Share on other sites More sharing options...
corbin Posted March 5, 2009 Share Posted March 5, 2009 http://php.net/global Quote Link to comment https://forums.phpfreaks.com/topic/148010-solved-notice-undefined-variable-can-someone-help-me-with-this-please-s/#findComment-776874 Share on other sites More sharing options...
jamesxg1 Posted March 5, 2009 Author Share Posted March 5, 2009 http://php.net/global are global vars a vunrability ? Quote Link to comment https://forums.phpfreaks.com/topic/148010-solved-notice-undefined-variable-can-someone-help-me-with-this-please-s/#findComment-776876 Share on other sites More sharing options...
jamesxg1 Posted March 5, 2009 Author Share Posted March 5, 2009 oh well beggers cant be chooser's <?php error_reporting (E_ALL | E_NOTICE); error_reporting(E_ALL | E_STRICT); require("db/db.php"); $sql = "SELECT * FROM `settings`"; $query = mysql_query($sql); while ($settings = mysql_fetch_assoc($query)) { $siteurl = $settings['siteurl']; } function smiley($text) { global $siteurl; $text = ereg_replace("", "<img src='$siteurl/template/images/smiley/cheesy.gif'>", $text); $text = ereg_replace(":@", "<img src='$siteurl/template/images/smiley/angry.gif'>", $text); $text = ereg_replace("", "<img src='$siteurl/template/images/smiley/cool.gif'>", $text); $text = ereg_replace(":'\(", "<img src='$siteurl/template/images/smiley/cry.gif'>", $text); $text = ereg_replace(":-\[", "<img src='$siteurl/template/images/smiley/embarrassed.gif'>", $text); $text = ereg_replace("", "<img src='$siteurl/template/images/smiley/grin.gif'>", $text); $text = ereg_replace(":-X", "<img src='$siteurl/template/images/smiley/lipsrsealed.gif'>", $text); $text = ereg_replace("", "<img src='$siteurl/template/images/smiley/rolleyes.gif'>", $text); $text = ereg_replace(":\(", "<img src='$siteurl/template/images/smiley/sad.gif'>", $text); $text = ereg_replace("", "<img src='$siteurl/template/images/smiley/shocked.gif'>", $text); $text = ereg_replace("", "<img src='$siteurl/template/images/smiley/smiley.gif'>", $text); $text = ereg_replace("", "<img src='$siteurl/template/images/smiley/tongue.gif'>", $text); $text = ereg_replace(":\/", "<img src='$siteurl/template/images/smiley/undecided.gif'>", $text); $text = ereg_replace("", "<img src='$siteurl/template/images/smiley/wink.gif'>", $text); return $text; } ?> wokring thanks guy's (*) Quote Link to comment https://forums.phpfreaks.com/topic/148010-solved-notice-undefined-variable-can-someone-help-me-with-this-please-s/#findComment-776886 Share on other sites More sharing options...
corbin Posted March 5, 2009 Share Posted March 5, 2009 Technically it's not a security vulnerability, but it can become a problem if you forget what globals are named. Lets say later on you decide to use siteurl for something else... What happens then? Or what if someone else decides to the use the variable name safeurl? (Obviously you would have to be using the global version or it wouldn't apply.) Quote Link to comment https://forums.phpfreaks.com/topic/148010-solved-notice-undefined-variable-can-someone-help-me-with-this-please-s/#findComment-776894 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.