Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

Coding Forum


You are currently viewing our Coding Forum as a guest. Please register to participate.
Login



Reply
Old 04-25-2004, 11:09 PM Custom login pages?
Junior Talker

Posts: 2
Trades: 0
Is there a way to set up a login system so that when a user logs in he/she is automatically taken to a specific page for that user? In other words, when user abc logs in he is taken to /abc/index.html and when user xyz logs in she is taken to /xyz/index.html ? I know how to do a basic .htaccess setup to password protect a file/folder and allow users to register their own logins, but am not sure how to do a "custom login" where upon login a user is taken to a specific page for them. Another use would be for someone to login on my site's front page and then, based on their login, be transported to another page on the site.
joelwnelson is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-26-2004, 01:48 AM Script it
r3alityc0d3r's Avatar
Novice Talker

Posts: 14
Location: Austin, TX
Trades: 0
I have used ASP, JSP, and Servlets. Basically, you just setup a user database with a field that specifies where they go. For example my site sent employees to one subsite and customers to another subsite. They both had the same login page. I made a table in MySQL that had the username, password and Userlevel. Userlevel 1 = employee, Userlevel 2 = customer. The scripts would do a SELECT on the user DB and find out what the user level was then by use of a simple "if(rs.userlevel == 1) //goto the employee URL. Hope this helps. I don't think there is a way to do what you want with .htaccess. that just secures a folder.
r3alityc0d3r is offline
Reply With Quote
View Public Profile Visit r3alityc0d3r's homepage!
 
Old 04-26-2004, 11:11 AM
Junior Talker

Posts: 2
Trades: 0
Thanks for the response. I am not very familiar with MySQL so how would I set up the database (I at least know how to create a database) and then set it up to be queried?
joelwnelson is offline
Reply With Quote
View Public Profile
 
Old 04-26-2004, 01:00 PM
r3alityc0d3r's Avatar
Novice Talker

Posts: 14
Location: Austin, TX
Trades: 0
I use the oficial JDBC connector from MySQL:

Quote:
FirstName = req.getParameter("FirstName");
Password = req.getParameter("Password");
String url = "jdbc:mysql:localhost:3306/MomsDB?user='tomcat'&password='austinut'";
try
{
Class.forName("com.mysql.jdbc.Driver").newInstance ();
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/MomsDB?user=tomcat&password=austinut");
stmt = conn.createStatement();
rs = stmt.executeQuery("Select * from UserDB where Firstname='"+FirstName+"' and Password='"+Password+"'");
if (rs.next())
{
userlevel = rs.getInt("employee");
Cookie cookie = new Cookie("MomsUser", FirstName);
cookie.setMaxAge(-1);
cookie.setPath("/");
res.addCookie(cookie);

Cookie lvlcookie = new Cookie("MomsLevel", String.valueOf(userlevel));
lvlcookie.setMaxAge(-1);
lvlcookie.setPath("/");
res.addCookie(lvlcookie);

custid = rs.getInt("num");
Cookie cidcookie = new Cookie("CustID", String.valueOf(custid));
cidcookie.setMaxAge(-1);
cidcookie.setPath("/");
res.addCookie(cidcookie);

myerror = false;
} else {
myerror = true;
}
} catch (SQLException ex)
{
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
myerror = true;
}
catch (ClassNotFoundException e)
{
System.out.println("Can't load the JDBC driver");
}
catch (InstantiationException e)
{
System.out.println("Problem Instantiating JDBC Driver");
}
catch (IllegalAccessException e)
{
System.out.println("Illegal Access Exception JDBC Driver");
}
finally
{
if (rs != null)
{
try
{
rs.close();
} catch (SQLException sqlEx) { }
rs = null;
}
if (stmt != null)
{
try
{
stmt.close();
} catch (SQLException sqlEx) { }
stmt = null;
}
if( myerror )
{
res.sendRedirect("http://www.rogue-soul.com/login.html?message=failed1023");
} else {
if(userlevel==0) {
res.sendRedirect("http://www.rogue-soul.com/customer.html");
} else {
res.sendRedirect("http://www.rogue-soul.com/employee.html");
}

}

}
r3alityc0d3r is offline
Reply With Quote
View Public Profile Visit r3alityc0d3r's homepage!
 
Reply     « Reply to Custom login pages?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.16977 seconds with 12 queries