[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

PHP login to forward to HTML page

Posted on 2007-11-14
6
Medium Priority
?
240 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 17

Expert Comment

by:nplib
ID: 20283368
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
ID: 20283515
nothing happens. i also removed a bracket on line 12 that was extra.....
0
 
LVL 2

Author Comment

by:bcmeyer1983
ID: 20283562
also my please login is not showing...
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 2

Author Comment

by:bcmeyer1983
ID: 20283589
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 2000 total points
ID: 20283830
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
ID: 20283842
awesome worked out.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
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.
Suggested Courses

656 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