Jump to content

DjMikeS

Members
  • Posts

    140
  • Joined

  • Last visited

    Never

Everything posted by DjMikeS

  1. Robbie, first I would like to welcome you to the php freaks forums. Second, there are two things wrong with your post. We don't "do" urgent requests...Everyone here is helping others in there own free time so you will just have to be patient... The other thing is that you are requesting help for a 'third party script' and thus your post should be in this forum: http://www.phpfreaks.com/forums/index.php?board=34.0 And at last, it would be helpful to tell us exactly what is going wrong....
  2. Does php work when calling a php page without the ~ ? When I try this on my own webserver, it simply displays a 404...
  3. http://nl.php.net/unlink... So...in your script that would be... <?php unlink ("/destaques/". $_GET['id'] ."); ?> Notice that I used the code tags...you should do so to!
  4. May I ask why you get such a strange value? Can you show us your db layout? Ideally, a table would have 2 fields (type and quantity) then you can easily get the values without having to go through explode and implode troubles...
  5. I'm sorry...I think I haven't explained the problem right. The usr_preferences table holds one record for each user. The field removed_hosts looks like: host1;host2;host3; etc... The nagios_services table holds one record for each service. The row looks like: host: localhost, service: check_ping, last_check: unix_time, description: Service is okay, yeah! So one host can have (and does have) multiple service checks. That's why there is a loop for $arrLastServices What I want to achieve is that $arrLastServices does NOT contain the service records of the hosts that are in the usr_preferences table....
  6. Hi all, I'm trying to write a query that will search the db using an array as where clause... Unfortunately, it only returns a single row, which it shouldn't return at all... The code: <?php function getServices($intTid, $uid) { $qryRemHosts = "SELECT removed_hosts FROM usr_preferences WHERE uid='$uid'"; try { if (!$rsltRemHosts = mysql_query($qryRemHosts)) { $mysql_error = mysql_error(); throw new Exception($mysql_error); return false; } /* if (!$rsltLastServices = mysql_query($qryLastServices)) { $mysql_error = mysql_error(); throw new Exception($mysql_error); return false; } */ else { $arrRemHosts = mysql_fetch_array($rsltRemHosts); $arrRemHosts = explode(";", $arrRemHosts[0]); //arrRemHosts looks like: Array ( [0] => localhost [1] => VOCNL01S002 ) $rsltLastServices = mysql_query ("SELECT * FROM nagios_services WHERE tid = '$intTid' AND host NOT IN ('".implode("', '", $arrRemHosts)."') ORDER BY host") or die(mysql_error()); $i = 0; $arrLastServices = array(); while($row = mysql_fetch_array($rsltLastServices)) { while(list($myVariableName,$sqlFieldName)=each($row)) { $arrLastServices[$i][$myVariableName] = $sqlFieldName; } } $i++; return $arrLastServices; } } catch (Exception $e) { $error = $e->getMessage(); $script = $e->getFile(); log_error($error, $script); return "An unexpected error has occured. This error has been logged and will be investigated as soon as possible."; } } ?> And it only returns one array with host VOCNL01S002 while it should return only rows where host is not localhost or VOCNL01S002 Can you help me ?
  7. I know that...but I don't get how to implement it, so I just made a start... Could you give me some pointers as to how I rewrite this piece of code into proper OOP?
  8. Hi all... I've read al lot about classes, but have been able to grasp it. So I decided to just start using it and see where it ends... I've written a class which, at the moment, is nothing more then a collection of functions. I would like to know if it can be done more efficient or 'nicer'.... Here's the code: <?php class nagiosStatus { function getLastUpdate() { $getLastUpdate = "SELECT id,timestamp FROM nagios_program ORDER BY id DESC LIMIT 0,1"; try { if (!$qResult = mysql_query($getLastUpdate)) { $mysql_error = mysql_error(); throw new Exception($mysql_error); return false; } else { $arrLastUpdate = mysql_fetch_array($qResult); return $arrLastUpdate; } } catch (Exception $e) { $error = $e->getMessage(); $script = $e->getFile(); log_error($error, $script); return "An unexpected error has occured. This error has been logged and will be investigated as soon as possible."; } } function getHosts($intTid) { $getLastHosts = "SELECT * FROM nagios_hosts WHERE tid = '$intTid'"; try { if (!$qResult = mysql_query($getLastHosts)) { $mysql_error = mysql_error(); throw new Exception($mysql_error); return false; } else { $i = 0; $arrLastHosts = array(); while($row = mysql_fetch_array($qResult)) { while(list($myVariableName,$sqlFieldName)=each($row)) { $arrLastHosts[$i][$myVariableName] = $sqlFieldName; } $i++; } return $arrLastHosts; } } catch (Exception $e) { $error = $e->getMessage(); $script = $e->getFile(); log_error($error, $script); return "An unexpected error has occured. This error has been logged and will be investigated as soon as possible."; } } function getServices($intTid) { $getLastServices = "SELECT * FROM nagios_services WHERE tid = '$intTid'"; try { if (!$qResult = mysql_query($getLastServices)) { $mysql_error = mysql_error(); throw new Exception($mysql_error); return false; } else { $i = 0; $arrLastServices = array(); while($row = mysql_fetch_array($qResult)) { while(list($myVariableName,$sqlFieldName)=each($row)) { $arrLastServices[$i][$myVariableName] = $sqlFieldName; } $i++; } return $arrLastServices; } } catch (Exception $e) { $error = $e->getMessage(); $script = $e->getFile(); log_error($error, $script); return "An unexpected error has occured. This error has been logged and will be investigated as soon as possible."; } } function getServiceHistory($intTid, $host, $service) { $getServiceHistory = "SELECT * FROM nagios_services WHERE host = '$host' AND service = '$service' GROUP BY last_check"; try { if (!$qResult = mysql_query($getServiceHistory)) { $mysql_error = mysql_error(); throw new Exception($mysql_error); return false; } else { $i = 0; $arrServiceHistory = array(); while($row = mysql_fetch_array($qResult)) { while(list($myVariableName,$sqlFieldName)=each($row)) { $arrServiceHistory[$i][$myVariableName] = $sqlFieldName; } $i++; } return $arrServiceHistory; } } catch (Exception $e) { $error = $e->getMessage(); $script = $e->getFile(); log_error($error, $script); return "An unexpected error has occured. This error has been logged and will be investigated as soon as possible."; } } function getHostHistory($intTid, $host) { $getHostHistory = "SELECT * FROM nagios_hosts WHERE host = '$host' GROUP BY last_check"; try { if (!$qResult = mysql_query($getHostHistory)) { $mysql_error = mysql_error(); throw new Exception($mysql_error); return false; } else { $i = 0; $arrHostHistory = array(); while($row = mysql_fetch_array($qResult)) { while(list($myVariableName,$sqlFieldName)=each($row)) { $arrHostHistory[$i][$myVariableName] = $sqlFieldName; } $i++; } return $arrHostHistory; } } catch (Exception $e) { $error = $e->getMessage(); $script = $e->getFile(); log_error($error, $script); return "An unexpected error has occured. This error has been logged and will be investigated as soon as possible."; } } } I use it like this: <?php $nagiosStatus = New nagiosStatus(); $arrLastUpdate = nagiosStatus::getLastUpdate(); $arrLastHosts = nagiosStatus::getHosts($arrLastUpdate[0]); $arrLastServices = nagiosStatus::getServices($arrLastUpdate[0]); //Do stuffy here.... ?> I appreciate any thoughts about it
  9. What most designers usually do is get the variable at the top of the page, sanitize it, and store it... Like: <?php $intProfileId = mysql_real_escape_string($_GET['profile']); ?> [code] Now $intProfileId has the id that was in the url, but it's also sanitized using mysql_real_escape_string so you can check it in a database...
  10. Oh, thnx Project, that works great...still need to clean it up a bit but the idea works!
  11. @Haku: I've tried your solutions, but that breakes the script...And the images display as a list instead of the fading header... @dropfaith: This is the relevant output to the browser: <div class="header"> <script type="text/javascript"> document.write('<ul id="header" class="header"><li><img src="http://dev.phison.nl/headerbg/code.jpg" alt="code" title="code" /></li>_ <li><img src="http://dev.phison.nl/headerbg/lake.jpg" alt="lake" title="lake" /></li>_ <li><img src="http://dev.phison.nl/headerbg/san_switch.jpg" alt="san_switch" title="san_switch" /></li>_ <li><img src="http://dev.phison.nl/headerbg/typewriter.jpg" alt="typewriter" title="typewriter" /></li>_ <li><img src="http://dev.phison.nl/headerbg/wet-flower.jpg" alt="wet-flower" title="wet-flower" /></li>_ <li><img src="http://dev.phison.nl/headerbg/yellow-field.jpg" alt="yellow-field" title="yellow-field" /></li>_ </ul>'); </script> <noscript><div><img src="http://dev.phison.nl/headerbg/lake.jpg" alt="lake" /></div></noscript> </div> For now it's merely a cosmetic problem but I would to solve it... So if anyone has a solution...
  12. Hi all, I'm trying to make my website cross browser compatible. This also means that I want it to validate as strict XHTML and I'm nearly there...just one last error... I'm using jquery to get a nice fading header which loops through some images and fades them in and out. <?php $backgrounds = ""; $arrPhotos = scandir($site_path . "headerbg"); foreach ($arrPhotos as $strPhoto) { $arrPhoto = explode (".", $strPhoto); if ($arrPhoto[1] == "jpg") { $backgrounds .= "<li><img src=\"http://dev.phison.nl/headerbg/$arrPhoto[0].$arrPhoto[1]\" alt=\"$arrPhoto[0]\" title=\"$arrPhoto[0]\" /></li>"; } } echo "<script type=\"text/javascript\">\n document.write('<ul id=\"header\" class=\"header\">$backgrounds</ul>');\n </script>\n"; ?> noscript><div><img src="http://dev.phison.nl/headerbg/lake.jpg" alt="lake" /></div></noscript> </div> So, when javascript is enabled, it shows the nice fading header, and when javascript is disabled, it shows just a single image. The validator outputs: Line 21, Column 49: document type does not allow element "ul" here. …write('<ul id="header" class="header"><li><img src="http://dev.phison.nl/head I can't put the <ul> outside the javascript tag, because that causes unexpected behavior. Does anyone know how I can keep this structure and make it XHTML Strict valid ?
  13. @twister: You almost got it... <?php //Mysql is connected $id = (int) $_GET['id']; //the ID is a integer. This is what i dont get. where will it get the ID from? if (!($id > 0)) {//if the ID is above 0 (Or 1 meaning the profile exists) $id = $_SESSION['user_id']; //display their own profile if they decide to mess with the query string too much //what? how would they do that? lol } $query = "SELECT * FROM users WHERE id=$id";//selects the ID of the user from the database from $id $result = mysql_query($query) or die(mysql_error()); //Goes to result as a query or it dies if not successful. //code of the profile is setup by arrays and SQL The integer comes from the URL (that's what $_GET does...) Little example: let's say I have an URL like: www.example.com/index.php?profile=1&user=2 You can see that I use 2 variables in the URL: profile and user <?php echo $_GET['profile']; echo $_GET['id']; //Would output: 12 ?> The if(!$id > 0) doesn't mean that the profile exists...Usually when working with databases, the id is aan auto increment value..Meaning that the database automatically assigns the value. This means that the value can't be 0, because this isn't used...So id 0 will always be a wrong number... However, you should still check if the profile exists....
  14. Something like this: http://nl.php.net/manual/en/function.simplexml-load-string.php ?
  15. You should read this: http://nl2.php.net/manual/en/function.imagesx.php That lets you get the image width as an integer...once you have that, you can just check it with an if statement... Oh, does require the GD Library to be available...you can check that with <?php phpinfo(); ?> Then look for the GD part and see if it's enabled...
  16. I've tried that and it works, but now I don't get any stylesheets and images...It rewrites every single file... My .htaccess RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f [OR] RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^section/([^/\.]+)$ index.php?section=$1 [L,QSA] example: http://dev.phison.nl/section/home As you can see it does load the correct page, it only fails to load the images, jscripts and stylesheets... Do anyone know how to correct this ?
  17. Hi all, I've got a problem with mod_rewrite and I can't figure it out. I'm trying to rewrite http://dev.phison.nl/index.php?section=home to http://dev.phison.nl/section/home/ and for some reason I keep getting the dreaded 404 error. Also, my error.log shows a "File does not exist" error...leading me to think that mod_rewrite is not enabled...But when I open phpinfo() it does appear to be loaded... Can anyone help? Some files: .htaccess RewriteEngine On RewriteLog "/var/log/apache2/dev.phison.nl/rewrite.log" RewriteLogLevel 3 RewriteRule ^/(.*)/ index.php?section=$1 My virtualhost file: <VirtualHost *:80> ServerName dev.phison.nl DocumentRoot /var/www/dev.phison.nl ServerAdmin helpdesk@phison.nl Options +ExecCGI FollowSymLinks Indexes ErrorLog /var/log/apache2/dev.phison.nl/error.log CustomLog /var/log/apache2/dev.phison.nl/access.log combined <Directory /var/www/downloads.phison.nl/*> AllowOverride All </Directory> Am I missing something ?
  18. Thnx tmallen, I know feedburner isn't limiting my ip, because when I open the feed in my browser I can refresh as much as I like... I think php is caching the feed or something... The other solution would be to create a cronjob that automagically downloads the correct file every hour or so...but I would like to have it in sync.... edit: I read something about the headers so I added this to my site: header('Expires: Fri, 25 Dec 1980 00:00:00 GMT'); // time in the past header('Last-Modified: ' . gmdate( 'D, d M Y H:i:s') . 'GMT'); header('Cache-Control: no-cache, must-revalidate'); header('Pragma: no-cache'); header('Content-Type: text/html'); But no luck yet....
  19. What kind of server is it ? Or do you have multiple servers ? As it is just for development, why not run a virtual server ? VMWare ESXi is free...
  20. I don't have the full code, but what you should do. convert the returndate into a unix timestamp with http://nl2.php.net/maketime do the same for dateneeded and compare the two. This will allow you to also work with hours of you want to.
  21. From the manual: http://nl2.php.net/mysql_info string mysql_info ([ resource $link_identifier ] ) so you should try: <?php $con = mysql_connect("localhost", "root" , ""); mysql_info($con); ?>
  22. Hi all, I've got this script to read an rss feed and display it on my website. I only want it to display the first 10 records, and leave out any items that don't belong to the "nieuws" (in english: news) category. So far so good though I think it can be done a little nicer... The real problem is that it doesn't seem to reload the feed when I reload my website...I still see the old news items while the feed has been updated... Do you know how to solve this? My code: <?php try { $strFeed = "http://feeds.feedburner.com/tweakers/mixed"; if (!$sxml = simplexml_load_file($strFeed)) { $strError = "RSS feed not available at this moment"; Throw New Exception(); } $i = 0; foreach ($sxml->channel->item as $item){ if (stristr($item->category, 'Nieuws') AND $i < 10) { echo "<li><b><a href=\"$item->link\">$item->title</a></b></li>\n"; $i++; } } unset ($sxml); } catch (Exception $e) { echo $strError; } ?>
  23. Well, then may I suggest you tidy up you code...removing all the enters for example and post it back ? this is a bit hard to read... And where is the edit button ? if (isset($_POST['edit'])) // Just calling the function when clicking a button Also, where is $date and $submitter? Ow, and please escape your variables before inserting them into a db... http://nl3.php.net/manual/en/function.mysql-real-escape-string.php
×
×
  • 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.