Solved

PHP & HTML

Posted on 2004-10-31
343 Views
Last Modified: 2006-11-17

I have asked previously to make script to ban certain IPs from my site and redirect them to another page with login, they can access the site only after providing the right login info.

Everything seems ok so far except for one thing. After the user logins, the page doesn't show some HTML codes written in the PHP script
Only the PHP welcome messege stating a successful login.

I need the HTML to appear along with the welcome msg.


The whole coding has three files, index.php, login.php, and page.php

the index.php file checks the user's IP, if its in the ban list, it will redirect them to login.php, otherwise, they will enter the site normally.

the login.php file has the login form and checks the login info provided, if its right, it will take them to page.php, otherwise it will states invalid login and will ask to login again.

the page.php has the successful login messege and some HTML code (my MGChat java code)

following are the code for all the files.

this is the code for index.php

<?php
$certain_ips = array('62.215','62.150','195.39','213.189','213.181','168.187','194.54','195.226');
foreach($certain_ips as $ip)
{
 if(substr($_SERVER['REMOTE_ADDR'], 0, strlen($ip)) == $ip)
 {
  header('Location:login.php');
  exit();
 }
}
header('Location:page.php');
exit();
?>



this is the code for login.php

<?php
session_start();

$your_password = "pass";

if (!empty($_POST)) {
 if ($_POST['pass'] == $your_password) {
  $_SESSION['username'] = $_POST['username'];
  header ("location: page.php");
  exit;
 }
 else {
  $notif = "Invalid password;
 }
}
?>


this is the code for page.php

<?php
session_start();
if (!isset($_SESSION['username'])) {
 //not logged in
 header("location: login.php");
 exit;
}

echo "Welcome".$_SESSION['username'];
?>

<html>
<head>
</head>
<p><b><font size="3">
Some HTML Code Here!      </font></b></p>
</body>
</html>


As I said, everything works fine, only the HTML code never shows after a successful login.

0
Question by:Souled
    2 Comments
     
    LVL 27

    Accepted Solution

    by:
    Just tested the code and it works fine. After login i see (in the source)

    WelcomeDiablo
    <html>
    <head>
    </head>
    <p><b><font size="3">
    Some HTML Code Here!      </font></b></p>
    </body>
    </html>

    and obviously "Some HTML Code Here!  " is displayed in the browser.

    You can instead try:

    <?php
    session_start();
    if (!isset($_SESSION['username'])) {
     header("location: login.php");
     exit;
    }
    else {
    echo "Welcome ".$_SESSION['username'];
    ?>

    <html>
    <head>
    </head>
    <p><b><font size="3">
    Some HTML Code Here!      </font></b></p>
    </body>
    </html>

    <?php
    }
    ?>

    Though it shouldnt make any difference
    0
     

    Author Comment

    by:Souled

    It worked after adding
    <?php
    }
    ?>

    at end of the code

    Thanks once again Diablo


    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
    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…
    The viewer will learn how to dynamically set the form action using jQuery.
    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.

    934 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

    18 Experts available now in Live!

    Get 1:1 Help Now