Login Register


Need Help: PHP Not redirecting filter_list
Author
Message
Need Help: PHP Not redirecting #1
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

Reply

RE: Need Help: PHP Not redirecting #2
Attempt
Code:
header("Location ./profile");
And are you sure everything else runs. I'm on my phone right now. But if the problem still is happening tomorrow I'll poker deeper into it.

Reply

Need Help: PHP Not redirecting #3
(08-28-2017, 06:46 AM)Mystique Wrote: Attempt
Code:
header("Location ./profile");
And are you sure everything else runs. I'm on my phone right now. But if the problem still is happening tomorrow I'll poker deeper into it.


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.

Reply

RE: Need Help: PHP Not redirecting #4
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.
It's often the outcasts, the iconoclasts ... those who have the least to lose because they
don't have much in the first place, who feel the new currents and ride them the farthest.

Reply

RE: Need Help: PHP Not redirecting #5
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
(This post was last modified: 09-03-2017, 01:42 AM by saegenulled.)

Reply







Users browsing this thread: 1 Guest(s)