Solved

was working now not :S echo in html

Posted on 2011-03-06
6
263 Views
Last Modified: 2012-05-11
i have this div that is positioned nice on my banner
but the php echo is not echoing where the div is positioned on the page. its echoing at the very top of the page even though i put the php in the div.


here is the code:

<?php
session_start();
if(isset($_POST['submit1'])) {
logout();
}
?>

<div id="apDiv6"><!-- logout echo here-->
<?php

function logout()
{

      if ($_SESSION['u_name'])
      {
            session_destroy();
      echo "You've been logged out.";}
      else{
            echo "You where not logged in!";
            }        
}
?>
</div>

<div id="two"><!-- logout button here-->

<form action="<?=$_SERVER['PHP_SELF'];?>" method="POST">
<table width="65" border="0" cellpadding="1" cellspacing="3" class="table1">
<td width="57">
<input type="submit" name="submit1" value="Log out"></td>
</table>
</form>
</div>

#apDiv6 {/*css postitions for my echo*/
      position:absolute;
      width:458px;
      height:45px;
      z-index:4;
      left: 183px;
      top: 61px;
}
i allso have some more css for the button here to. what i show here is just a part of my code

so how come the echo is not displayed where i placed the div?
i just want my echo to be displayed in the place i want to position it at :( was working a few hours ago.
0
Comment
Question by:helpchrisplz
  • 4
  • 2
6 Comments
 
LVL 4

Expert Comment

by:florjan
Comment Utility
      if ($_SESSION['u_name'])
      {
            session_destroy();
      echo "You've been logged out.";}
      else{
            echo "You where not logged in!";
            }    

Open in new window

 if ($_SESSION['u_name']) {
	session_destroy();
	echo "You've been logged out.";}
else{
	echo "You where not logged in!";
}    

Open in new window


I have made spacing proper. I had same problem yesterday, hope it helps.
0
 
LVL 1

Author Comment

by:helpchrisplz
Comment Utility
i try that and nothing changes
0
 
LVL 4

Expert Comment

by:florjan
Comment Utility
What if you add <p> and </p>.
if ($_SESSION['u_name']) {
        session_destroy();
        echo "<p>You've been logged out.</p>";
}else{
        echo "<p>You where not logged in!</p>";
}  

Open in new window

Also I have rewrote the code and made it nicer if you're interested (you want to put echo after the logout button right?).
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 4

Accepted Solution

by:
florjan earned 500 total points
Comment Utility
Here's the rewritten code.  
<?php
session_start();
if(isset($_POST['submit1'])) {
	logout();
}

/* This function checks if $_SESSION['u_name'] is open and 
 * if it is it destroys(deletes) the session and writes 
 * something into variable $logoutmessage, otherwise
 * it writes something else into variable $logoutmessage.
 * Global indicates that $logoutmessage can also be used 
 * outside of function. */
function logout() {
	global $logoutmessage;
	if ($_SESSION['u_name']) {
		session_destroy();
		$logoutmessage = "<p>You've been logged out<p>";
	} else {
		$logoutmessage = "<p>You've been logged out<p>";
	}        
}
/* If the logoutmessage isn't set it's null */
if (!isset($logoutmessage)) {
	$logoutmessage = "";
}
/* Now we echo everything we want (EHTML marks it as html instead 
 * plain like in normal echo and also we can use both " and ')*/
echo  <<<EOHTML
<div id="two"><!-- logout button here-->
<form action="{$_SERVER['PHP_SELF']}" method="POST">
<table width="65" border="0" cellpadding="1" cellspacing="3" class="table1">
<td width="57">
<input type="submit" name="submit1" value="Log out"></td>
</div>
</table>
</form>
<div id="apDiv6"><!-- logout echo here-->
$logoutmessage
</div>
EOHTML;
?>

Open in new window

0
 
LVL 4

Expert Comment

by:florjan
Comment Utility
Ups a mistake on line 19 of code in my last post. Should be You were not logged in instead of You've been logged out
0
 
LVL 1

Author Closing Comment

by:helpchrisplz
Comment Utility
had to change it a bit but works thx
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

772 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

11 Experts available now in Live!

Get 1:1 Help Now