login form
Moderator: General Moderators
login form
I need help coding a login form. I have a forum and a chat section to my site. I would like a form that would give the option to log in to either the forums or the chat. I have tried just about everything I thought would work but nothing did. Please help. Thank you
Jcart | Please use
Login.php
Thats what I have so far. I'm not really sure how to code the login.php since I have not yet used if statements since I don't really know how.
Jcart | Please use
Code: Select all
andCode: Select all
tags where appropriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
my site is set up so that the forums and the chat is are each at a subdomain of the main site where I would like to log on to one or the other. The forums uses a different username and password than the chat and both are not integrated at all. The php page that the login to the forums is login.php (forums is phpbb) and chat uses index.php to log into. So my login needs to be on the home page and it needs to log into the forums or the chat. I have it goin to a login.php on the main site for processing of which one to log on to. This is what I have so far.
[b]Login Form[/b]Code: Select all
<form id="login" name="login method="post" action="login.php">
<input name="username" type="text" id="username" size="15" />
<br />
<input name="password" type="password" id="password" size="15" />
<br />
<span class="style2">Select one to log in to. <br />
<input name="login" type="radio" value="forums" />
Forums
<input name="login" type="radio" value="chat" />
Chat </span>
<input type="submit" name="Submit" value="Login" />
</form>Code: Select all
<?
$login=$_POST['login'];
$username=$_POST['username'];
$password=$_POST['password'];
if ($login == forums)
{
}
if ($login == chat)
{
}
else
{
}
?>Jcart | Please use
Code: Select all
andCode: Select all
tags where appropriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Last edited by hinz347 on Wed Nov 09, 2005 9:13 pm, edited 1 time in total.
-
Charles256
- DevNet Resident
- Posts: 1375
- Joined: Fri Sep 16, 2005 9:06 pm
- jayshields
- DevNet Resident
- Posts: 1912
- Joined: Mon Aug 22, 2005 12:11 pm
- Location: Leeds/Manchester, England
Well, I've never POST'd radio buttons, but if your code is correct for checking against that then change your code to something like this:
Notice I left out your
that code is not needed, but ideally, it should be used along with something like this
or your own variable cleaning function or w/e.
Also notice I correctly your form name parameter, your missed the trailing double quotation mark after login.
Code: Select all
<?php
if (isset($_POST['submit'])) {
/*Validate the username and password here...
...
...
...
*/
if ($login == "forums") {
header("Location: http://www.yourdomain/path/to/forums.php");
}
if ($login == "chat") {
header("Location: http://www.yourdomain/path/to/chat.php");
}
}
?>
<form id="login" name="login" method="post" action="login.php">
<input name="username" type="text" id="username" size="15" />
<br />
<input name="password" type="password" id="password" size="15" />
<br />
<span class="style2">Select one to log in to. <br />
<input name="login" type="radio" value="forums" />
Forums
<input name="login" type="radio" value="chat" />
Chat </span>
<input type="submit" name="Submit" value="Login" />
</form>Code: Select all
$login = $_POST['login'];
$username = $_POST['username'];
$password = $_POST['password'];Code: Select all
$login = $_POST['login'];
$username = trim(stripslashes($_POST['username']));
$password = trim(stripslashes($_POST['password']));Also notice I correctly your form name parameter, your missed the trailing double quotation mark after login.
that could be why it doesnt work. if his host doesnt have register globals on, it wont work. add that in or change all $login to $_POST['login'] etc.jayshields wrote:
Notice I left out yourthat code is not needed, but ideally, it should be used along with something like thisCode: Select all
$login = $_POST['login']; $username = $_POST['username']; $password = $_POST['password'];
Code: Select all
if ($_POST['login'] == 'forums') {
header("Location: http://www.yourdomain.com/path/to/forums.php");
}
if ($_POST['login'] == 'chat') {
header("Location: http://www.yourdomain.com/path/to/chat.php");
}