Revdutchie
Revdutchie

Reputation: 41

php redirect after database query and use the output

I have some gameservers and players can use keywords to open websites in the game. Now I want to give them the possibility to see their own profile page usings the keyword "/me" what it does is, it will open a link that looks like this "http://mywebsite.net/me.php?&NEWID=STEAM_0%3a1%3a40577662&SRVIP=145.226.237.229&SRVPORT=27030"

now problem 1 is that the NEWID part needs to be converted into an other format, I use

$split = explode(":", $_GET[ 'NEWID' ]); // STEAM_?:?:??????? format

$x = substr($split[0], 6, 1);
$y = $split[1];
$z = $split[2];

$namesearch = ($z * 2) + 0x0110000100000000 + $y;

It will give me the right format I need a 17 digit number like 45687654326787987 This number I use to do a database lookup to find the userid we use on our website with the following code;

// echo $namesearch. "<br>";

include 'db_login_details.php';

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
  if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
} 
//echo "Connected successfully";
//echo "<br>";

$sql = "SELECT * FROM users WHERE loginname LIKE $namesearch";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
  // output data of each row
while($row = $result->fetch_assoc()) {
    //echo "Your username: " . $row["username"]. "<br>";
    //echo "Your userID: uid" . $row["uid"]. "<br>";
    $uid = $row["uid"];
    //echo $uid;
}
} else {
//echo "0 results";
}

$conn->close();

Now once I have all the info I needed I want to open the right profile page with

header( 'http://mywebsite.net/member.php?action=profile&uid=' .$uid );

And that last step fails, I know you may not echo anything before redirecting, that's why I commented all the echo lines, they are just there to check my code but it's still not working. Anybody has a solution for me?

Best regards, Jacques

Upvotes: 2

Views: 768

Answers (1)

ZZZZtop
ZZZZtop

Reputation: 457

The problem is because you're not defining the Location so for example it should look like this:

header( "Location: http://mywebsite.php?action=profile&uid=" . $uid );

Upvotes: 2

Related Questions