• What the hell? PHP weirdness?
    31 replies, posted
I have set up a php page to output a random image every time, but it only does if I reload the page. Somehow, if I follow a link to the page, it won't give another image but use the same. Check for yourself. [url=http://terabyte.altervista.org]Main page that uses the generator (wont change if opened from a link (like this one) but only if reloaded[/url] [url=http://terabyte.altervista.org/images/pf_header.php]The generator. It acts the same as the page it is hosted inside (linked before)[/url] code of the generator: [php]<?php header('Content-type: image/png'); $imagename = 'pf_header'.rand(1,14).'.png'; readfile($imagename); ?>[/php] Can anyone explain why this happens and how to fix?
PHP outputs only static text, so it can't really update the image while you're viewing it, and you'd need some javascript or other to do it. I also believe it's because the page is cached, and so your browser sees no reason to redownload the same text as it already has stored, hence why the image doesn't change if you're linked there-
[QUOTE=Tools;22828515]PHP outputs only static text, so it can't really update the image while you're viewing it, and you'd need some javascript or other to do it. I also believe it's because the page is cached, and so your browser sees no reason to redownload the same text as it already has stored, hence why the image doesn't change if you're linked there-[/QUOTE] And is there a way to like 'uncache' it?
[code] header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); [/code]
[QUOTE=andersonmat;22828724][code] header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); [/code][/QUOTE] Thanks, that worked perfectly
That's a bad method. Have the page do something like background url( blah/<?php echo mt_rand( 1, 5 ); ?>.jpg ) which means it'll cache, but change all the time too, for less bandwidth and faster loading for users.
[QUOTE=Fizzadar;22829814]That's a bad method. Have the page do something like background url( blah/<?php echo mt_rand( 1, 5 ); ?>.jpg ) which means it'll cache, but change all the time too, for less bandwidth and faster loading for users.[/QUOTE] That was the previous solution, but since you can only have one stylesheet per page and I wanted to have an external one, I couldn't keep that.
[QUOTE=Reg;22835079]That was the previous solution, but since you can only have one stylesheet per page and I wanted to have an external one, I couldn't keep that.[/QUOTE] What the fuck? No, seriously, what the fuck? Since WHEN can you only have one stylesheet per page? Where do you get this utter shit from?
You can have multiple stylesheets per page as well as inline styles so i don't see wtf your problem is
[QUOTE=Reg;22835079]That was the previous solution, but since you can only have one stylesheet per page and I wanted to have an external one, I couldn't keep that.[/QUOTE] :downs:
[QUOTE=turb_;22835967]What the fuck? No, seriously, what the fuck? Since WHEN can you only have one stylesheet per page? Where do you get this utter shit from?[/QUOTE] Your anger sums up what everyone was thinking
[QUOTE=wutanggrenad;22845005]Your anger sums up what everyone was thinking[/QUOTE] That's how I roll
Well anyhow I liked it all to be in the same css.
[QUOTE=Reg;22845422]Well anyhow I liked it all to be in the same css.[/QUOTE] That sounds like a cover-up for your last downs comment, because this one doesn't make it any better.
[QUOTE=Reg;22845422]Well anyhow I liked it all to be in the same css.[/QUOTE] You'll look back on that post someday and say "Damn, what the fuck was I thinking?"
Umm, you could be right. I'm still a newbie afterall. But I wanted it to be external so that I could get all the changes on all the pages at once.
[QUOTE=turb_;22835967]What the fuck? No, seriously, what the fuck? Since WHEN can you only have one stylesheet per page? Where do you get this utter shit from?[/QUOTE] How about "That's not correct" or "You've been misinformed"?
[QUOTE=Ortzinator;22854910]How about "That's not correct" or "You've been misinformed"?[/QUOTE] This guy's threads have been giving me the shits.
[QUOTE=Ortzinator;22854910]How about "That's not correct" or "You've been misinformed"?[/QUOTE] Yeah sorry but people don't fucking learn like that. Especially Facepunch :sigh:
<link rel="stylesheet" type="text/css" href="myshittystyle.css"> <link rel="stylesheet" type="text/css" href="myothershittystyle.css"> oh look multiple styles
I don't see how being an asshole is better than being dumb.
[QUOTE=Ortzinator;22862077]I don't see how being an asshole is better than being dumb.[/QUOTE] Hey it looks like you're new the the Web Development forum. May I take your coat?
Think of it as persuasion.
Ortzinator - don't even try, it's a tradition to be an asshole in this sub-forum.
[QUOTE=jmazouri;22862075]<link rel="stylesheet" type="text/css" href="myshittystyle.css" /> <link rel="stylesheet" type="text/css" href="myothershittystyle.css" /> oh look multiple styles[/QUOTE] Fixed :eng101: [editline]01:14AM[/editline] [QUOTE=Ortzinator;22862077]I don't see how being an asshole is better than being dumb.[/QUOTE] Being an asshole is usually the only method that people will actually learn. For example, if someone directly uses a variable in an SQL query (open for SQL injection), what message will help pass the message better? "Umm, putting that variable there isn't a good idea," or giving them a quick lesson on injection the hard way.
[QUOTE=deadeye536;22867382]Fixed :eng101:[/QUOTE] Both are valid in HTML5
I came into this thread, I'm going to leave now before I get stuck in here.
turb_ is right, the information he gathered about being only to have one stylesheet, where the hell did that come from? I'm sorry but stupid ass questions deserve stupid ass answers! People need to read more, I can't stress that enough, just keep reading, wake up one day and say, fuck I'll learn everything there is to know about CSS. At the end of the day, sit back and realize you think you know everything, but you really don't. Continue cycle under brain hemorrhaging occurs. turb_++
Well thanks for making Facepunch a better place.
[QUOTE=a2h;22867793]Both are valid in HTML5[/QUOTE] Learn something every day I guess. Also, if I'm not mistaken, can't you simply include a PHP file as the style sheet? Allows a central, yet dynamic style sheet.
Sorry, you need to Log In to post a reply to this thread.