Discuss Trying to redirect login user to specific url in the PHP Development forum on Dev Shed. Trying to redirect login user to specific url PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
Posts: 22
Time spent in forums: 3 h 52 m 53 sec
Reputation Power: 0
Trying to redirect login user to specific url
Spent 3 days figuring out how this whole deal works with allowing a user to register a name and password, placing that information in a database, and allowing them to login and all that good stuff. Well, I'm stuck... I know how to create a database, I know how to create a table, and I know how to recall information from a table on a webpage. I even currently have it setup so that when a user logs in it takes them to a page where it displays their specified url. This is great, but what I'd like to happen is when they login to their account it takes them directly to their URL, rather than have them have to click on their account on the login successful screen... Make sense? My coding is very simple. This is my code for my login.php page...
FGMembersite is the PHP that checks the info... as you can see, it automatically redirects the user to "login-home.php". But, it is not checking what user is logged in and redirecting it to their own specified page. I feel like there's like one line of coding I could put in there in place of $fgmembersite->RedirectToURL("login-home.php"); to make this work, but maybe not? Pretty new to this, so I'm not able to fully understand everything. HELP PLEASE!
Posts: 22
Time spent in forums: 3 h 52 m 53 sec
Reputation Power: 0
I've been seeing this everywhere but where do I put that?
I've been seeing a redirect header everywhere, but I have no idea what file to place that in or how it works. I mean, I get what the header does, as in, it would redirect me to "login-home.php", but how does it know what user has logged in?
Like, I don't understand how it all works, but it only makes sense for their to be a way for once a user is logged in that there is a new url created for them specifically so that there can be personalized information... and you can recall a new table (or whatever) that is specific to that users information... am I making sense?
Quote:
Originally Posted by Rhytz
Why not use a redirect header?
PHP Code:
header('Location: login-home.php');
You should be getting the member data within login-home.php
Posts: 22
Time spent in forums: 3 h 52 m 53 sec
Reputation Power: 0
Session...
That definitely makes sense, so that each user is specifically logged into their session... And I definitely don't want to be any security risks... Is there a good tutorial to recommend for how to do this?
Posts: 163
Time spent in forums: 1 Day 13 h 18 m 54 sec
Reputation Power: 17
When you write your login script you want it to be something similar to this but specific to your variables.
PHP Code:
INCLUDE(sqlconfig.php);
session_start();
$result=mysql_query('SELECT * FROM userTable WHERE userName='$_POST[userName]');
WHILE($row=mysql_fetch_array($result)){
if($row[userPassword]==$_POST['Password']){
$_SESSION['userName']=$_POST['userName'];
HEADER('location: loginhome.php');
}else{
HEADER('location: loginfailed.php');
}
}
This way after the user logs in their username is stored in $_SESSION['userName'] for future reference by other scripts during the duration of the session
Posts: 163
Time spent in forums: 1 Day 13 h 18 m 54 sec
Reputation Power: 17
Yes I realize their is SQL injection vulnerabilities in this code just trying to keep it as so to keep it simple and prefer using php rather than pseudo code for demonstration
Posts: 1,833
Time spent in forums: 1 Month 2 Weeks 1 Day 53 m 25 sec
Reputation Power: 811
Quote:
Originally Posted by portcitysoftwar
Yes I realize their is SQL injection vulnerabilities in this code just trying to keep it as so to keep it simple and prefer using php rather than pseudo code for demonstration
C'mon, that's a poor excuse. If you don't know to write proper PHP (or you don't have the time for it or whatever), then do use pseudo code instead.
There's nothing worse than posting bad code snippets, because those are likely to be just copied and pasted. And you didn't even say anything about the security holes.
Posts: 163
Time spent in forums: 1 Day 13 h 18 m 54 sec
Reputation Power: 17
yes i apologize for that. I should have included or at least mentioned the need to validate the input from the user before including it in the MySQL query.
However on a side note mysql_query is not deprecated yet is it? or am i just that far behind? I am currently running php 5.3.2 and i know there is php 5.4.x available but as far as i am aware the mysql_query method is not deprecated until 5.5.x when the mysql improved extension will replace the former mysql extension. I have used this method for many years and was how i was taught in college. What are the benefits of the MySqlI or using a data object?
Thanks alot,
TJ
Quote:
Originally Posted by Jacques1
C'mon, that's a poor excuse. If you don't know to write proper PHP (or you don't have the time for it or whatever), then do use pseudo code instead.
There's nothing worse than posting bad code snippets, because those are likely to be just copied and pasted. And you didn't even say anything about the security holes.
Posts: 12,676
Time spent in forums: 5 Months 1 Week 4 Days 1 h 40 m 59 sec
Reputation Power: 8969
It wasn't until ~5.5 that they decided to make it officially deprecated, true. However there are no new features that suddenly made it so - the PHP devs finally acknowledged that the mysql extension was inferior to mysqli and PDO, both of which have been out for a while. Those better tools are available to everyone and they should be using it right now.
Posts: 163
Time spent in forums: 1 Day 13 h 18 m 54 sec
Reputation Power: 17
Alright thanks for the information. Which one is superior between the two other than the fact that PDO supports more database drivers. I am familliar with pdo for MsSQL connections
Quote:
Originally Posted by requinix
It wasn't until ~5.5 that they decided to make it officially deprecated, true. However there are no new features that suddenly made it so - the PHP devs finally acknowledged that the mysql extension was inferior to mysqli and PDO, both of which have been out for a while. Those better tools are available to everyone and they should be using it right now.