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
Solved

PHP login to forward to HTML page

Posted on 2007-11-14
6
235 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
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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
mysqli_query() expects parameter 1 to be msqli, string given in 4 62
Dynamic Dropdowns 15 32
Why will this INSERT statement not insert the date? 2 20
php help 34 58
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

840 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