![]() |
|
Need Help: PHP Not redirecting - Printable Version +- Sinisterly (https://sinister.ly) +-- Forum: Coding (https://sinister.ly/Forum-Coding) +--- Forum: PHP (https://sinister.ly/Forum-PHP) +--- Thread: Need Help: PHP Not redirecting (/Thread-Need-Help-PHP-Not-redirecting) |
Need Help: PHP Not redirecting - Mudlight - 08-28-2017 I was using mysqli in the past and i decided to go and switch everything to PDO on this go around and im having a problem with my header("Location: profile.php"); not redirecting. root/include/dbc.php Code: <?
session_start();
# Connect to the Database:
try {
$host = ''; // Host name
$name = ''; // Database name
$user = ''; // Username
$pass = ''; // Password
$dbc = new PDO("mysql:host=$host;dbname=$name", $user, $pass);
}
catch(PDOException $e) {
echo $e->getMessage();
}
###### Register USER ######
if(isset($_POST['register'])){
$stmt = $dbc->prepare("INSERT INTO users ( gamertag, password ) VALUES ( :gamertag, :password )");
$stmt->bindParam(':gamertag', $_POST['gamertag']);
$stmt->bindParam(':password', $_POST['password']);
$stmt->execute();
}
###### Login USER ######
if(isset($_POST['login'])){
$gamertag = $_POST['gamertag'];
$password = $_POST['password'];
$select = $dbc->prepare("SELECT * FROM users WHERE gamertag='$gamertag' and password='$password'");
$select->setFetchMode(PDO::FETCH_ASSOC);
$select->execute();
$data=$select->fetch();
if($data['gamertag']!=$gamertag and $data['password']!=$password)
{
$message = "You entered the wrong gamertag or password";
}
elseif($data['gamertag']==$gamertag and $data['password']==$password)
{
$_SESSION['gamertag']=$data['gamertag'];
$_SESSION['email']=$data['email'];
header("Location: profile.php");
}
}
?>root/profile.php Code: <?
session_start();
echo var_dump($_SESSION);
?>my dbc.php is included into my index.php file where the forms are located any help would be appreciated .. thanks RE: Need Help: PHP Not redirecting - Esoterith - 08-28-2017 Attempt Code: header("Location ./profile");Need Help: PHP Not redirecting - Mudlight - 08-28-2017 (08-28-2017, 06:46 AM)Mystique Wrote: Attempt Yeah, I placed a error message in place of header to make sure and it echoes out every time and I var dump sessions in its place works out perfectly every time it’s just like it is ignoring header. I can echo out on either side and display it on the index.php. Thanks for the reply and willingness to help. RE: Need Help: PHP Not redirecting - Inori - 08-28-2017 As per the HTTP RFC specification, the Location header won't work if any other data has already been sent. This includes other headers, response content (which sets headers automatically), and (afaik) session tokens, so you may need to figure out a different method of data flow. RE: Need Help: PHP Not redirecting - saegenulled - 09-02-2017 The second validation, if the fetched data and the Post Data are equal is very nice, but i hope that you are escaping SQL-interpretable Signs in the Form Data, because with enough motivation and some Ideas, it is possible to overwrite the User Data. And without escaping your Query is vulnerable to injection, even with pdo Prepared Statements // POST DATA // gamertag=' or 'a'='a'#--' //gamertag='test' or 'a'='a |