Jump to content

PHP Redirect


CodeTech

Recommended Posts

Can someone tell me how to fix this

 

At the top of every page i have this.

<?php include('GiveAway_Control.php');?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>

 

in the GiveAway_Control.php there is the

header("Location: http://www.domain.com/winner.html"); /* Redirect browser */

 

The GiveAway_Control.php has NO echo statements what so ever.

 

Link to comment
https://forums.phpfreaks.com/topic/232247-php-redirect/
Share on other sites

I have database stuff in the GiveAway_Control.php and depending of the responses, it either redirects or not. I don't see how that helps. If I load the GiveAway_Control.php by its self which has the redirect in it, it all works fine; I just can't get it to work with the include.

 

Another note:

 

if I just have...

<?php
header("Location: http://www.domain.com/winner.html"); 
?>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>

 

I get the same error. I don't get it.

 

Warning: Cannot modify header information - headers already sent by (output started at /home/domain/public_html/contact.php:1) in /home/domain/public_html/contact.php on line 2

 

Link to comment
https://forums.phpfreaks.com/topic/232247-php-redirect/#findComment-1194794
Share on other sites

Ok, I put it all in the same file. Still doesn't work.

 

<?php
////////// MySQL Database Information ////////////
$dbservertype='mySQL';
$servername='localhost';
$dbusername='**********';
$dbpassword='**********';
$dbname='**********';
////////// End Database Information ////////
//// Other Information ///////

function ConnectToDB($servername,$dbname,$dbuser,$dbpassword)
{
global $dblink;
$dblink = mysql_connect ("$servername","$dbuser","$dbpassword")or die("Couldn't connect to the database.");
mysql_select_db("$dbname",$dblink) or die ("Could not select Database".mysql_error());
}
ConnectToDB($servername,$dbname,$dbusername,$dbpassword);
$VisitorIP=$_SERVER['REMOTE_ADDR'];
$result = mysql_query("SELECT Hits FROM Visitors WHERE IP = '$VisitorIP'");
$num_rows = mysql_num_rows($result);
if($num_rows){
while ($row = mysql_fetch_array($result, MYSQL_NUM)) { $numHits = $row[0]; }
mysql_free_result($result);
$newHits = $numHits + 1;
mysql_query("UPDATE Visitors SET Hits = '$newHits' WHERE IP = '$VisitorIP' AND Hits = '$numHits'");
}
else {
	/*echo "Unable to match IP";*/
	mysql_query("INSERT INTO Visitors (IP, Hits, Date, Time) VALUES ('$VisitorIP', '1', CURDATE(), CURTIME())");
	$allrows = mysql_query("SELECT * FROM Visitors");
	$TotalVisitors = mysql_num_rows($allrows);
	mysql_free_result($allrows);
	if ($TotalVisitors == '7') {
		header("Location: http://www.domain.com/winner.html"); /* Redirect browser */
		exit;
	}
}	
?>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<body>
Why doesn't this work
</body>

</html>

Link to comment
https://forums.phpfreaks.com/topic/232247-php-redirect/#findComment-1194801
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.