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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.