SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 35
  1. #1
    SitePoint Enthusiast Anthony_c's Avatar
    Join Date
    May 2008
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Lightbulb PHP-Flash integration to a new level

    Okay, not sure if this the right place to put this, but I just wanted to share my discoveries, because I think others will find it incredibly useful. Taken originally from my blog at http://www.anthonycargile.com/blog/?p=36 :

    Here’s what I needed this for: a client of mine is having me do a flash site, and as we all know flash is a one time deal, make the swf, embed it, and updates mean recompiling the swf. Now some get fancy and pass parameters to the movie via the corresponding HTML tag, but that could possibly lead to security vulnerabilities. Flash DOES, however, support reading external xml files over the network, allowing you to update an app just by re-uploading a new xml file, but for me, no, even that was not good enough.

    This client of mine is a model. She gives me an average of 10 new pics a week to put on the (soon-to-be-old-yet-kept-for-accessibility-while-keeping-the-same-content-as-the-flash) site, which as mentioned above is a problem for flash. Enter using xml, which saves me from recompiling the whole shebang, but for an average 10 photos a week, I’m sorry but that is just waaay to much work for a programmer of my caliber.

    Now the old html-php site used a custom portfolio I made that actually per-request went into the image directory, fetched the photos out of the subdirectories that were the same name as the album (which were specified in the query string after stripping any hackers’ slashes), then placed them in a javascript-paged image viewer. All I had to do to update it was add the new pics to the correct album name directory, and the next page requests would automatically put them there.

    So how do we do this same thing in flash? Well, flash was smarter than to to read an “xml” file with a .php extension, apparently hard-coded in there by adobe. So, since I favor Linux web hosting under apache, I made a little .htaccess file, and added:

    Code:
    AddType application/x-httpd-php .xml
    in there. Now, I only did this because I am 100% sure that I won’t be needing anything else xml-related that would disagree with php for this website, otherwise I would put it in a directory, although I have not tested this.

    What this does now, is let the webserver’s php processor execute any php code in any .xml file prior to serving it. I am lucky that flash is so client side that it actually REQUESTS the .xml file rather than open it (in a fopen() flashion) and then read the contents, which would just give the app php code, obviously not the desired effect here.

    So now that php can process a .xml file before handing the output to flash upon request, I can just tell php to add a new xml tag for each image found in the album directories, which includes an image URL that flash can load into the app for viewing pleasure.

    Not exactly 100% creative, but still, a nice way to incorporate laziness into a flash app. As subtly mentioned above, for non-javascript/flash enabled users, the old (lynx/screenreader capable) html website will still be kept around, and it uses the same server-side technique for content management, so both the flash and html sections of the site will display the same content that I simply had to add to a directory.

  2. #2
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't see the need for what you have done. You can set the content-type headers to xml so it will return as an xml document when flash requests it.


  3. #3
    SitePoint Enthusiast Anthony_c's Avatar
    Join Date
    May 2008
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by gRoberts View Post
    I don't see the need for what you have done. You can set the content-type headers to xml so it will return as an xml document when flash requests it.
    No, flash refused anything without a .xml file extension, I tried feeding it a .php file and it refused it. Re-read my post, I don't think you quite understand what this is - letting php output xml markup to flash dynamically for a very easy updating portfolio.

  4. #4
    SitePoint Wizard
    Join Date
    Mar 2008
    Posts
    1,149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is a really bad way to do it. You should use mod_rewrite instead.

    Also, this isn't revolutionary at all. If you were to going to update it often, using dynamically-generated XML would have been the first thought for an experienced programmer.

  5. #5
    SitePoint Guru mwolfe's Avatar
    Join Date
    Mar 2005
    Posts
    912
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    lol. Its really not that bad of an idea but could have been done better.
    Here is what i'd do:
    Write a script that runs as a cronjob every so often that will generate this xml file... If you don't have access to cron on the server then you could just put it at a webpage that is not accessible by regular users (password protected directory).. or just name it something funny, its really not a security issue anyways if someone else ran it as long as they aren't doing it all the time.

    That will give you better performance and you can get rid of that apache AddType declaration. Running different types of files through the php interpreter slows things down and adds potential security risks, and its a bad habit to get into.

  6. #6
    SitePoint Enthusiast Anthony_c's Avatar
    Join Date
    May 2008
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up

    Jesus, you guys really butchered this one up!

    Using mod_rewrite is never a good idea to play a key role in a web app, because it ties in too close with the webserver. I only use it to redirect a tld to the correct one, given the client provides 2 with a preference. And that little comment about dynamically generated xml, can you read? No offense, but that is what this whole thing is about, only using php to MAKE it dynamic, dynamic in the sense that whatevers in that xml file depends on what the php processor finds in the image directories. And about the cron job, that again ties too closely with the server, and although I used a .htaccess hack for this, I try to stay away from that as much as possible, and my model client and I communicate over IM, so waiting 10 minutes for a cron job to swing by and change the xml is still not good enough, especially if after the 10 minutes on the dot she has yet another pic or two she forgot to give me the first time! (and yes, this does happen quite a bit!).

    Again the above suggestions are good alternatives for this, but my original idea didn't involve going too deep in the server, a never for most web apps, and off-limits for non-VPS/dedicated hosting, where a .htaccess file is the only communication, although it still permits the mod_rewrite rule. And I haven't forgotten about IIS, but, trying not to turn this into another stupid sitepoint platform war, if I were going to host on IIS, I would go for VPS or dedicated hosting so I could adjust the subtle nuances needed for hacks like this, granted ASP.net would allow this sort of thing from the server, although this is designed specifically for php, but tomcat would permit the JSP engine to execute code in xml files.

    Luckily for my ASP.net apps, my hosting provider uses mod_proxy on their load-balanced linux servers to talk to backend IIS 7 servers, allowing a whole directory to hold asp apps, for a minimal additional fee . And as far as security as mentioned above, I'm only using the AddType for the flash directory, which stores the xml files, and getting FTP access to the server is quite hard, again thanks to my hosting provider whom changes the port that sftp listens one.

  7. #7
    SitePoint Guru mwolfe's Avatar
    Join Date
    Mar 2005
    Posts
    912
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cron jobs tie too closely with the server?
    Not sure what that means.
    You actually wouldn't need to make a cron job, you could just call the script from some special web page instead.
    Seriously though, scanning the directory of images and building an xml file on every request for this flash file might be fine with a small set of files but if that set gets large you are doing a lot of extra work for a relatively small amount of convenience.


    Also, there is nothing wrong with using mod_rewrite IMO, typically i'd use it to clean up URL's for good SEO and for perminent or temporary redirects as you suggested.

  8. #8
    SitePoint Enthusiast Anthony_c's Avatar
    Join Date
    May 2008
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Lightbulb

    After reading the replies again, I think I need to provide an example of the xml files php is sending to the flash app. Flash app requests for portfolio.xml, and since php parses xml thanks to the AddType for the flash directory, this is what php is fed:
    Code PHP:
    <portfolio>
    <?php
    $dh = opendir("/path/to/images"); //relative to the webserver, unless chrooted
    $rh = "/path/to/images"; //relative to the web root
    while($file = readdir($dh)) { //read the entire directory of images
    if($file !== "." && $file !== "..") { //leave out unix-style irrelevant directories 
    $picname = split("[/\\.]",$file,2); //get the filename minus the extension for display
    echo '<picture caption="' . $picname[0] . '" url="' . $rh . '/' . $file . '" />'; 
    //echo everything to an xml tag flash can use
    }
    }
    ?>
    </portfolio>
    //close the xml file

    So given there were 5 pics in that directory, flash would receive in response to its request:
    Code XML:
    <portfolio>
      <picture caption="picture 1" url="/path/to/images/pic1.jpg" />
      <picture caption="picture 2" url="/path/to/images/pic2.jpg" />
      <picture caption="picture 3" url="/path/to/images/pic3.jpg" />
      <picture caption="picture 4" url="/path/to/images/pic4.jpg" />
      <picture caption="picture 5" url="/path/to/images/pic5.jpg" />
    </portfolio>
    Maybe that will help some people better see what this is doing, and keep in mind that while I was too lazy/secretive to print the source of the real app, the only difference is that the real one uses the first subdirectory as the album name, and the contents of that directory as the actual files to display. But you get the picture here.

    And no, there is nothing wrong with using mod_rewrite for SEO work, but making it a fundamental step in web apps is just poor practice, same as the cron job thing. I like to keep the server independent from the web apps, because it doesn't limit possibilities for other things, say, changing hosting providers to a more traffic friendly one, or other major changes. Not to say its completely out of the question, but its just something i like to avoid.

  9. #9
    SitePoint Wizard
    Join Date
    Mar 2008
    Posts
    1,149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Using mod_rewrite is perfectly fine. Things like mod_rewrite and cron jobs are things you should expect when you host on a *nix/BSD server. It's standard these days, even on virtual hosting. Using it is much better than making your code un-necessarily ugly and error-prone. If you're going to switch to a non-Apache server (not that IIS and other servers don't' have equivalent mod_rewrite functionality that can be installed), changing one thing around is hardly hard work.

    You don't need to provide examples anyway. We know exactly what you mean, and anyone who has any experience with web servers would be aware that that's one of your many options to falsify a URL. It's just one of the ugliest ways of doing it. You remind me of this guy who wrote a tutorial for "Invert" in Photoshop.

    I'm also pretty positive that Flash will open any XML file of any extension. You must be doing it wrong.

  10. #10
    SitePoint Enthusiast Anthony_c's Avatar
    Join Date
    May 2008
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    No, I'm not doing it wrong, I'm doing it in a better (albeit different, for the one-track-minded people here) way than using mod_rewrite. And that code is hardly ugly compared to what mod_rewrite would be doing, and since it is completely server-side and out of the client-dependent zone (despite using flash in the first place but as mentioned above I have a parallel HTML site that reads the same content), it is hardly any sacrifice to make. And how would using mod_rewrite save "ugly code" in the first place since replacing AddType with it would just let php execute code in the xml file anyway? Think before you type, next time. I only used AddType (over your beloved mod_rewrite) to get php to read the file. If flash could take a .php file, would we even be having this conversation?

    And how DARE you claim I took code from that other site! I do use some external code and even use some modified templates for some jobs, but I would never go this far to show it off for the benefit of others if it were not original in the first place, and despite that (one of the reasons I dislike sitepoint anyway), look at the positive comments on the mentioned page. Those people may not be as experienced as some of us (although some of the people in this thread I question after the elementary/highly critical comments), but if it works, DON'T FIX IT.

    I'm also pretty positive that Flash will open any XML file of any extension. You must be doing it wrong.
    Well I tried handing it a .php file, but it didn't work. It might be because I am using Flash 8 on Ubuntu Linux (since that is the most recent one wine can execute), but nonetheless, I had to resort to this. Try it for yourself before making blind assumptions.

  11. #11
    SitePoint Wizard
    Join Date
    Mar 2008
    Posts
    1,149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's ugly because you break convention. People do not expect a .xml file to be parsed as PHP code. It gets worse because XML files have a declaration that conflicts with PHP.

    I also didn't claim that you took code at all. I only provided that link because it was an example of Flash reading a URL that does not end in .xml. This is why the edit immediately followed my comment: "I'm also pretty positive that Flash will open any XML file of any extension." And lastly, because it works, it doesn't mean it's the right way. Your comments embody this belief, as you are so very anti-mod_rewrite.

    And I already did try for it myself later on, in both AS2 and AS3 (although with the Windows Flash Player), and it worked fine in both. I've also done it before, and that's why I had the thought to begin with. Since it was a while ago, I wasn't entirely sure.

  12. #12
    SitePoint Wizard REMIYA's Avatar
    Join Date
    May 2005
    Posts
    1,351
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is so easy.

    At the load of the PHP page with Flash, make the PHP read your picture directory and update the XML file, if there are changes.

  13. #13
    SitePoint Enthusiast Anthony_c's Avatar
    Join Date
    May 2008
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Post

    At the load of the PHP page with Flash, make the PHP read your picture directory and update the XML file, if there are changes.
    That is harder on the server, since the page has to stop (possibly annoying the visitors on high server loads with a long wait), THEN scan the directory, THEN fopen() the xml file, which gets into how easily php can update an xml file (looks like it would be more work for php to actually use API functions), update it, then close it then proceed with the page, which will then just request the xml again anyway. And since the whole site is flash, save the php-xml thing, this would happen before the site's "homepage" is even displayed. My solution actually waits for them to request the portfolio section (in flash, triggering the loading of the xml file) before doing this, and having the code IN the xml file saves the server processing time/load, and works even better since I have caching turned on so some requests will just re-use the generated xml anyway.

    This is so easy.
    hehe, yeah THAT solution was easy to come up with, but it just doesn't work quite 100&#37; .

    ...XML files have a declaration that conflicts with PHP
    Only if the shorttags directive is set in php.ini, which in my case it is not, so
    Code:
    <?xml
    is not the same as
    Code:
    <?php
    , if you actually read this carefully before attempting to "correct" everything I say.

    And as far as the rest of your ramblings, when I tested it, it did NOT work with a non-.xml extension. And just because I don't use mod_rewrite (which is as NOT as big of a deal as you guys are making it), does not need to bring an entire slew of posts. In fact, rewrite still does depend on the client to have a "smart" sense of HTTP headers anyway, something not all browsers, albeit old ones, may not have. And using rewrite would require modifying the return headers as well, since flash would no doubt be looking for "Content-type: text/xml" in the return, as opposed to what php might return. And I'm only doing this for one directory, which is set aside for the flash, so it's not like I'm compromising the whole damn server just for php to parse a couple of xml docs.

  14. #14
    SitePoint Wizard REMIYA's Avatar
    Join Date
    May 2005
    Posts
    1,351
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Anthony_c View Post
    That is harder on the server, since the page has to stop (possibly annoying the visitors on high server loads with a long wait), THEN scan the directory, THEN fopen() the xml file, which gets into how easily php can update an xml file (looks like it would be more work for php to actually use API functions), update it, then close it then proceed with the page, which will then just request the xml again anyway.
    Antony.

    Listing the folder contents takes milliseconds.

    - START -

    1. List pictures
    2. Compare, with previous picture list cache
    3. IF THERE ARE CHANGES, generate
    - new XML
    - new picture list cache

    -END-

    It will not slow down your page a bit. Make a benchmark to test how mush time it will take.

    PS. You don't have to read and parse the XML file.

  15. #15
    SitePoint Enthusiast Anthony_c's Avatar
    Join Date
    May 2008
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs down

    think about I/O activity, etc of constantly creating and deleting the xml file! This client's current html/php site puts out 1GB of traffic A DAY! Trust me, you don't want that much disk actvity and the likes with that much traffic. By not explicitly opening the xml file, my solution lets the cache handle some of the work, but the cache is overriden if you explicitly open it and re-open it, and delete it over and over again for all those requests, rendering the whole idea's gains completely outweighed by the loss of performance! And as many pics as she has, comparing the whole file, which is easily huge, to the changes to be made is slower than just putting the code in the file anyway and let the natural cache do its job, since it is already loaded into memory at Apache's start.

    It's a good idea, but you're experiencing a problem I had when I first went from desktop programming to server-side code, and that's still thinking that it's like a desktop, but performance under high-loads is a must here. Luckily flash is just bandwidth consuming, since it is executed on the client, so we just have to improve on the server cpu usage here, and that's one of the goals I tried to fulfill other than just a lazy updating solution.

  16. #16
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you post your actionscript that is being used to pull the xml file? That may be the best place to start. It may not be the correct forum but it may help other users.


  17. #17
    SitePoint Wizard REMIYA's Avatar
    Join Date
    May 2005
    Posts
    1,351
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Anthony_c View Post
    think about I/O activity, etc of constantly creating and deleting the xml file! This client's current html/php site puts out 1GB of traffic A DAY!
    If you don't want the script to be executed on each page load. Make it run separately once daily, with a cron job.

    Or make it run through an admin interface when you upload new pictures.

    However keep it simple.

  18. #18
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is way overcomplicating things. I've never known any http requests including XMLHttpRequests to be picky about the type of extension you use.

    If you are using php extensions, make sure your setting the content-type header text/xml as that could be the reason why it's failing.

    It would help emensly if we knew how you were creating the request in flash.


  19. #19
    SitePoint Wizard REMIYA's Avatar
    Join Date
    May 2005
    Posts
    1,351
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by gRoberts View Post
    I've never known any http requests including XMLHttpRequests to be picky about the type of extension you use.
    Sometimes it happens.

  20. #20
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I knew it was picky about cross-domain fetching but apart from that, thats it.

    We'll have to see how the OP is doing it before we can really continue.


  21. #21
    SitePoint Wizard
    Join Date
    Mar 2008
    Posts
    1,149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Anthony_c View Post
    Only if the shorttags directive is set in php.ini, which in my case it is not, so
    Code:
    <?xml
    is not the same as
    Code:
    <?php
    , if you actually read this carefully before attempting to "correct" everything I say.
    I don't recall you ever mentioning "shorttags." Maybe you need to write it first before I can read it. Shorttags is enabled on many servers.

    Quote Originally Posted by Anthony_c View Post
    And as far as the rest of your ramblings, when I tested it, it did NOT work with a non-.xml extension.
    The link I provided showed someone else's (successful) attempt at loading a non .xml extension XML file.

    Quote Originally Posted by Anthony_c View Post
    And just because I don't use mod_rewrite (which is as NOT as big of a deal as you guys are making it), does not need to bring an entire slew of posts.
    I'm only posting this because you think you are experienced at web development, but your posts say otherwise. The fact that you're posting about AddType shows that you're still very new to the field. It's even worse that you actually think it's revolutionary.

    Quote Originally Posted by Anthony_c View Post
    In fact, rewrite still does depend on the client to have a "smart" sense of HTTP headers anyway, something not all browsers, albeit old ones, may not have.
    Smart sense of headers? All a browser needs to do is implement 302 Found.

    Quote Originally Posted by Anthony_c View Post
    And using rewrite would require modifying the return headers as well, since flash would no doubt be looking for "Content-type: text/xml" in the return, as opposed to what php might return.
    Using AddType doesn't change the content type header. Your PHP .xml file is currently returning text/html (or whatever is the default) for the content type header.

  22. #22
    SitePoint Enthusiast Anthony_c's Avatar
    Join Date
    May 2008
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't recall you ever mentioning "shorttags." Maybe you need to write it first before I can read it. Shorttags is enabled on many servers.
    I don't use it because using
    Code:
    <?php
    is neater than short tags, makes the code consistant, and is overall neater, but that's just my personal preference.
    The link I provided showed someone else's (successful) attempt at loading a non .xml extension XML file.
    Well that's great, but like I said, I tested it, and since my test failed, I went with another solution.
    I'm only posting this because you think you are experienced at web development, but your posts say otherwise. The fact that you're posting about AddType shows that you're still very new to the field. It's even worse that you actually think it's revolutionary.
    Excuse me? You really do not want to go there, as I have designed over 30 high profile websites, and manage even more, in addition to years of regular programming even mastering the assembly language of several different architectures, but this is not the place to discuss that. By the way, in case you haven't noticed, look to the left of this: I hardly ever post to this forum because I am actually working on websites all the time, and don't have time to play around like this. Even if this was my first website, using AddType is still better than mod_rewrite for ensuring that the server does what it needs to do here. Post what mod_rewrite conditions you think would suffice, and I will personally test them under several conditions and show you an example of when it either fails because of the client (and flash complicates this), fails in a benchmark of speed (rewriting URLs concastantly vs. just letting the already loaded php processor execute code in xml files), or so-call "ugly code" as you mentioned earlier, and with regular expressions, this is going to be the case, refer to the annual obfuscated C contests. And no, AddType is not revolutionary, dynamic xml through php for this application is the key here, people just have other ideas of how to implement it, and I'm simply stating the advantages of using my solution for those who may not see them.
    Smart sense of headers? All a browser needs to do is implement 302 Found.
    Who's inexperienced? The browser LOOKS for 302 found in the return packets, the SERVER implements it when it has FOUND the document requested(although most of the time via redirection, otherwise its 200, else 404), then the browser implements the necessary functions. Again, you don't know what you are talking about and it's reasons like this that I don't like using mod_rewrite as a key to web apps. Although I understand it having a Network+ certification under my belt, it's others like you that use it without knowing what it's actually doing. Just using AddType for the one directory you need it saves this problem, and you never have to worry about it again, since the code for php to look at xml files is already loaded into memory, whereas mod_rewrite uses more bandwidth and CPU power, something a high-traffic website such as this one just cannot tolerate. (Apparently you need to learn a little bit more about HTTP status codes, especially before you use mod_rewrite: http://en.wikipedia.org/wiki/HTTP_302 ).

    Using AddType doesn't change the content type header. Your PHP .xml file is currently returning text/html (or whatever is the default) for the content type header.
    Yeah, but the server itself sees the mime-type as xml anyway, and that is the final authority, despite the php processor being fooled into executing code in xml files.

  23. #23
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Now now children... remember this is a place to get help. I understand both parties fustrations but it's not going to answer the question.

    Again.. Can you please post a snippet of the code that actually communicates with the xml/php/whatever it is document and fails.

    That way we can point out how to fix the issue..


  24. #24
    SitePoint Enthusiast Anthony_c's Avatar
    Join Date
    May 2008
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Post

    Now now children... remember this is a place to get help. I understand both parties fustrations but it's not going to answer the question.
    But he started it!!

    ..anyways, here's the actionscript in question:
    Code Actionscript:
    var xml:XML = new XML();
    xml.onLoad = function()
    {
    	item_list.fm_item._visible = false;
    	var nodes = this.firstChild.childNodes;
    	total = nodes.length;
     
    	for( i = 0; i < total; i++)
    	{
    		item_title[i] = nodes[i].attributes.caption;
    		item_url[i] = nodes[i].attributes.url;
    		item_description[i] = nodes[i].attributes.description;
    	}
    	create_item_list();  //this and scroller() are just irrelevant external functions
    	scroller();              //used by the movie. Don't think I need to post them.
    }
    xml.load("portfolio.xml"); //yes, I tried changing it to .php here, keyword TRIED
    xml.ignoreWhite = true;
    That way we can point out how to fix the issue..
    Not to start this again, but if it works, works well, and without any issues... is it broken? I'm all ears to suggestions, but so far none of them have really given me enough reason to change the script.

  25. #25
    SitePoint Wizard
    Join Date
    Mar 2008
    Posts
    1,149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Anthony_c View Post
    Excuse me? You really do not want to go there, as I have designed over 30 high profile websites, and manage even more, in addition to years of regular programming even mastering the assembly language of several different architectures, but this is not the place to discuss that. By the way, in case you haven't noticed, look to the left of this: I hardly ever post to this forum because I am actually working on websites all the time, and don't have time to play around like this.
    That's nice, but we all know there are plenty of people who work in a field for years and never seem to improve. I suppose you're one of them.

    Quote Originally Posted by Anthony_c View Post
    Even if this was my first website, using AddType is still better than mod_rewrite for ensuring that the server does what it needs to do here. Post what mod_rewrite conditions you think would suffice, and I will personally test them under several conditions and show you an example of when it either fails because of the client (and flash complicates this), fails in a benchmark of speed (rewriting URLs concastantly vs. just letting the already loaded php processor execute code in xml files), or so-call "ugly code" as you mentioned earlier, and with regular expressions, this is going to be the case, refer to the annual obfuscated C contests. And no, AddType is not revolutionary, dynamic xml through php for this application is the key here, people just have other ideas of how to implement it, and I'm simply stating the advantages of using my solution for those who may not see them.
    It takes only one line of mod_rewrite to do it. Dynamic XML is even less amazing (it's even more obvious to a newbie programmer).

    Quote Originally Posted by Anthony_c View Post
    Who's inexperienced? The browser LOOKS for 302 found in the return packets, the SERVER implements it when it has FOUND the document requested(although most of the time via redirection, otherwise its 200, else 404), then the browser implements the necessary functions. Again, you don't know what you are talking about and it's reasons like this that I don't like using mod_rewrite as a key to web apps. Although I understand it having a Network+ certification under my belt, it's others like you that use it without knowing what it's actually doing. Just using AddType for the one directory you need it saves this problem, and you never have to worry about it again, since the code for php to look at xml files is already loaded into memory, whereas mod_rewrite uses more bandwidth and CPU power, something a high-traffic website such as this one just cannot tolerate. (Apparently you need to learn a little bit more about HTTP status codes, especially before you use mod_rewrite: http://en.wikipedia.org/wiki/HTTP_302 ).
    Excuse me there. Somehow what you said led me think you wanted a redirect (rather than a rewrite). In which case, you don't, so the client absolutely is not involved, and browsers don't need to know any sense of HTTP headers.

    I know how (HTTP) servers work. I've programmed several of them.

    mod_rewrite has a negligible effect on server performance, especially if it goes into httpd.conf. You're obviously not going for performance here, as you're not caching the XML output. Not caching the document probably has a greater impact. If performance was actually that important, you'd be using a caching proxy in front.

    mod_rewrite sends a 302 when redirecting (not rewriting), unless you explicitly tell it to send a permanent redirect. 302 is not really the right status code for a temporary redirect, but browsers have been using it for years.

    Quote Originally Posted by Anthony_c View Post
    Yeah, but the server itself sees the mime-type as xml anyway, and that is the final authority, despite the php processor being fooled into executing code in xml files.
    Apache does not. The way a script parser/module works is that it will return the list of headers and the body of the page. Apache will listen to the parser/module, and it will print out the Content-Type that PHP gives it. PHP will default to giving out its default content type, which is usually text/html. There are only a few headers that Apache will not allow you to override, such as Server. In actuality, once you use AddType, Apache has "lost" the right mime-type. Now the mime type is actually application/x-httpd-php, but it's not sensible to send "application/x-httpd-php" as the content type, so PHP spits out text/html.


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •