Php and javascript problem

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
satheshf12000
Forum Commoner
Posts: 25
Joined: Mon Sep 04, 2006 5:38 pm

Php and javascript problem

Post 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..
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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">
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post 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.
satheshf12000
Forum Commoner
Posts: 25
Joined: Mon Sep 04, 2006 5:38 pm

Post 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 ??
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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>
satheshf12000
Forum Commoner
Posts: 25
Joined: Mon Sep 04, 2006 5:38 pm

Post by satheshf12000 »

can we detect whether javascript is disabled or not in PHP ? Is there anyway ?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Post Reply