重定向是否脱机但不在线?

时间:2021-08-19 18:10:15

On my offline dev server, I have the following code:

在我的离线开发服务器上,我有以下代码:

<?php //submit_build.php

include_once 'header.php';
require_once 'login_users.php';
include_once 'functions.php';

if(empty($_SESSION['username']))
die ("You must be logged in to use this page");

$choice = $_GET['choice'];

$db_server = mysql_connect($db_hostname, $db_username, $db_password);

mysql_select_db($db_database)
    or die("Unable to select database: " . mysql_error());


if (isset($_POST['buildname']) &&
    isset($_POST['weapon']) &&
    isset($_POST['mod1']) &&
    isset($_POST['description']) &&
    isset($_POST['category']) &&
    isset($_POST['hidden']) &&
    isset($_POST['password']))
{
$buildname = clean(sanitizeString($_POST['buildname']));
$buildurl = urlencode($buildname);
$section = $choice;
$weapon =   sanitizeString($_POST['weapon']);
$modcap = sanitizeString($_POST['modcap']);
$mod1 =     sanitizeString($_POST['mod1']);
$mod2 =     sanitizeString($_POST['mod2']);
$mod3 =     sanitizeString($_POST['mod3']);
$mod4 =     sanitizeString($_POST['mod4']);
$mod5 =     sanitizeString($_POST['mod5']);
$mod6 =     sanitizeString($_POST['mod6']);
$mod7 =     sanitizeString($_POST['mod7']);
$mod8 =     sanitizeString($_POST['mod8']);
$polarity1 =    sanitizeString($_POST['polarity1']);
$polarity2 =    sanitizeString($_POST['polarity2']);
$polarity3 =    sanitizeString($_POST['polarity3']);
$polarity4 =    sanitizeString($_POST['polarity4']);
$polarity5 =    sanitizeString($_POST['polarity5']);
$polarity6 =    sanitizeString($_POST['polarity6']);
$polarity7 =    sanitizeString($_POST['polarity7']);
$polarity8 =    sanitizeString($_POST['polarity8']);
$description =  sanitizeString($_POST['description']);
$category =     sanitizeString($_POST['category']);
$hidden =       sanitizeString($_POST['hidden']);
$pw_check =     sanitizeString($_POST['password']);

$pw_check = md5($pw_check);
if ($pw_check == ($_SESSION['password']))
{
$add_build = "INSERT INTO weapons VALUES(NULL,'$username', '$buildname', '$section', '$weapon', '$modcap', '$mod1', '$mod2', '$mod3', '$mod4', '$mod5', '$mod6', '$mod7', '$mod8', '$polarity1', '$polarity2', '$polarity3', '$polarity4', '$polarity5', '$polarity6', '$polarity7', '$polarity8', '$category', '$hidden', '$description', NULL, '{$_SESSION['ipaddress']}', '$buildurl')";
mysql_query($add_build);
header("Location: account.php");
}
else{
die("Incorrect password.");


}
}

Followed by some more PHP, and HTML later on in the document.

接下来是文档中的更多PHP和HTML。

NOTE The file header.php contains HTML.

注意文件header.php包含HTML。

My code works perfectly offline. I can click submit, and I will be redirected to account.php.

我的代码完全脱机工作。我可以点击提交,然后我将被重定向到account.php。

However as soon as I upload the files to my remote server, the code still works perfectly but the redirect does not. Instead of redirecting, it just brings me back to the same page. The data that was entered DOES however get submitted to MySQL, so it's just the redirect that isnt working.

但是,只要我将文件上传到远程服务器,代码仍然可以正常工作,但重定向不会。它不是重定向,而是让我回到同一页面。然而,输入的数据会被提交给MySQL,因此它只是重定向无效。

Can someone tell me how I would get this

谁能告诉我怎么会得到这个

header(Location: account.php);

to work? Where should I place it? Or where should I move

上班?我应该把它放在哪里?或者我应该在哪里移动

include_once 'header.php';

to make it work?

使它工作?

Thanks so much!

非常感谢!

EDIT:

Here is my authenticate.php file.. up to where the html begins. Maybe you can see an issue here.

这是我的authenticate.php文件..直到html开始的地方。也许你可以在这里看到一个问题。

<?php // authenticate.php
include_once 'functions.php';
require_once 'login_users.php';

$db_server = mysql_connect($db_hostname, $db_username, $db_password);
if (!$db_server) die("Unable to connect to database:" . mysql_error());
mysql_select_db($db_database)
    or die("Unable to find database:" . mysql_error());

if (!empty($_POST['username']) &&
    (!empty($_POST['pw_temp'])))
{
    $username = sanitizeString($_POST['username']);
    $pw_temp = sanitizeString($_POST['pw_temp']);
    $pw_temp = md5($pw_temp);
    $query = "SELECT username,password FROM users WHERE username='$username' AND password='$pw_temp'";
    if (mysql_num_rows(mysql_query($query)) == 0)
    {
    die("Wrong info");
    }
    else
    {
            session_start();
            $_SESSION['username'] = $username;
            $_SESSION['password'] = $pw_temp;
            $_SESSION['ipaddress'] = $_SERVER['REMOTE_ADDR'];
            header('Location: index.php');
            exit;
     }      
}else{
include_once 'header.php';


echo <<<_END

<html xmlns="http://www.w3.org/1999/xhtml">

1 个解决方案

#1


0  

Its a good idea to exit; after a header() as otherwise your code will continue in the current script. Which probably means it will send itself again. So you may well be running account.php but this page is then being sent and overwriting account.php making it look like account.php is not being run.

退出是一个好主意;在header()之后,否则您的代码将在当前脚本中继续。这可能意味着它会再次发送自己。所以你可能正在运行account.php但是这个页面正在被发送并覆盖account.php使它看起来像account.php没有被运行。

#1


0  

Its a good idea to exit; after a header() as otherwise your code will continue in the current script. Which probably means it will send itself again. So you may well be running account.php but this page is then being sent and overwriting account.php making it look like account.php is not being run.

退出是一个好主意;在header()之后,否则您的代码将在当前脚本中继续。这可能意味着它会再次发送自己。所以你可能正在运行account.php但是这个页面正在被发送并覆盖account.php使它看起来像account.php没有被运行。