Forum Moderators: coopster

Message Too Old, No Replies

redirecting the browser

         

infinity

12:05 am on Oct 5, 2003 (gmt 0)

10+ Year Member



Well, I know how to redirect the browser with PHP using something like

header('Location: http://mysitehere.com');

But is there any other way to redirect with PHP? If not, I need some help fixxing my script (I always get an error that says I cannot modify header information.

jatar_k

1:30 am on Oct 5, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld infinity,

was it

cannot modify headers already started at ...

usually that message means you have already outputted something to the browser. It could even be a space above the starting <?.

Take a look and see if there is any output at all.

infinity

1:53 am on Oct 5, 2003 (gmt 0)

10+ Year Member



Yes thats the error I get, but take a look @ my code, I dont see anything that would cause this error.


<head>
<title>.: omni :.</title>
<link rel="stylesheet" href="text.css" type="text/css">
</head>

<?php

#change localhost to the sql server, user to the correct username, and pass to the correct password
$con = mysql_connect("localhost","****_****","*******")
or die("Unable to establish a connection to the database.");

#change database to the database name
$database = "******_*****";
$db = mysql_select_db("$database") or die("Couldn't select database $database.");

// IP Banning Function

function ipbanning ($addr)

{

$banned_ips = array();

$banned_ip[] = array(' \123.123.***.***', ' banned');
$banned_ip[] = array(' \123.123.***.***', ' banned');

// continue adding list of banned ips where necessary.

foreach ($banned_ips as $banned_ip) {
$addr = eregi_replace($banned_ip[0],$banned_ip,$addr);
}
return trim($addr);

}

// do the check for ip banning

$ip = ipbanning($REMOTE_ADDR);

if ($ip=='banned')
{
die ("IP banned, you cannot post shouts.");
}

// do a basic check, don't let user submit a blank entry.

if ($name == '' ¦¦ $msg == '' ¦¦ $name == 'name' ¦¦ $msg == 'message')
{
die ("Error! You cannot fill in an empty shout. Please try again.");
}

// strips off weird characters and HTML tags

$name = htmlspecialchars($name);
$msg = htmlspecialchars($msg);

// do check here

$last_entry = "select * from shoutbox order by id desc";
$check = mysql_query($last_entry);

while ($row = mysql_fetch_array($check))
{
$oldname = $row["name"];
$oldmsg = $row["msg"];
}

// compare the values of old and new entry
if ($oldname == $name && $oldmsg == $msg) // means the name and msg entered is the same
{
die ("Error! Duplicate entry detected, please submit only once.");
}

// insert into database

$q = "insert into shoutbox (id,name,msg) VALUES ('','$name','$msg') ";
$result = mysql_query($q);

if ($result)
{
// success so redirect user to view shoutbox.
$siteurl = 'view.php';
header('Location: [site.com');...]
}

?>

[1][edited by: jatar_k at 3:17 am (utc) on Oct. 5, 2003]
[edit reason] generalized [/edit]

jatar_k

3:18 am on Oct 5, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



ouput to browser

<head>
<title>.: omni :.</title>
<link rel="stylesheet" href="text.css" type="text/css">
</head>

you can't have anything otherwise it will give you that error. ;)

dreamcatcher

4:32 pm on Oct 5, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What I usually do is create a function with a message in and use a meta refresh. ie:

if ($result)

{

// success so redirect user to view shoutbox.

$siteurl = 'view.php';

redirect();

}

function redirect() {

echo "<meta http-equiv=\"refresh\" content=\"3;URL=http://www.site.com\">\n";
echo "Thank you, please wait....\n";
exit;

}

?>

Or something like that.

And welcome to Webmaster World.

:)

infinity

4:54 pm on Oct 5, 2003 (gmt 0)

10+ Year Member



well jatar I still get the same error after deleting it...I think I'll try dreamcatchers idea

jatar_k

4:59 pm on Oct 5, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



there has to be some output otherwise it would work just fine.

If it is just redirecting to a page on your site then you could also just include the page. The meta refresh will work just fine also.