Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

was working now not :S echo in html

Posted on 2011-03-06
6
Medium Priority
?
279 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Accepted Solution

by:
florjan earned 2000 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
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.
Suggested Courses

972 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