Solved

don't want .asx file cached

Posted on 2004-10-02
25
647 Views
Last Modified: 2012-06-27
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
0
Comment
Question by:daleyjem
  • 13
  • 7
  • 3
  • +1
25 Comments
 
LVL 36

Expert Comment

by:Zyloch
ID: 12209015
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
 
LVL 4

Author Comment

by:daleyjem
ID: 12209022
well that was quick...

hmmm.... not too bad of an idea....
but isn't there other ways?
0
 
LVL 27

Expert Comment

by:Diablo84
ID: 12209024
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Author Comment

by:daleyjem
ID: 12209048
won't this prevent every thing else on the page to not be cached?.... like images and all that?
0
 
LVL 36

Expert Comment

by:Zyloch
ID: 12209054
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
 
LVL 27

Expert Comment

by:Diablo84
ID: 12209070
>>  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
 
LVL 4

Author Comment

by:daleyjem
ID: 12209077
well, i'm not real advanced with php... all of my script is on the same page
0
 
LVL 36

Expert Comment

by:Zyloch
ID: 12209078
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
 
LVL 4

Author Comment

by:daleyjem
ID: 12209087
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
 
LVL 36

Expert Comment

by:Zyloch
ID: 12209104
Ok, are you hosting this on your own server or a free webhost?
0
 
LVL 4

Author Comment

by:daleyjem
ID: 12209113
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
 
LVL 4

Author Comment

by:daleyjem
ID: 12209127
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
 
LVL 36

Expert Comment

by:Zyloch
ID: 12209138
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
 
LVL 4

Author Comment

by:daleyjem
ID: 12209153
i don't see any mod_header thing

...access it to test what?

what are you having me do here?
0
 
LVL 36

Expert Comment

by:Zyloch
ID: 12209228
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
 
LVL 14

Expert Comment

by:ThG
ID: 12209397
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
 
LVL 36

Expert Comment

by:Zyloch
ID: 12209436
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
 
LVL 27

Accepted Solution

by:
Diablo84 earned 125 total points
ID: 12209531
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
 
LVL 14

Expert Comment

by:ThG
ID: 12209598
Yes, that is exactly what I had in mind. At least that's the idea asker gave me with his description.
0
 
LVL 4

Author Comment

by:daleyjem
ID: 12209806
<?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
 
LVL 4

Author Comment

by:daleyjem
ID: 12209820
the .asx file is a separate file... it is only written from another page with that code.

0
 
LVL 4

Author Comment

by:daleyjem
ID: 12209832
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
 
LVL 4

Author Comment

by:daleyjem
ID: 12209836
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
 
LVL 4

Author Comment

by:daleyjem
ID: 12210132
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
 
LVL 4

Author Comment

by:daleyjem
ID: 12210136
... and yeah... that's the right mime-type as shown on microsofts support page.
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question