php and wget

Posted on 2008-11-12
Last Modified: 2012-05-05
Hi all,

I have a small problem I hope you can all help me with.

I have two totally different websites located on different servers. Lets call them A and B.

What I want to happen is user goes to site A and fills in a forum. When hitting submit the form is processed, added to a database and also the php file processing the form calls a remote script hosted on website B and passes variables in the url to that form.

On site B the script is called and reads in the $_get parameters. It uses these parameters and processes them and posts output on a private forum.

Problem I am having is that the wget part and passing the variables to the script.

The $boturl is formed correctly as when I echoed it out as a test it comes out fine. When I go to folder the script is running from it shows a file that resulted from the wget has the filename: postdata.php?password=temppassword and thats it. So seems when wget is pulling the file at the url it only passes the password variable and nothing else after the first &

On B's side the script only runs if password is correctly passed which it is but no other variables are being passed correctly so end results are blank/empty variables.

Am I doing something wrong?
// Code from site A  --  All variables assigned values fruther above in my code (not shown here)

$boturl = "" . $files . "&size=" . $size_temp . "&name=" . $name . "&url=" . $website;

system("wget " . $boturl);

// Code from site b

$turl = isset( $_GET['url'] ) ? $_GET['url'] : '';

$password = isset( $_GET['password'] ) ? $_GET['password'] :

// etc etc

Open in new window

Question by:SerjTech
    LVL 107

    Accepted Solution

    Instead of system(wget) try CURL or simply this:

    $x = file_get_contents($boturl);

    HTH, ~Ray
    LVL 15

    Assisted Solution

    I'd prefer Ray's solution however if you must use the system() wget command, you may need to wrap the URL in single quotes because some characters are interpreted literally, such as a space.
    LVL 5

    Author Comment

    When using $x = file_get_contents($boturl); I get the following error:

    Warning: file_get_contents( MB&name=Test Filename&&url= [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request in /home/testsite/ on line 205

    Line 205 is:
    $x = file_get_contents($boturl);

    But if I run that url in the error message via my browser the page will open and run fine processing all the information.
    LVL 5

    Author Comment

    Got it working now.

    Problem was a space in the url that script didn't like getting so used str_replace to handle the space character and it worked fine first time.

    So thank you both for your answers.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    The purpose of this article is to demonstrate how we can use conditional statements using Python.
    Join Greg Farro and Ethan Banks from Packet Pushers ( and Greg Ross from Paessler ( for a discussion about smart network …
    Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now