0

i want to post a username to a PHP File. Then i want that the Username will be implemented in a PHP File which i will write in my script.

But its not working? And how do i implement the POST username in the string on $Line 5? And i want to write every line as single line, its putting all together i think. I Guess it would be easier to copy the file, and implement there the Post but i dont know how to do that.

Token Infos are not the real one ;)

$username = $_POST["username"];


//twilio tokenlines
$Line0 = "<?php";
$Line1 = "include '../Services/Twilio/Capability.php'";
$Line2 = "$accountSid = '3763876534876584'; ";
$Line3 = "$authToken  = '4765784365874365'; ";
$Line4 = "$capability = new Services_Twilio_Capability($accountSid, $authToken); ";
$Line5 = "$capability->allowClientIncoming("HERE I WANT TO STAND MY POST"); ";
$Line6 = "$capability->allowClientOutgoing('746357846358764387564387'); ";
$Line7 = "$token = $capability->generateToken(); ";
$Line8 = "echo $token;";
$Line9 = "?>";  


$tokenfile = fopen("${username}.php", 'w'); 
fwrite($tokenfile,$Line0); 
fwrite($tokenfile,$Line1); 
fwrite($tokenfile,$Line2);
fwrite($tokenfile,$Line3);
fwrite($tokenfile,$Line4);   
fwrite($tokenfile,$Line5); 
fwrite($tokenfile,$Line6); 
fwrite($tokenfile,$Line7); 
fwrite($tokenfile,$Line8);
fwrite($tokenfile,$Line9);  
3
  • What do you mean by "not working"? What happens (or does not happen)? Commented Jul 11, 2015 at 14:04
  • Its not creating the file. When i remove the post, upload it to my webspace and execute the script its not creating the file either. Commented Jul 11, 2015 at 14:19
  • syntax check gives me `PHP Syntax Check: Parse error: syntax error, unexpected '"' in your code on line 2 $Line0 = "<?php";`` How do i solve this? Commented Jul 11, 2015 at 14:20

2 Answers 2

1

You can create multiple lines just by appending \n at the end of each string.

$Line0 = "<?php\n";

Don't forget to call

fclose($tokenfile)

-- only then the contents are guaranteed to be written to disk.

Sign up to request clarification or add additional context in comments.

Comments

1

Semicolon

$Line1 = "include '../Services/Twilio/Capability.php'";

=>

$Line1 = "include '../Services/Twilio/Capability.php'; ";
                                                     ^

Escape

$Line5 = "$capability->allowClientIncoming("HERE I WANT TO STAND MY POST"); ";

=>

$Line5 = "$capability->allowClientIncoming(\"HERE I WANT TO STAND MY POST\"); ";
                                           ^                             ^ 

Add PHP_EOL to end of each line.

$Line1 = '...'.PHP_EOL;
$Line2 = '...'.PHP_EOL;
...

And also convert all " to ' because it translates $abc and we don't want it.

3 Comments

done everything but its giving me syntax error: PHP Syntax Check: Parse error: syntax error, unexpected 'include' (T_INCLUDE) in your code on line 2 $Line1 = 'include '../Services/Twilio/Capability.php';\n'.PHP_EOL;
remove \n. PHP_EOL will do the \n job for you. @mav
@mav did it help you? you can choose the answer which helped you as the best.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.