Jump to content

Header relocating....!


Andy Booth

Recommended Posts

I have the following code at the top of my PHP page. Basically, it checks if the user is logged in, if they aren't its supposed to redirect them to login.php. Below that, I do some processing of data...The problem i'm having is that it redirects me to edit_games.php....

[code] session_start();
include('includes/toolbox.php');
include('includes/check_log_in.php');
doDB();
get_stats($mysqli);

if ($_SESSION["s_loggedin"] != "1")
{
header("Location: login.php");
}

$home_button = "../images/button_home_g.jpg";
$faq_button = "../images/button_faq_g.jpg";
$forum_button = "../images/button_forums_g.jpg";
$contact_button = "../images/button_contact_g.jpg";

switch($_SERVER["PHP_SELF"])
{
case "/index.php";
$home_button = "../images/button_home_o.jpg";
break;
case "/faq.php";
$faq_button = "../images/button_faq_o.jpg";
break;
case "/forum/index.php";
$forum_button = "../images/button_forums_o.jpg";
break;
case "/contact.php";
$contact_button = "../images/button_contact_o.jpg";
break;

}

if($_POST["comments_to_edit"] == "")
{
$owned_id = $_GET["owned_id"];
if ($owned_id != "")
{
$game_sql = "SELECT games.game_name, games.game_console, owned.owned_id, owned.master_id, owned.condition FROM games, owned WHERE (games.game_id= owned.game_id) AND (owned.owned_id = '".$owned_id."') AND (owned.master_id = '".$_SESSION["s_id"]."')";
$game_res = mysqli_query($mysqli, $game_sql) or die (mysqli_error($mysqli));
if (mysqli_num_rows($game_res) == "1")
{
$game_array = mysqli_fetch_array($game_res);
$game_name = $game_array["game_name"];
$game_platform = "<img src=\"images/title_".$game_array["game_console"].".gif\" alt=\"\$game_array[\"game_console\"]\">";
$game_comments = $game_array["condition"];
$owned_id = $game_array["owned_id"];
}
else
{
header("Location: edit_games.php");
}
}
else
{
header("Location: edit_games.php");
}
}
else
{
$owned_id = $_POST["hidden_id"];
$condition = $_POST["comments_to_edit"];
$game_sql = "UPDATE owned SET condition = '".$condition."' WHERE (owned_id = '".$owned_id."')";
$game_res = mysqli_query($mysqli, $game_sql) or die (mysqli_error($mysqli));
header("Location: edit_games.php");
}
[/code]

If I remove all the code including and after "if($_POST["comments_to_edit"] == "")" then it works. The thing I dont understand is, this code is below the check for a logged in user, so it should never even get looked at if the user is not logged in should it?

To re-iterate, the code above when used in its entirety redirects me to edit_games.php when the user isn't logged in, yet if I remove all the section of code starting with "if($_POST["comments_to_edit"] == "")" then it will redirect me to login.php

Really strange error to me this...

Hope someone can help :)
Link to comment
https://forums.phpfreaks.com/topic/34864-header-relocating/
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.