Solved

PHP login to forward to HTML page

Posted on 2007-11-14
6
231 Views
Last Modified: 2013-12-13
Here is my code:

<html>
<head />
<body>
<form action="login2.php" method=POST>
<table border="0" width="100%" id="table1">
      <tr>
            <td width="42%">&nbsp;</td>
            <td align="center" width="15%" colspan="2">
<img src="http://www.website/images/about/CG210.png" width="321" height="188"><p align="center">
<?php

$user=$_POST['user'];
$pass=$_POST['pass'];

$link="<a href=\"http://www.website/page.html\"><strong>View Plans</strong></a>";

if(($user=="user") && ($pass=="pass")) echo('<table width="100%"><tr><td align="center">'."$link".'</td></tr></table>');

else echo('<table width="100%"><tr><td align="center">Please Login</td></tr></table>');

?>

<br>

<font size="4">&nbsp;Welcome</font></td>
<tr>
            <td align="center" width="41%">
            &nbsp;</td>
      </tr>
      <tr>
            <td width="42%">&nbsp;</td>
            <td align="center" width="4%" style="text-align: left; margin-left: 20">
            <p style="margin-left: 22px">Username</td>
            <td align="center" width="11%" style="text-align: left; margin-left: 20">
            <input name=user style="float: left" size="29"></td>
            <td align="center" width="41%">
            <p align="left">&nbsp;</td>
      </tr>
      <tr>
            <td width="42%" height="30">&nbsp;</td>
            <td align="center" height="30">
            <p align="left" style="margin-left: 22px">Password</td>
            <td align="center" height="30">
            <input type=password name=pass style="float: left" size="29"></td>
            <td align="center" width="41%" height="30">
            &nbsp;</td>
      </tr>
      <tr>
            <td width="42%" height="30">&nbsp;</td>
            <td align="center" width="15%" height="30" colspan="2">
            <p align="left" style="margin-left: 21px">
<input type=submit value="Login" style="float: left"></td>
            <td align="center" width="41%" height="30">
            <p align="left">&nbsp;</td>
      </tr>
      </table>
<p>
<p>
</form>

</body>
</html>

What I want to do is:

when the user logins in with the correct username password combo, they are displayed a link. all is well and it works perfectly with the code above. However I am wanting instead of displaying a link, I would like it to take the user directly to the link when the login is correct. Is this possible. If so, help. If not: i would like to display just the link and  hide the username & password boxes.

I know this is extremely basic. I will soon be using global variables/sessions to verify login for the future login pages.

0
Comment
Question by:bcmeyer1983
  • 4
  • 2
6 Comments
 
LVL 17

Expert Comment

by:nplib
Comment Utility
Change your code to look like this
<?php

$user=$_POST['user'];
$pass=$_POST['pass'];

$link="http://www.website/page.html";

if(($user=="user") && ($pass=="pass")) {
 header("location:$link");
}
 $html = '<table width="100%"><tr><td align="center">Please Login</td></tr></table>';
}
?>
<html>
<head />
<body>
<form action="login2.php" method=POST>
<table border="0" width="100%" id="table1">
      <tr>
            <td width="42%">&nbsp;</td>
            <td align="center" width="15%" colspan="2">
<img src="http://www.website/images/about/CG210.png" width="321" height="188"><p align="center">
<?=$html ?>
<br>

<font size="4">&nbsp;Welcome</font></td>
<tr>
            <td align="center" width="41%">
            &nbsp;</td>
      </tr>
      <tr>
            <td width="42%">&nbsp;</td>
            <td align="center" width="4%" style="text-align: left; margin-left: 20">
            <p style="margin-left: 22px">Username</td>
            <td align="center" width="11%" style="text-align: left; margin-left: 20">
            <input name=user style="float: left" size="29"></td>
            <td align="center" width="41%">
            <p align="left">&nbsp;</td>
      </tr>
      <tr>
            <td width="42%" height="30">&nbsp;</td>
            <td align="center" height="30">
            <p align="left" style="margin-left: 22px">Password</td>
            <td align="center" height="30">
            <input type=password name=pass style="float: left" size="29"></td>
            <td align="center" width="41%" height="30">
            &nbsp;</td>
      </tr>
      <tr>
            <td width="42%" height="30">&nbsp;</td>
            <td align="center" width="15%" height="30" colspan="2">
            <p align="left" style="margin-left: 21px">
<input type=submit value="Login" style="float: left"></td>
            <td align="center" width="41%" height="30">
            <p align="left">&nbsp;</td>
      </tr>
      </table>
<p>
<p>
</form>

</body>
</html>
0
 
LVL 2

Author Comment

by:bcmeyer1983
Comment Utility
nothing happens. i also removed a bracket on line 12 that was extra.....
0
 
LVL 2

Author Comment

by:bcmeyer1983
Comment Utility
also my please login is not showing...
0
Easy Project Management (No User Manual Required)

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 2

Author Comment

by:bcmeyer1983
Comment Utility
sorry wrong username password combo it forwards to the link - thanks
i just need my please login to display :)
0
 
LVL 17

Accepted Solution

by:
nplib earned 500 total points
Comment Utility
cause you removed a bracket that is not extra.

if($something == "something") {
 do something
} else {
   do somethign else
}
the brackets are needed, if they are not present, nothing will happen.

Also, just so you know
if(($user=="user") && ($pass=="pass")) {
says if the variable $user is equal to the value "user" and the variable $pass is equal to the value $pass then return true.

0
 
LVL 2

Author Comment

by:bcmeyer1983
Comment Utility
awesome worked out.
0

Featured Post

Easy Project Management (No User Manual Required)

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now