plz somebody help with this code . i m fed up now

<?php
$x=5;
echo $x;
session_start();
$_SESSION['y']=$x;

$string = '<?php 
session_start(); 
$x=$_SESSION['y'];
 echo $x;?> ';

$fp = fopen("6.php", "w");

fwrite($fp, $string);

fclose($fp);
?>

Recommended Answers

All 5 Replies

Try the following:

<?php
$x=5;
session_start();
echo $x;
$_SESSION['y']=$x;

$string = '<?php 
session_start(); 
$x=$_SESSION[\'y\'];
echo $x;?> ';
$fp = fopen("6.php", "w");
fwrite($fp, $string);
fclose($fp);
?>
commented: he really undrestood my problem very fast +0

thanx man :)

i have one more problem
this is my code

<?php
    
    session_start();
    
     
for($i=5;$i<=6;$i++)
{
$_SESSION['y']=$i;
 $string = '<?php
    session_start();
    $x=$_SESSION[\'y\'];
    echo $x;?> ';
    $fp = fopen("$i.php", "w");
    fwrite($fp, $string);
    fclose($fp);
}
    ?>

it is generating the output 6 in both newly created pages. but i want to print 5 on 5.php and 6 on 6.php .. how to do it ??

Do you mean like the following?

<?php
session_start();
for($i=5;$i<=6;$i++)
{
$_SESSION['y']=$i;
$string = '<?php
$x='.$_SESSION['y'].';
echo $x;?> ';
$fp = fopen("$i.php", "w");
fwrite($fp, $string);
fclose($fp);
}
?>

thanx man .. i really appreciate u

commented: Thanks for the positive comments +12
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.