0

So here is what I am trying to do. I have two files: .bat and .php

run.bat:

set password = ok123
php -f data.php

data.php:

<?php
$pass = %password%;
echo '.$password.'

I need to pass the password from the bat file to the php script. What is the best way to do this?

Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
  • 1
    http://php.net/manual/en/reserved.variables.argv.php – RiggsFolly Feb 04 '17 at 22:16
  • 1
    Possible duplicate of [setting environment variables for accessing in PHP](http://stackoverflow.com/questions/10902433/setting-environment-variables-for-accessing-in-php) – José Luis Feb 04 '17 at 23:40

3 Answers3

0
set password = ok123

will set a variable "password " to " ok123".

spaces are significant on both sides of a string set statement. Lose the spaces!

Magoo
  • 77,302
  • 8
  • 62
  • 84
0

Run the PHP script like this, as you dont want to place a password in an environment variable

php data.php paswd123

data.php

<?php
if ( $argc < 2 ) {
    echo 'call this script using the password as a parameter';
    exit;
}

$password = $argv[1];

The manual http://php.net/manual/en/reserved.variables.argv.php

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
  • Thanks alot sir! , belive me i have searched for this answer but i forget to read about the above link that you have given to me . Anyway , it has worked like a charm. – Mohammed Darwish Feb 05 '17 at 08:06
0

If you want to set environment variables, like you did with set command, you can access them in PHP using $_ENV array. So in your situation password will be stored as $_ENV['password'].

Grawer
  • 121
  • 3