don't want .asx file cached

i have something on my site where the viewer checks a list of checkboxes for what songs in my list they would like to hear.

once they click a "play selected" button, i have some php code that generates an .asx file on the fly and then opens it.

if i do another one, a new .asx file is created but internet explorer chooses to open the .asx file that was previously cached. and i know the one that it is supposed to use is correct, but it won't choose to open THAT one.

how can i prevent this from happening? let me know if you desire further explaining.

thanks,
jeremy
LVL 4
Jeremy DaleySenior DeveloperAsked:
Who is Participating?
 
Diablo84Connect With a Mentor Commented:
Presumably its contained within an if statement if daleyjem has it all in one page.

eg.

if (isset($_POST['play'])) {
 header("Cache-Control: no-store, no-cache, must-revalidate");
 header("Cache-Control: post-check=0, pre-check=0", false);
 header("Pragma: no-cache");
 header ("Content-type: video/x-ms-asf"); //nearest mime type i could find for asx
 header("Content-Disposition: attachment; filename=something.asx");
 //etc
}
else {
 //display page
}

Though frankly it would be better to have to asx handling code in a seperate file in my opinion.
0
 
ZylochCommented:
Hi daleyjem,

I know a way to do this would be to instead of using one name for the .asx file, attach time() to it, i.e.

$yourasxfilename="eminem".time().".asx";

Then, open up that file. Later, you can have a PHP script that automatically deletes viewed ones already.

Regards,
Zyloch
0
 
Jeremy DaleySenior DeveloperAuthor Commented:
well that was quick...

hmmm.... not too bad of an idea....
but isn't there other ways?
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
Diablo84Commented:
Add the following to the top of you script to prevent caching:

header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

http://www.php.net/manual/en/function.header.php
0
 
Jeremy DaleySenior DeveloperAuthor Commented:
won't this prevent every thing else on the page to not be cached?.... like images and all that?
0
 
ZylochCommented:
I'm hoping Diablo's will work, just not sure if it will work even for the .asx file.

If it doesn't, and you can use .htaccess, and you're using Apache, and that Apache has mod_header, you can do this in .htaccess:

Header append Pragma "no-cache"
Header append Cache-Control "no-store,  no-cache, must-revalidate"
Header add Cache-Control "post-check=0, pre-check=0"

(Information on mod_header)
http://httpd.apache.org/docs/mod/mod_headers.html
0
 
Diablo84Commented:
>>  won't this prevent every thing else on the page to not be cached?.... like images and all that?

Put it within the headers used for the generation of the ASP file, you probably have a line which is something like, header ("content-type: .... add the lines there.

I would have imagined you would have had a seperate script that handles outputting the file so not caching images etc wouldn't be a problem.
0
 
Jeremy DaleySenior DeveloperAuthor Commented:
well, i'm not real advanced with php... all of my script is on the same page
0
 
ZylochCommented:
For mine above about mod_header:

You'd probably want another folder for your dynamic asx files. Then, put that .htaccess in there, or use <Directory> in main .htaccess

0
 
Jeremy DaleySenior DeveloperAuthor Commented:
please understand i'm pretty novice so a lot of what you're saying may work, but doesn't make sense to me, so a little explaining might help
0
 
ZylochCommented:
Ok, are you hosting this on your own server or a free webhost?
0
 
Jeremy DaleySenior DeveloperAuthor Commented:
it's not free like angelfire or any of them, but it is bought hosting space.

i can edit just about anything
i have an .htaccess file but i'm not sure what it's all about
0
 
Jeremy DaleySenior DeveloperAuthor Commented:
i'm gonna be leaving for about an hour but i'll keep up with the post as much as i can...

thanks for now,
jeremy
0
 
ZylochCommented:
Ok. Check to see if they have mod_header. I've never really tried mod_header, but we'll see.

Open .htaccess file there if possible. If you can't, make one locally. Just make sure if you make it locally, upload it ASCI not binary and chmod permissions to 644.

Add this:

<Files "testing.html">
Header append Location "http://www.google.com/"
</Files>

Then create and save a testing.html and access it to test.

0
 
Jeremy DaleySenior DeveloperAuthor Commented:
i don't see any mod_header thing

...access it to test what?

what are you having me do here?
0
 
ZylochCommented:
Well, the <Files thing I'm telling you to add into .htaccess. any mod_whatever, be it mod_header, mod_redirect, etc, all have to do with .htaccess files
0
 
ThGCommented:
I don't understand the point. You said you have some code generating an asx file. In this case, you MUST have somewhere two header() calls, one for Content-Type and the other for Content-Disposition. You add Diablo84's code there and the cache control refers to THAT specific file (the .asx).

HTML code and images are still cached per default values..
0
 
ZylochCommented:
Doesn't Content-Type hold for the whole file? If you're going to be providing a link to a .asx file, you have to set Content-Type for the link, which I'm not sure how to do. Possibly you have a better idea than me?
0
 
ThGCommented:
Yes, that is exactly what I had in mind. At least that's the idea asker gave me with his description.
0
 
Jeremy DaleySenior DeveloperAuthor Commented:
<?php
if(isset($_REQUEST['playlist'])){
      $filename ="playlist.asx";
      $myFile= fopen($filename,'w+');
      $server_name = "localhost";
      $user_name = "someusername";
      $password = "somepassword";
      $playlistitems=Array();
      $playlistitems=$_POST['checkSelect'];
      fputs($myFile,"<asx version=\"3.0\">\n");
      fputs($myFile,"<Param Name = \"AllowShuffle\" Value = \"yes\" />\n");
      foreach($playlistitems as $playitem){
            $connection = mysql_connect($server_name, $user_name, $password);
            if (!$connection) {
                  printf("Connection error: %s", mysql_error());
                  exit;
            }
            mysql_select_db("someDB");
            $result=mysql_query("SELECT * from list_mp3s where theIndex='" . $playitem . "'");
            $row = mysql_fetch_assoc($result);
            $string="\n<Entry>\n<Title>" . $row['theArtist'] . " - " . $row['theSong'] . "</Title>\n<ref href=\"" . $row['theURL'] . "\"/>\n</Entry>\n";
            fputs($myFile, $string);
            mysql_close();

      }
      fputs($myFile,"\n</asx>");
      fclose($myFile);
      printf("<script language=javascript>window.open('playlist.asx');</script>\n");
}
?>



that is my php code within my page...it basically erases the old playlist.asx file and then rewrites it.
so then the .asx file would look like this:


<asx version="3.0">
<Param Name = "AllowShuffle" Value = "yes" />

<Entry>
<Title>Artist - Song</Title>
<ref href="http://www.mockURLlocation/Music/somesong.mp3"/>
</Entry>

</asx>

so no where in there do i have anything about headers...
0
 
Jeremy DaleySenior DeveloperAuthor Commented:
the .asx file is a separate file... it is only written from another page with that code.

0
 
Jeremy DaleySenior DeveloperAuthor Commented:
i have an index.php page
it has a form in it with checkboxes.
when you submit... the action directs it to its self with a "request" variable set.
when it re-opens that page it will not recognize the request variable and then perform the routine.
the routine opens a separate file located on my server called playlist.asx
it then writes to that file.
after the file is written to, it is closed.
the index.php page then opens the .asx file that was just written to and it opens up in windows media player or what have you.

is this a bit more clear?
0
 
Jeremy DaleySenior DeveloperAuthor Commented:
sorry...

"when it re-opens that page it will not recognize the request variable and then perform the routine.
"

is supposed to read...

"when it re-opens that page it will NOW recognize the request variable and then perform the routine.
"
0
 
Jeremy DaleySenior DeveloperAuthor Commented:
ahhhhhhhhhh!!!!!!!!

i got it!!!!!!!!!

i understand what you wanted me to do....

so i set my form action to a "playlist.php" file where i set the headers and wrote the .asx file IN that php file...

i didn't understand the "science" of doing all of that

but anyway... it worked thanks to y'all , especially Diablo except instead of an attachment disposition... i made it inline so it would play

ya dig?

alright yall... thanks again
0
 
Jeremy DaleySenior DeveloperAuthor Commented:
... and yeah... that's the right mime-type as shown on microsofts support page.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.