Solved

was working now not :S echo in html

Posted on 2011-03-06
6
276 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
[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
  • 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
Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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 …
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

630 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