Session variables

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Henaro
Forum Newbie
Posts: 4
Joined: Sun Nov 12, 2006 5:01 pm

Session variables

Post by Henaro »

Hello all~

I am having some trouble with session variables. You see, I have a session that tracks the user name of a person on my site.

Code: Select all

<?php
session_start();
global 1, Henaro;
session_register("logged");
session_register("usen");
if(!isset(1) || 1 == FALSE){
echo "Log in or <span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span> yourself.";
exit;
}
?>
Well when a person creates a new topic I want to have it written like this:

Code: Select all

fwrite($fi, "
<?php
session_start();
global $logged, $usen;
session_register(\"logged\");
session_register(\"usen\");
if(!isset($logged) || $logged == FALSE){
echo \"Log in or <span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span> yourself.\";
exit;
}
?>
<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\">
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />
<title>BBS</title>
<script language=\"JavaScript\" type=\"text/JavaScript\">
function sendText(e, text)
{
  e.value+=text
}
</script> 
</head>
<LINK REL=stylesheet HREF=\"../../style.css\" TYPE=\"text/css\">
<body>
<?PHP include(\"../../ban.php\"); ?>
<div id=\"header\"><center>CommaBunny</center></div>
<div id=\"right\"><?PHP include('../../right.txt'); ?><br />
<Br /></div>
<div id=\"left\">Navigation<hr id=\"nav\"/><a href=\"../../index2.php\">Home</a><br /><a href=\"../../bbs.php\">BBS</a><Br /><a href=\"../../media.php\">Media</a><br /><a href=\"../../about.php\">About Us</a></div>
<div id=\"center\">

<center><table class=\"alttable\">
<tr bordercolor=\"#000000\" class=\"anothertable\">
  <td width=\"600\" height=\"53\"><center>
		<i>"$title"</i>
  </center></td>
</tr>
</table></center>
<br />
<p align=\"center\">
<?PHP
include(\"http://commabunny.com/admin/an.txt\");
?>
<br>
<?PHP
include(\"../show_post.php\");
?>
</p>
<br />
<form action=\"post_reply.php\" method=\"post\" name=\"lolform\">
		<p>
  <input type=\"text\" name=\"title\" value=\"Title\" size=\"60\" class=\"form\"/>
  <input type=\"checkbox\" name=\"checkbox3\" value=\"1\" checked=\"checked\">
  <br />
  <input type=\"text\" name=\"sauce\" value=\"Sauce\" size=\"60\" class=\"form\"/>
		  <input type=\"checkbox\" name=\"checkbox1\" value=\"1\" checked=\"checked\">
		  <br />
		  |<a name=\"reply2\"><font color=\"#ffffff\">>></font></a><a href='#reply2' onClick=\"sendText(document.form.posting, '')\">[b]</a><a href='#reply2' onClick=\"sendText(document.form.posting, '')\">[i]</a><a href='#reply2' onClick=\"sendText(document.form.posting, '[ascii][/ascii]')\">[ascii]</a>|<a href=\"http://commabunny.com/BBSHELP.php\">[Help]</a>|<br />		  
      <textarea name=\"posting\" rows=\"10\" cols=\"100\" class=\"bunny\" id=\"posting\">Your post.</textarea>
      <br /> 
    <input type=\"submit\" name=\"Submit\" value=\"Submit\" class=\"altButton\" vspace=\"\"/><input type\"reset\" class=\"altButton\" />
  </form> <br></div>
<div id=\"footer\"><center>Created by <a href=\"mailto:assbone@gmail.com\">Henaro</a>.</center></div>
</body>
</html>
");
Where

Code: Select all

$username = $usen;
The problem is pretty obvious:

Code: Select all

<?php
session_start();
global $logged, $usen;
session_register(\"logged\");
session_register(\"usen\");
if(!isset($logged) || $logged == FALSE){
echo \"Log in or <span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span> yourself.\";
exit;
}
?>
gets written as:

Code: Select all

<?
session_start();
global 1, Henaro;
session_register("logged");
session_register("usen");
if(!isset(1) || 1 == FALSE){
echo "Log in or <span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span> yourself.";
exit;
}
?>

Anyone know a way around this? :/

Thanks,
Henaro

PS- I tried to make this as short as possible.
User avatar
kaszu
Forum Regular
Posts: 749
Joined: Wed Jul 19, 2006 7:29 am

Post by kaszu »

So you want to write php and html into file as i understand, then instead of " (double quotes) try using ' (single)
fwrite($fi, " becomes fwrite($fi, '
and
"); becomes ');
and you then don't have to use slashes before ", but before '

Then php variables wont be evaluated (is that correct word?) in that string.

What's the purpose of writing this into a file, I'm just curious?
Henaro
Forum Newbie
Posts: 4
Joined: Sun Nov 12, 2006 5:01 pm

Post by Henaro »

Aha! It works. Thanks a lot.

And it's purpose is to create a new topic on a small BBS I am making. :D
Post Reply