Page 1 of 1

Please Help me understand cURL better

Posted: Wed Aug 24, 2011 12:06 am
by Bel
As in why doesnt it work the way i expected it to.

Using Ajax i have a index.php page displaying output from response.php page.

I have an admin section in an admin folder.
admin\index.php also using ajax to display results form admin\response.php.

I want to be able to pass 'commands' from the admin\response.php to response.php so i thought i would use cURL for the first time.
within admin\response.php

Code: Select all

        $ch = curl_init();
        curl_setopt($ch,CURLOPT_URL,'http://localhost/IPOfficeConfigurator/response.php?command=LOAD_CONFIG&data1='.$data1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $buffer = curl_exec($ch);
        curl_close($ch);
Now in response.php i have:

Code: Select all


@$command=addslashes($_GET["command"]);
@$data1=addslashes($_GET["data1"]);
switch ($command){
    case "LOAD_CONFIG":
        $_SESSION['header_display']->set_load_config($data1);
        $_SESSION['ipo']->check_capacity();
        $fil = @fopen('test.txt', w);
        @fwrite($fil, $data1."\r\n");
        @fclose($fil);
       break;
}

The thing is the write to file works. It successfully saves $data1 to file ( i only am doing that for testing) yet the object stored in the session is not carryign out the command. I find that bizaare and suspect its due to my own lack of advanced knowledge.

If i were to within admin\index.php output the curl result then yeah i can actually see the change being effected to $_SESSION['header_display']. But from index.php $_SESSION['header_display'] isnt altering.

What am i missing?

ps: i hope ive written my question out well enough to follow.

Re: Please Help me understand cURL better

Posted: Wed Aug 24, 2011 6:09 am
by phphelpme
I dont understand why you are using cURL to pass variables to a $_GET statement to change your session?

Would it not be easier to just direct the it right to the file and carry out the commands?

Or are you just playing with cURL because you are new to it?

Best wishes

Re: Please Help me understand cURL better

Posted: Wed Aug 24, 2011 7:03 pm
by Bel
Thankyou for the reply.

I was hoping to have the GET hidden and sorted before redirecting the user back to the index.php page.

I have a method that works but unreliably. (not sure why)
Using javascript within admin\index.php

Code: Select all



else if(command == "EXPORTS_LOAD"){
    window.location.href='../response.php?command=LOAD_CONFIG&data1='+data1;
    history.back();
}
seems pretty ugly to me.

Can you offer any improvements?