Jump to content

question about fwrite and square bracket - beginner user


fergald

Recommended Posts

Hi,

 

please forgive me if this is a stupid question or in the wrong area.  I have a piece of code wrote in a php page similar to this

 

$filename=$_SERVER["DOCUMENT_ROOT"]."/Training/fred.php";

$fh = fopen($filename, 'w') or die("can't open file");

 

$theData="<?

unset($_SESSION\['page']);

$user = $color;

//echo \"fergal user is $color\";

if($user==\"\"){

  $receivedfoldername=$_REQUEST\[\"user\"];

  if ($receivedfoldername == \"\"){

  }else{

      $color=$receivedfoldername;

  }

}

";

 

fwrite($fh,  $theData);

fclose($fh);

 

 

 

now when i execute this its fine, then i go to my fred.php which is create with theData and if fails

i think the problem is here unset($_SESSION\['page']);

it does not like strings containing [] - is their a way to avoid this or am i doing this totally wrong.

 

Any help would be much appreciated.

 

Kind Regards

Fergal.

Link to comment
Share on other sites

You'll want to use single quotes around the data.

 

<?php

$theData = '<?
unset($_SESSION["page"]); 
$user = $color;
//echo "fergal user is $color";
if($user==""){
   $receivedfoldername=$_REQUEST["user"];
   if ($receivedfoldername == ""){
   }else{
      $color=$receivedfoldername;
   }
}
?>';

 

I'm really not sure why you would be wanting to dynamically generate php though.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.