Gotharious Posted November 5, 2011 Share Posted November 5, 2011 hello all, What I want to do is, make the session ID clickable in a url here Login Successful <a href="user.php">Conitnue</a> so when a user logs in, his ID gets in the link of Continue so he can only see his information so for example, if his id is 10, then the url would be ....user.php?id=10 Quote Link to comment https://forums.phpfreaks.com/topic/250510-session-to-url/ Share on other sites More sharing options...
watsmyname Posted November 5, 2011 Share Posted November 5, 2011 Login Successful <a href="user.php?id=<?php echo $_SESSION["user_id"]?>">Conitnue</a> Quote Link to comment https://forums.phpfreaks.com/topic/250510-session-to-url/#findComment-1285279 Share on other sites More sharing options...
Gotharious Posted November 5, 2011 Author Share Posted November 5, 2011 ok thanks, that's great now what if I want to redirect based on the user type I mean it looks up the database, and check the column type, and if this user is admin it redirects to admin.php, if staff then to staff.php and if client, then to client.php I tried header but didn't work at all Quote Link to comment https://forums.phpfreaks.com/topic/250510-session-to-url/#findComment-1285280 Share on other sites More sharing options...
watsmyname Posted November 5, 2011 Share Posted November 5, 2011 if you've outputted or echoed something before header code, it won't work, instead you can use (though is not a good approach) <?php echo "<script>document.location.href='admin.php'</script>";?> Quote Link to comment https://forums.phpfreaks.com/topic/250510-session-to-url/#findComment-1285282 Share on other sites More sharing options...
Gotharious Posted November 5, 2011 Author Share Posted November 5, 2011 no, I'm not following now ok here is the code, what do I need to add? <?php if (isset($_POST['email'])) { $email = $_POST['email']; $password = $_POST['password']; //Query $results = mysql_query("SELECT * FROM users WHERE email = '$email' AND password = '$password' "); $row = mysql_fetch_assoc($results); $count=mysql_num_rows($results); if($count==1){ // Register $myusername, $mypassword and redirect to file "login_success.php" session_register("email"); session_register("password"); header("location:index.php"); $_SESSION['id'] = $row['id']; } else { echo "Wrong Username or Password, Please click back and try again"; } mysql_close($con); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/250510-session-to-url/#findComment-1285292 Share on other sites More sharing options...
Gotharious Posted November 5, 2011 Author Share Posted November 5, 2011 Ok, I've done it here is the code I used <?php $results = mysql_query("SELECT * FROM users WHERE email = '$email' AND password = '$password' "); $row = mysql_fetch_assoc($results); $count=mysql_num_rows($results); if($count==1){ // Register $myusername, $mypassword and redirect to file "login_success.php" session_register("email"); session_register("password"); $_SESSION['id'] = $row['id']; $type = $row['type']; switch ($type) { case ($type=='client'): header("location:user.php"); break; case ($type=='Company'): header("location:Users.php"); break; case ($type=='employee'): header("location:employee.php"); break; } } else { echo "Wrong Username or Password, Please click back and try again"; } mysql_close($con); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/250510-session-to-url/#findComment-1285313 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.