Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

PHP & HTML

Posted on 2004-10-31
2
Medium Priority
?
358 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
Comment
Question by:Souled
[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
2 Comments
 
LVL 27

Accepted Solution

by:
Diablo84 earned 1000 total points
ID: 12459298
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
ID: 12459398

It worked after adding
<?php
}
?>

at end of the code

Thanks once again Diablo


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

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…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
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…
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.
Suggested Courses

610 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