Problem with code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Problem with code

Post by nigma »

Hey I don't know why this would not work but it doesn't seem to:

Code: Select all

<SCRIPT language="JavaScript">

var width  = screen.width;
var height = screen.height;

if     ((width == 1280) && (height == 1024))
&#123;
	<?php
		$cooklife = time() + 1800;
		setcookie('res', '1280x1024', $cooklife);
	?>
	window.location="index1.html";
&#125;

</script>
Thanks for any help provided. It'sgreatly apreciated.
Malder
Forum Newbie
Posts: 13
Joined: Wed Mar 19, 2003 11:09 pm

Post by Malder »

setcookie() defines a cookie to be sent along with the rest of the header information. Cookies must be sent before any other headers are sent (this is a restriction of cookies, not PHP).
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post by nigma »

See what I want to do is have a seperate stylesheet for each of the different resolutions. To do this I thought great idea, I would store there resolution in a cookie and then get the data from the cookie whereI would usually include the stylesheet. How else could I do this?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

You can't mix PHP and JavaScript like that - PHP is server-side and has finished processing before the JavaScript even starts.

viewtopic.php?t=1030
viewtopic.php?t=7380&highlight=resolution+javascript

Why do you need a different style sheet for different resolutions?

Mac
Ben C
Forum Newbie
Posts: 7
Joined: Sat Mar 29, 2003 5:16 am

Post by Ben C »

If you want to keep it similar to how it is, you'll have to do the whole thing in Javascript. If you don't know how to do cookies in Javascript see the advanced tutorial here:

http://hotwired.lycos.com/webmonkey/pro ... rial2.html

Hope this helps.
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post by nigma »

Thanks a bunch. I really apreciate this.
Ben C
Forum Newbie
Posts: 7
Joined: Sat Mar 29, 2003 5:16 am

Post by Ben C »

I don't know if that is all of your code, or if you just pasted in a bit, but remember that Javascript should be 'commented out', so that at least in browsers that don't recognise Javascript, the code doesn't show on the visible page. Like this:

http://hotwired.lycos.com/webmonkey/98/ ... rogramming

Code: Select all

<script language="JavaScript"> 

<!-- hide this stuff from other browsers 

YOUR SCRIPT HERE 

// end the hiding comment --> 

</script>
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post by nigma »

I had more code in there, but that was the section I was having trouble with.
Post Reply