PHP & HTML


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.

SouledAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Diablo84Commented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SouledAuthor Commented:

It worked after adding
<?php
}
?>

at end of the code

Thanks once again Diablo


0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.