0

I can't get my required result when i use this code

<?php 
session_start(); 
$returnMessage = "Hey"; 
$test = fopen('check.txt', a+);
fwrite($test, '
   if (empty($_SESSION["nabeel"])) {
     echo "<script>alert($returnMessage)</script>";
   };
    ?>    ')

I also tried doing this but does work...

<?php 
session_start(); 
$returnMessage = "Hey"; 
?>
$test = fopen('check.txt', a+);
fwrite($test, '
   if (empty($_SESSION["nabeel"])) {
     echo "<script>alert(<?php $returnMessage ?>)</script>";
   }
    ?>    ')

I think I have some problem with quotes.

  • What's the required result? What result are you getting? – Gavin Mar 31 '17 at 20:38
  • 1
    Do you realise that `$test = ` and `fwrite` are not within PHP tags so are just being output to the browser? Perhaps you should read a few PHP tutorials before trying to actually use a language you don't yet know. You also need to use `;` at the end of each PHP statement. – Martin Mar 31 '17 at 20:38

1 Answers1

0

use this:

<?php 
session_start(); 
$returnMessage = "Hey";
$test = fopen('check.txt', a+);
if (empty($_SESSION["nabeel"]))
    fwrite($test,'<script>alert('. $returnMessage .');</script>');
?>
Thorny84
  • 325
  • 3
  • 22
  • BUT this won't make it alert??? – cleo master Mar 31 '17 at 20:59
  • @CLEO MASTER i have update.try... – Thorny84 Mar 31 '17 at 21:02
  • ok can i ask you a simple question. How can i use a php string variable in the fwrite area and add that variable in the alert box. How would i do that please give me a code. Thanks by the way!! – cleo master Mar 31 '17 at 21:16
  • I did not understand your question.if you want to use a php variable in a script javascript see:http://stackoverflow.com/questions/4287357/access-php-variable-in-javascript. Or use an – Thorny84 Mar 31 '17 at 21:24