Solved

PHP login to forward to HTML page

Posted on 2007-11-14
6
237 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
Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

 
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 500 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

688 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