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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.