Solved

was working now not :S echo in html

Posted on 2011-03-06
6
266 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
ID: 35045523
      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
ID: 35045817
i try that and nothing changes
0
 
LVL 4

Expert Comment

by:florjan
ID: 35046412
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 4

Accepted Solution

by:
florjan earned 500 total points
ID: 35046461
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
ID: 35047184
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
ID: 35058169
had to change it a bit but works thx
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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…

932 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

12 Experts available now in Live!

Get 1:1 Help Now