Good Day Everyone,
I am currently having some difficulty setting my environment variables, I am currently using a mac as well.So, I am not a PHP user so I do not know much about the language. However, I have a few variables that I stored in my bashrc file.
I would like to retrieve them, and use it as part of my current project workflow (GIT Token).
I have a few variables stored, but it will not return any value... I am really not sure what is wrong. Please do assist me..
nano ~/.bashrc
export GITHUB_TOKEN= ghp_123456
export testVal = Testing
However when I call nothing happens
echo $testval
And when downloading a private repo it shows this error..
curl -sSfL -H "Authorization: token ${GITHUB_TOKEN?not set}" -H 'Accept: application/rnd.github.v2.raw' "https://eg.git" | sh -s --
bash: GITHUB_TOKEN: not set
Remove the spaces between the equals sign, like this:
export GITHUB_TOKEN=ghp_123456
export testVal=Testing
When writing var = value you're asking the shell to open program var with = and value as arguments.
Related
I am trying to work with an OpenAI library (https://github.com/orhanerday/open-ai) that uses environment variables for key storage, but it doesn't seem to be finding the key when I run it.
On my local Windows machine I ran the following command: setx OPENAI_API_KEY “mykey”
On the Linux web server I ran the following command: export OPENAI_API_KEY=mykey
Now on the server when I run the following, I see the correct key value printed back to me: printenv OPENAI_API_KEY
In my script I'm using $open_ai_key = getenv('OPENAI_API_KEY'); but I'm getting no value back..??
Any information on how I can resolve this would be greatly appreciated. Thanks!
Thank you for using orhanerday/OpenAI PHP SDK,
Let's try to set your ‘OPENAI_API_KEY’ Environment Variable through the Control Panel
Open System properties and select Advanced system settings
Select Environment Variables...
Select New… from the User variables section(top). Add your name/key-value pair, replacing with your API key.
Variable name: OPENAI_API_KEY
Variable value: <yourkey>
Sign out and then log in to your PC.
Create a PHP file;
<?php
$open_ai_key = getenv("OPENAI_API_KEY");
print("OPENAI_API_KEY is; $open_ai_key");
run the PHP file
$ php index.php
> OPENAI_API_KEY is: sk-gjtv.....
After running the app you should get the value.
I'm developing a code which uses ldap_search Shell Script Command for extracting user information from Active Directory using user id and by proper LDAP Server Authentication. I am getting accurate result from ldap_search script.
But, whenever I put the shell script inside exec or shell_exec PHP command, I'm not getting anything.
All the other shell scripts are working fine with the help of PHP exec command except ldap_search.
Is there some additional task left for me to do?
Is ldap_search and exec/shell_exec not compatible with each other?
You must use echo exec('your command or script');
Make sure to have permissions to run it. I mean, the web user must have permissions to execute that.
May seem obvious, but I think your failure is in something basic like this. You must put echo to show the result of the command.
EDIT After reading your new comments about it and using that new info... I saw you are trying to redirect the output to a file... but maybe you have 2 different problems.
Have the user which is executing php (usually www-data) permission to write on the folder where the php is?
Your code has quotes inside quotes that must be escaped using . Try this:
<?php exec("ldapsearch -x -v -h 'LDAP://server' -p '389' -D 'uid=\"domain_user_id\",ou=users,ou=internal,o=\"organization\"' -w 'domain_password' -b 'ou=users,ou=internal,o=organization' 'uid=person's_user_id' >> result.txt"); ?>
So you don't need echo if you want the output in a file. And the redirection >> can be inside the command executed, not in php.
Remember that > replaces de file and what you have >> add at the end of the file.
I want to use wkhtmltopdf to convert a web page to a PDF file. I have a test with a static template and this syntax works perfectly:
wkhtmltopdf my.html my.pdf
The problem is the actual page is a dynamic PHP page with tables that rely on three HTML GET variables.
An example would be:
http://mypage.php?clientid=SJC&datestart=201201&dateend=201202
I can't do this directly like so:
wkhtmltopdf mypage.php?clientid=SJC&datestart=201201&dateend=201202 my.pdf
Someone suggested I needed to call the PHP from the command line with the variables first to get the HTML source code for that set of variables, and convert it using wkhtmltopdf.
How do I do this? What is the process using the above URL as an example?
The cleanest way would be using $_SERVER['argv'] instead of the GET variables.
However, if you HAVE to use the GET variables, you can set them in a custom script:
$_REQUEST['var1'] = $_SERVER['argv'][0];
and then require() the PHP script itself.
Another way would be to set the environment variables QUERY_STRING and REQUEST_METHOD:
export REQUEST_METHOD=GET
exprt QUERY_STRING='var1=blub&var2=blah'
In Linux you can use the wget command to get a result HTML file from an URL:
wget "http://localhost/mypage.php?clientid=SJC&datestart=201201&dateend=201202"
Or
wget -O myfile.html "http://localhost/mypage.php?clientid=SJC&datestart=201201&dateend=201202"
to output the result to specific file, for example, myfile.html
Note:
wget wget -O myfile.html "http://localhost/mypage.php?clientid=SJC&datestart=201201&dateend=201202"
Double quote seems to solve the ampersand encoding problem.
A WordPress site of a client was recently hacked due to a theme vulnerability and I am now in the process of cleaning up and fortifying. I found guncompress(base64_decoded code. When I decoded it I had more base64 in an array:
$GLOBALS['_1780441916_']=Array(base64_decode('' .'ZXJ' .'yb3Jfc' .'mVwb3J' .'0a' .'W5'.'n'),base64_decode('Y3VybF9pb' .'ml0'),base64_decode('c
How can I decode base64 in an array on my localhost?
Try to using evalhook.so.
You need:
PHP >= 5.2
php5-devel
PHP Zend Optimizer
download source from http://php-security.org/downloads/evalhook-0.1.tar.gz
then unpack and install it
tar xvfz evalhook-0.1.tar.gz
cd evalhook
phpize
./configure
make
sudo make install
and you can use it from console.
php -d extension=evalhook.so encoded_script.php
where encoded_script.php is your encoded script.
every time it ask you
Do you want to allow execution? [y/N]
Type Y if your code after execution have some "base64_decode" in it.
Then when you get something like that
$GLOBALS['_889997777_'] = Array(
...
$GLOBALS['_224568216_'][21]('Xr' . 'x8f7g=')
);
Just run after that var_export($GLOBALS['_889997777_']);die; and you get all functions name, than you can replace it. Here is link that can automate it http://pastebin.com/kBj4iqWh
I am using PHP on Windows machin. I also use Dev C++. I can perfectly compile .cpp file on CMD using this command:
g++ hello.cpp -O3 -o hello.exe
Now what I am trying to do is running the same command using php system() function, so it looks like this:
system("g++ c:\wamp\www\grader\hello.cpp -O3 -o C:\wamp\www\grader\hello.exe");
but it doesn't compile. I am lost, please tell me what am I missing?
I also looked up at this question and thats exactly what I need, but I couldnt find a usefull solution for my case there:
Php script to compile c++ file and run the executable file with input file
Use the PHP exec command.
echo exec('g++ hello.cpp -O3 -o hello.exe');
should work.
There's a whole family of different exec & system commands in PHP, see here:
http://www.php.net/manual/en/ref.exec.php
If you want the output into a variable, then use :
$variable = exec('g++ hello.cpp -O3 -o hello.exe');
If that doesn't work, then make sure that g++ is available in your path, and that your logged in with sufficient enough privliges to allow it to execute.
You may find also that it's failing beacuse PHP is essentially being executed by your web server (Unless your also running PHP from the cmd prompt) , and the web server user ID may not have write access to the folder where G++ is trying to create the output file.
Temporarily granting write access to 'Everybody' on the output folder will verify if that is the case.
Two things:
You are using double quotes and are not escaping the \ inside the path.
You are not using a full path to g++.
The first one is important as \ followed by something has a special meaning in such a string (you might know \n as new line), the second one is relevant since the PHP environment might have a different search path.
A solution might be
system("c:\\path\\to\\g++ c:\\wamp\\www\\grader\\hello.cpp -O3 -o C:\\wamp\\www\\grader\\hello.exe");
Alternatively you can use single quotes, intead of double quotes, they use diffeent,less strict escaping rules
system('c:\path\to\g++ c:\wamp\www\grader\hello.cpp -O3 -o C:\wamp\www\grader\hello.exe');
or use / instead of \, which is supported by windows, too.
system("c:/path/to/g++ c:/wamp/www/grader/hello.cpp -O3 -o C:/wamp/www/grader/hello.exe");
What you do is your choice, while many might consider the first one as ugly, and the last one as bad style on Windows ;-)
Thanks to everyone. I tried to run the codes given in above posts and it worked like a charm.
I ran the following code using my browser
$var = exec("g++ C:/wamp/www/cpp/hello.cpp -O3 -o C:/wamp/www/cpp/hello.exe");
echo $var;
The exe file is created. I am able to see the result when i run the exe file but the problem is when i run the above code in the browser, the result is not displayed on the webpage. I gave full access permission to all users but still give does not show the result on the webpage.
I really need help on this since i am doing a project on simulated annealing where i want to get the result from compiled c++ program and display it in the webpage with some jquery highcharts.
Thanks again to all, it has helped me alot and i have learnt alot as well.