Page 1 of 1

login form

Posted: Wed Nov 09, 2005 6:21 pm
by hinz347
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

Posted: Wed Nov 09, 2005 6:23 pm
by feyd
post your code, we'll try to help guide you in the right direction.

Posted: Wed Nov 09, 2005 8:38 pm
by hinz347
Jcart | Please use

Code: Select all

and

Code: 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&nbsp;&nbsp;      </span>
      <input type="submit" name="Submit" value="Login" />
</form>
Login.php

Code: Select all

<?
$login=$_POST['login'];
$username=$_POST['username'];
$password=$_POST['password'];

if ($login == forums)
{

}

if ($login == chat)
{

}
else
{

}
?>
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

and

Code: 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]

Posted: Wed Nov 09, 2005 8:42 pm
by Charles256
first things first when checing to see if something equals something else use two equal signs. one equal sign is the assignment operator;)

Posted: Wed Nov 09, 2005 9:14 pm
by hinz347
oh. Thankyou.

Posted: Thu Nov 10, 2005 5:50 am
by jayshields
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:

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&nbsp;&nbsp;      </span> 
      <input type="submit" name="Submit" value="Login" /> 
</form>
Notice I left out your

Code: Select all

$login = $_POST['login'];
$username = $_POST['username'];
$password = $_POST['password'];
that code is not needed, but ideally, it should be used along with something like this

Code: Select all

$login = $_POST['login'];
$username = trim(stripslashes($_POST['username']));
$password = trim(stripslashes($_POST['password']));
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.

Posted: Thu Nov 10, 2005 8:14 pm
by hinz347
that didn't work. but nevermind I just wont use a login sceipt

Posted: Fri Nov 11, 2005 12:51 am
by mickd
jayshields wrote:
Notice I left out your

Code: Select all

$login = $_POST['login'];
$username = $_POST['username'];
$password = $_POST['password'];
that code is not needed, but ideally, it should be used along with something like this
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.

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");
  }