
HaLo2FrEeEk
Members-
Posts
724 -
Joined
-
Last visited
Never
Everything posted by HaLo2FrEeEk
-
I'm trying to optimize my site and the first thing on my list is my stats file. This file contains all the queries that my site uses, but not all queries are used on every page. For example, the page gets all the information for news posts, tutorials, roster, podcast...everything, but the news page only uses the news post query. I have no way of telling the page to only run the news post query, meaning that everytime any page that includes this stats file is requested, it runs all queries. This is obviously bad for multiple reason, the most obvious being server stress and page load times. I'd like to figure out how to tell that page to only load the queries I want it to. There are some queries there that every page does use, like number of posts and users, etc. Those will have to always be run. My idea was to simply put the ones that I wanted to control inside functions. Right now I've got my news query as, say, this: $news = mysql_query("[query]"); And on the news page, I use that by doing this: while($info = mysql_fetch_assoc($news)) { [...] } So I thought if I put the news query inside a function, like this: function fetch_news() { $news = mysql_query("[query]"); return $news; } Then changed my code on my news page to this: while($info = mysql_fetch_assoc(fetch_news())) { [...] } That it would work. Well, it doesn't. The page thinks and thinks and thinks for a long time, then gives me a 500 Server Error. What can I do to make those queries run from a function, or if a better way exists to make sure I'm only running them when I need them, how can I do that? Thanks in advance. EDIT: Actually, on further investigation, I get a mysql_error() message: Fatal error: Cannot redeclare fetch_roster() (previously declared in [stats.php path]:24) in [stats.php path] on line 27 This was the function I was using, lines 24-27 of stats.php: function fetch_roster() { GLOBAL $link; $roster = mysql_query('SELECT * FROM roster ORDER BY role=\'Peon\', role=\'Member\', role=\'Staff\', role=\'Overlord\'', $link) or die(mysql_error()); return $roster; } And my code to use it in roster.php: while($info = mysql_fetch_assoc(fetch_roster())) { [...] } EDIT Again: Nope, I was getting that error because I included header.php, which included stats.php, but I was also including stats.php in the roster.php file, so I was including stats.php twice. I still have the issue of the page loading for a long time then giving me a 500 Server Error.
-
I'm sorry, I figured it out guys, I was using this string for my date function: l, F d, Y g:m:s a minutes isn't m it's i, so it should be: l, F d, Y g:i:s a It's working now. Sorry for the useless thread.
-
I'm trying to make a countdown to a certain date by taking the current time and subtracting it from a timestamp of a future date. For the future date I'm using strtotime(). This is the string I'm using: strtotime("3 May 2010"); But the returned timestamp gives me Monday, May 3, 2010 12:05:00 am. Why is it adding 5 minutes to my timestamp? I've tried changing the string I'm using for my time, I've tried these: 3 may 2010 midnight 3 may 2010 12:00 am 3 may 2010 00:00 None seem to work, I'm still getting 12:05 am. Even if I put 1:30 am or something like that it goes to 1:05. Can anyone think of a reason for this?
-
I'm mainly concerned with Google results, I don't really care about Yahoo. Google does really well with parameters on URLs, but all the same I would like to help it out as much as possible. Like I said it doesn't make a difference what your extension is, as long as there are no parameters. .php, .html, it doesn't matter. None of the URLs I'm using have parameters, so Google sees it as a static URL.
-
It doesn't affect the SEO in any way to have a .php ending as opposed to a .html ending, I know that. I also have no reason to hide the scripting language I'm using, I make it pretty obvious to anyone that reads the site. Also, the .php ending does denote a static URL, it doesn't have an parameters and the URL never changes.
-
By original page, do you mean this: http://infectionist.com/news[LinkID]/[news title].php If so then no, that page isn't accessible, it doesn't even exist, it's simply a rewrite of the click counter redirect, the URL for which is this: http://infectionist.com/pages/clicky/clicky.php?id=[LinkID] I haven't had any problems with my current mod rewrite, so I don't think I'll change anything. I just want google to see that .php link and index the url with the news title.
-
I recently redid my site to better support rewritten URLs to give Google and other search engines an easier time indexing. I'm trying to decide which redirect code I should use so that the search engine (I'm mainly focusing on Google) will see the rewritten "static" url and index it, but it still knows that it's a redirect to another post. For example, I make news posts on my frontpage that are associated with a certain LinkID, that LinkID is associated with a URL for, say, a post on the forum. When someone clicks the redirect link on the frontpage they're taken to the full post. I do it this way so I can track clicks to each specific link and display it. A rewritten redirect URL looks like this: http://infectionist.com/news[LinkID]/[news title].php The news title is, obviously, the title of the news post, but it doesn't have to be there. So any suggestions as to which redirect HTTP code I should use?
-
I have the library that that site offers, it's free if the site it will be used on is non-profit or doesn't show ads, and either way how are they going to know? Anyway, it looks like PHP is going to be the way to go. I was looking for a way to give the users a choice, I thought mod rewrite can access cookies though, can't it? HTTP_COOKIE right? Is PHP just simpler to use in this case, or will mod_rewrite really not work? I'm not arguing against the effectiveness of PHP, it would definitely be nice to use something I understand. I just have an idea. I could automatically redirect all mobile browsers to the mobile version of the site using mod_rewrite if a cookie is not present, then provide a link to take the person back to the full version. This link would go to a redirection page which would set the cookie, then the next time the person went to the site, the mod_rewrite would read the cookie and determine if the user wanted the mobile version or full version. That would work too, right?
-
Well, thank you for the reply, but I'm disinclined to take advice with a caveat of "I don't see what could go wrong." I've heard advice now telling me to put it at the beginning, before my main site's rewriterules, and you telling me to put it at the end. And I'll still need help with the rewritecond part.
-
Ok, I've done a little research on this subject and I've come up with 2 good methods. The first uses a PHP script that detects the $_SERVER['HTTP_USER_AGENT'] variable and parses it for information that might indicate that the browser is a mobile one. This works well, I tested it with my Motorola Droid with Android 2.0.1 and it successfully reported not only that I was on a mobile browser, but also that I was on an android device. However, I learned about another way, using a similar concept. Mod_Rewrite. I've done some searching and uncovered a few mod rewrite commands that will redirect a mobile browser, but I haven't tried any of them, mostly because I've got other RewriteRules already present on my site. My main question is what is going to be the best method? Logic leans toward Mod_Rewrite because it occurs before the page is even loaded, meaning I won't have to even run the PHP script in the first place. My second question, if I do go with Mod_Rewrite, will the RewriteCond's and RewriteRules interfere with the ones I already have implemented? The ones I have right now are things to redirect from subfolders to subdomains where I've moved files to keep organized, or to rewrite dynamic pages with parameters to static-looking pages. I don't want those to be disrupted, but I want all mobile browsers to be redirected to the mobile version of the site. Can someone help me out? I should also note that I'm not very good at the Regular Expressions used in Mod Rewrite, so I might need help with that, too.
-
Dynamically changing colors in an image
HaLo2FrEeEk replied to HaLo2FrEeEk's topic in PHP Coding Help
Bump please, guys. mattal, you helped me out first, can't you help me finish this? -
Dynamically changing colors in an image
HaLo2FrEeEk replied to HaLo2FrEeEk's topic in PHP Coding Help
Bump, please I need help with this! I really can't figure it out, I've tried everything I can think of. I don't want to use ImageMagick because I don't have IMagick installed (ImageMagick for PHP) so I'd have to save the image then display it. There has to be a way to do it, it can't be impossible. -
Dynamically changing colors in an image
HaLo2FrEeEk replied to HaLo2FrEeEk's topic in PHP Coding Help
Well 2 things I notice straight off the bat. You're replacing using exact colors, meaning the gradient replacement does absolutely nothing. Next, when replacing colors in an image like the second one I posted (background_12) there is a fringe around the edges of the color changes, example: Notice the little line around the edges? There has to be a way to utilize the alpha channel provided in the BMP or TGA versions of these images. -
If you use Firefox and have the add-on Firebug installed then you can monitor how this is performed most likely: polling. I use IE, and I won't change to Firefox, and I don't really NEED to know how it's done, though it would have come in handy a few months ago when I was helping a friend with a chat script.
-
Dynamically changing colors in an image
HaLo2FrEeEk replied to HaLo2FrEeEk's topic in PHP Coding Help
Apology for the broken image in the first post, here's what it was supposed to be: -
It's not possible to have a "live" chat over HTTP. be "live" I mean the instant that a person on one computer writes a message it shows up on the other computer(s). The closest you'd be able to get is using AJAX to refresh the message list every few seconds, but then there will still be a pause between the time when a message is written and when it shows up. I haven't been able to figure out how to make instant chat, though I haven't really diligently tried, but it's obviously possible since Google does it.
-
Switch statements are probably a lot cleaner than using an if...then statement because you can add to them much easier, but whatever, both will work fairly similarly.
-
Add a hiden input to your form, name it something like "act" or "do", set it's value to something like "search", then make a switch statement using the value of do: psuedo-code: <?php $do = $_GET['do']; switch($do){ case "search": // Do search stuff break; default: // Print the form break; } ?> Of course, you'll want to also include the rest of your code, this was just a simple example, I don't want to give you the answer, you'll have to figure out a bit on your own
-
Ok, I have a base image, or actually multiple base images, that use certain colors to map a replacement area. Here is an example of a base image: The blue needs to be replaced with one color and the transparency needs to be another color. This one seems like it would be simple, just replace the blue with the color I want and the alpha with the other color, right? Well I can't seem to find a GD function that does this, and there's the issue of images like these: With the gradient. Anyone have any ideas? As a side note, I'd really rather not do this pixel by pixel, I think that'd take way to long and be way to taxing on the server, these images are all 256x256, that's 65,536 pixels I'd have to check...EVERYTIME the image is loaded. As a reference, with the number of foregrounds, backgrounds, and colors I have to work with, there are a total of 429,981,696 possible unique combinations of primary color, secondary color, foreground, and background images. I don't want to do each image pxel by pixel as it loads. And as a final piece of information, I have TGA versions of all these images that include an alpha channel. In my tests in Photoshop, when I created 2 layers, filled the one on top with what I wanted my primary color to be, and filled the bottom one with my secondary color, then selected, and deleted, the alpha from the base image, I got a perfect result. Is there any way to make an equivalent of this using PHP? Meaning, can PHP access and use the Alpha channel from a, say, BMP or TGA image?
-
Well I'm going to be processing all files with .wma, .mp3, and .wav extensions, would that be similar enough code? I can do this: <?php $path = "./"; $handle = opendir($path); $allow = array("wma", "mp3", "wav"); while(($file = $readdir($handle) != false) { $ext = substr(strtolower($file), strrpos($file, ".")+1, strlen($file)); if(filetype($path.$file) == file && in_array($ext, $allow)) { // Only adds the files to the array if the extension is in the $allow array $files[] = $file; } } foreach($files as $file) { if($file != ($ren = str_replace(" ", "_", $file))) { rename($file, $ren); echo "File ".$file." renamed to ".$ren; } else { echo "No spaces in filename, skipping"; } echo "<br>"; } ?> That should get the job done, right? And I only need to do this once, not like, on a schedule or anything. It's just because I have files already there that have spaces that need to not have spaces, future uploaded files will have no spaces, I just don't feel like manually renaming hundreds of files.
-
I need to know how to rename files in a directory using php, specifically just files that have a space in the filename. I want to replace those spaces with underscores. First I need to know to to get a list of just the filenames that have spaces in them. What's the best way to do this? I'm thinking get a list of all the filenames and foreach the array, then split each filename into each character and check if that character is a space, then add that filename to another array, then foreach that other array and str_replace() each filename to replace spaces with the desired charcter. Is there a better way?
-
Pause a method until a condition is met
HaLo2FrEeEk replied to HaLo2FrEeEk's topic in Other Programming Languages
C#, sorry. And I figured it out, sorry again. -
Force download script not handling files with spaces properly
HaLo2FrEeEk replied to HaLo2FrEeEk's topic in PHP Coding Help
Well I suppose that solves that. I' sure I could whip up a quick script to go through and rename all files with spaces to replace spaces with, say, an underscore. That would fix it. I wanted to avoid that because I have direct links to some of those files on my forum, but I'm sure I can do a quick database search for any links at the base url and do a replace. Thanks for the help. -
I have a regular old php force download script, uses this code: header("Cache-Control: "); header("Pragma: "); header("Content-type: application/octet-stream"); header("Content-Disposition: attachment; filename=\"".$download."\""); header("Content-length:".(string)(filesize($path.$download))); readfile($path.$download); Where path is preset and $download is set by GET variables (don't worry, I've sanitized, I check the GET value against an array of acceptable filenames.) This works fine on my computer in both Internet Explorer and Firefox: http://infectionist.com/music/ But I recently got the new Droid phone and found a bug. I cannot download files with spaces in the filename. I've tried everything I can think of and nothing is working. I even tried downloading a file with a space (failed), then renaming that file replacing the space with an underscore, then it worked. So I know that it's space handling that's the issue, I just can't figure out how to get around it! The whole script is one that lists all the files in a directory that are of a certain extension (in this case mp3, wma, and wav). Each filename is put into an array, this array is used as the check against the GET variable's input. I then array_slice() the array to show 10 results per page. I foreach() the sliced array and print out information about the file, like filesize, filename, format, and a little icon. The filename is a link to download the file, printed like this: <a href=\"?file=".urlencode($filename)."\"> So spaces get replaced with a + sign in the URL, but get read as a space by the script. I think the problem lies with the readfile() line, I don't know why the Droid phone doesn't like it, but there HAS to be a way to fix this. If someone, ANYONE, can help me, it will be very much appreciated.
-
Ok, I've tried DataGridView1.Dispose(); and it's still giving me a issue with file associations. Maybe it'd help if I explained what I'm doing: I have a method that fetches an XML file based on a GET variable in the URL (an Xbox Live gamertag), and parses it for some information. There are 30 <item> tags within the XML and inside each of those I need 5 pieces of information: the title, pubdate, description, url to a thumbnail image, and url for the full-sized image. I also have a method to download the thumbnail image I pulled out of the XML for each item. So what I'm doing is parsing each of those <item>'s out of the XML using XmlNodeList, then using a foreach loop to iterate them. Inside that foreach loop I use another XmlNodeList with the value of item.ChildNodes to get all 5 pieces of information and I save them to string variables. Then I start a new thread: Thread t = new Thread(downloadThumb); t.start(thumbUrl); To download the thumbnail images to a folder called ./thumbs/. I use t.Join(); to pause the code until the thread is complete, and when it is I create a new row for my datagridview and add 2 new cells to that new row, one a checkbox and the other an imageCell. I use the thumbnail I just downloaded to fill in the imageCell. So, knowing this, how can I dispose of this properly so that I can delete the folder? When I try closing the program in debug mode (within Visual Studio) the program just won't close at all, if I run it from the /bin/debug folder of my project and try to close it it returns an error: See the end of this message for details on invoking just-in-time (JIT) debugging instead of this dialog box. ************** Exception Text ************** System.IO.IOException: The process cannot access the file '94358334-Thumbnail.jpg' because it is being used by another process. at System.IO.Directory.DeleteHelper(String fullPath, String userPath, Boolean recursive) at System.IO.Directory.Delete(String fullPath, String userPath, Boolean recursive) at WindowsFormsApplication1.Form1.Form_Closing(Object sender, CancelEventArgs cArgs) in E:\Misc\CS Programming\H3ScreenshotDownloader\H3ScreenshotDownloader\Form1.cs:line 138 at System.Windows.Forms.Form.OnClosing(CancelEventArgs e) at System.Windows.Forms.Form.WmClose(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) ************** Loaded Assemblies ************** mscorlib Assembly Version: 2.0.0.0 Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900) CodeBase: file:///C:/Windows/Microsoft.NET/Framework64/v2.0.50727/mscorlib.dll ---------------------------------------- H3ScreenshotDownloader Assembly Version: 1.0.0.0 Win32 Version: 1.0.0.0 CodeBase: file:///E:/Misc/CS%20Programming/H3ScreenshotDownloader/H3ScreenshotDownloader/bin/Debug/H3ScreenshotDownloader.exe ---------------------------------------- System.Windows.Forms Assembly Version: 2.0.0.0 Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900) CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll ---------------------------------------- System Assembly Version: 2.0.0.0 Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900) CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll ---------------------------------------- System.Drawing Assembly Version: 2.0.0.0 Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900) CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll ---------------------------------------- System.Xml Assembly Version: 2.0.0.0 Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900) CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll ---------------------------------------- System.Configuration Assembly Version: 2.0.0.0 Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900) CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll ---------------------------------------- ************** JIT Debugging ************** To enable just-in-time (JIT) debugging, the .config file for this application or computer (machine.config) must have the jitDebugging value set in the system.windows.forms section. The application must also be compiled with debugging enabled. For example: <configuration> <system.windows.forms jitDebugging="true" /> </configuration> When JIT debugging is enabled, any unhandled exception will be sent to the JIT debugger registered on the computer rather than be handled by this dialog box. It makes me feel like the program is tied to the file, not the directory, since the error returned says that the process cannot access the file. Anyone have any advice?