Page 1 of 1

Php and javascript problem

Posted: Mon Oct 09, 2006 3:19 pm
by satheshf12000
Hi all,
I have used the following code to redirect the registered user to the member page upon successful login.

Code: Select all

$insert_goto = "member.php";
	print "<script language=\"JavaScript\">";
	print "window.location = '$insert_goto' ";
	print "</script>";
Everything works perfect until if the user disables the javascript(i tested it in firefox) in his browser, then the page stops suddenly in the middle. If i use

Code: Select all

header('location: member.php');
, then i get the header already sent error. What shall i do ? Any help is appreciated..

thanks..

Posted: Mon Oct 09, 2006 3:27 pm
by volka
search the forum for headers alread sent.
It's one of the more common problems and more often ask questions.

You might also consider

Code: Select all

<meta http-equiv="refresh" content="5; URL=http://www.whatev.er">

Posted: Mon Oct 09, 2006 3:28 pm
by Burrito
search this forum for the 'headers already sent' error.

it's been talked about thousands of times.

basically you just need to make sure you're not outputting anything above the header function.

another alternative would be a meta refresh, but your best solution is going to be to get header() to work.

edit: damn it...volka beat me to it.

Posted: Wed Oct 11, 2006 5:29 pm
by satheshf12000
I searched the forum and found that no HTML should be sent before header. Atleast the title will be sent. The situation is this.

1. Can't use javascript (if user disables the javascript).
2. Using html to send atleast title and some meta tags and sometimes more html to design tables and etc..

How can i redirect then ? Using

Code: Select all

<meta http-equiv="refresh" content="0;url=www.xx.com">
..? If I use meta to redirect, what are the disadvantages ?? Any other way ??

Posted: Wed Oct 11, 2006 6:44 pm
by volka
satheshf12000 wrote:2. Using html to send atleast title and some meta tags and sometimes more html to design tables and etc..
What is the point in sending a html document (even only parts of if) when there's a "hey client, don't fetch this document, load another one" header?;)

satheshf12000 wrote:How can i redirect then ? Using

Code: Select all

<meta http-equiv="refresh" content="0;url=www.xx.com">
..? If I use meta to redirect, what are the disadvantages ?? Any other way ??
disadvantages:
http://www.w3.org/TR/html4/struct/global.html#edef-META wrote:Note. Some user agents support the use of META to refresh the current page after a specified number of seconds, with the option of replacing it by a different URI. Authors should not use this technique to forward users to different pages, as this makes the page inaccessible to some users. Instead, automatic page forwarding should be done using server-side redirects.
If you have to bother with such browsers (not supporting meta/refresh) in the real world you may use

Code: Select all

<html>
	<head>
		<title>redirect test</title>
		<meta http-equiv="refresh" content="1;url=www.php.net">
	</head>
	<body>
		<div>
			If your browser does not support meta redirection please click
			<a href="http://www.php.net">here</a>
		</div>
	</body>
</html>

Posted: Fri Oct 13, 2006 11:55 am
by satheshf12000
can we detect whether javascript is disabled or not in PHP ? Is there anyway ?

Posted: Fri Oct 13, 2006 1:01 pm
by feyd
It's not possible to detect if Javascript is enabled in PHP alone. It needs some help from the browser. Basically, you write a piece of Javascript in the initial page request that requests (in some fashion) a file/url or something that will signal your server that they have Javascript on. You also supply a <noscript> so that it doesn't break functionality.