Solved

PHP login to forward to HTML page

Posted on 2007-11-14
6
234 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
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…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

777 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