woah! i don't think you should be doing what you described, let me describe to you the flow of a page request and see if that helps you see what i am thinking and what i believe you are thinking
1) user types in address, or clicks on link
2) browser sends apache a page request
3) apache notices its a php script you want
4) apache starts up php
5) apache sends php your .php file
6) php runs through you code and execues it all, returns anything printed, any html written
7) apache takes whatever is returned from php and send it to the users browser as a webpage
8) browser recieves and loads page
9) browser reads and executes any bare javascript, which may write more html
10) page executes any onLoad='' javascript
11) javascript executes in response to mouse and keyboard input from user, which may reorganize the page (ie show a dropdown menu)
ok now php and javascript can do some similar things, like tell the browser to load a new page.
if you are not sure which page the user should be on. if you need to run logic to make sure that this page is the one the user should be on, then you need to take care of that at my step 6 (with php) before your webserver returns any webpage. You are wating till step 9 (in javascript), till after the user has already recieved the page...
php has access to all the information that javascript has access to about the browser via the HTTP_USER_AGENT variable.
javascript's
document.location = 'blah.html'
is identical in outcome to using the header() function in php
header('Location: blah.html");
maybe this helps explain. if not maybe you can explain to me why you are waiting till javascript executes to change the users page.
you can use javascript to read form values and to write form values:
<form name="f1" action="form.php">
<input type="hidden" name="user" value="nobody">
</form>
<script language="javascript">
document.forms.f1.user = 'ednark';
document.forms.f1.submit()
</script>
will send form.php the variable
'user'=>'ednark'
not
'user'=>'nobody'
#form.php
print $_POST['user']
this will print
ednark
not
nobody