简体   繁体   中英

Insert variable into Header Location PHP 1

The question is: How do i insert the variable $conf_url as a part of the link in line 16: header('Location:' $conf_url.'index_back.php');

<?php
session_start();
include("conexao.php");

$email = $_POST['email'];
$senha = $_POST['senha'];

$query1 = mysqli_query($con, "SELECT * FROM usuario WHERE email = '$email' AND senha = '$senha'");
$row = $query1->fetch_row();
$_SESSION["iduser"] = $row[0];
$_SESSION["nome"] = $row[2];
$_SESSION["sobrenome"] = $row[3];
$_SESSION["img"] = $row[8];

if($query1->num_rows == 1){
    header('Location:' $conf_url.'index_back.php');
    //echo "<meta http-equiv='refresh' content='0, url= $conf_url/index_back.php'>";
}else{
    $_SESSION['error'] = 'Email e/ou senha invalido(s).';
    header('Location: '$conf_url'.'/login.php);
    //echo "<meta http-equiv='refresh' content='0, url= $conf_url/login.php'>";
}
?>

config.php
<?php
$conf_url = "http://localhost/production/";
?>

你可以这样做

header("Location: " .$conf_url. "/login.php");

You have simply missed the '.' concatenation mark in both of your header() functions, and also messed up the string literals.

if($query1->num_rows == 1){
    header('Location:' . $conf_url . '/index_back.php');

}else{
    $_SESSION['error'] = 'Email e/ou senha invalido(s).';
    header('Location: ' . $conf_url . '/login.php');

}

Or using variable expansion in double quotes.

if($query1->num_rows == 1){
    header("Location: $conf_url/index_back.php");

}else{
    $_SESSION['error'] = 'Email e/ou senha invalido(s).';
    header("Location: $conf_url/login.php");

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM