Welcome to WebmasterWorld Guest from 54.162.157.249

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

PHP Includes and Cookies

Passing the Cookie

     
5:03 pm on Nov 11, 2004 (gmt 0)

10+ Year Member



I wrote a short PHP script that uses

include('program.cgi');

The problem I have is that the CGI program the include calls requires a cookie to display certain info.
Does any one know a way to pass the cookie so the CGI can use it. The cookie that is needed is created by
a shopping cart and not PHP.

9:32 pm on Nov 11, 2004 (gmt 0)

10+ Year Member



Using header() works
like this

header('Set-Cookie: $_COOKIE["the_cookie"]');
header("Location: [the_path_to_page.cgi");...]

but I really want to do this with include().
Is there a way?

4:55 pm on Nov 12, 2004 (gmt 0)

WebmasterWorld Administrator ergophobe is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



You can't set a cookie and then use it in the same script - you need a seperate http request for both of those action.

You need to send the data from the previous page and save it as a cookie or send it as post data or some such thing. Only then is it available to the page currently being generated.

Tom

5:09 pm on Nov 12, 2004 (gmt 0)

10+ Year Member



I can grab the cookie and echo it with the
global $_COOKIE["the_cookie"]. So I have no problems
seting it but, sending it is where Im having trouble.

I know why it won't work: It is because the CGI is seeing PHP modual as the client and not the user.

thanks for the input!

6:12 pm on Nov 12, 2004 (gmt 0)

WebmasterWorld Administrator ergophobe is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month




I can grab the cookie and echo it with the
global $_COOKIE["the_cookie"].

Okay, I misunderstood a bit what you were doing. I thought you were setting the cookie in the same script that was calling the CGI.


seeing PHP modual as the client and not the user.

? You mean it's seeing PHP as the server and not the client?

6:29 pm on Nov 12, 2004 (gmt 0)

10+ Year Member



you might pass cookies / data by setting enviroment variables before an other script
6:39 pm on Nov 12, 2004 (gmt 0)

10+ Year Member



Yes, What I should have said is the include() calls a CGI script that needs a cookie.

The problem is when that CGI is requested it sees the PHP sever as the client and not the acctual client.

I have tried seting variables before include but this still will not work.
I also tried something like this include($_COOKIE['name'] . "/path/prog.cgi"); but this does not work.

thanks for your help

6:44 pm on Nov 12, 2004 (gmt 0)

10+ Year Member



the cookie has already been set long before I use this PHP script. In this script I have no problem echoing it or setting it to a variable. I just can't seem to get it passed when using the include. Im not even sure if you can do this but I hope you can.
6:48 pm on Nov 12, 2004 (gmt 0)

10+ Year Member



this:
include($_COOKIE['name'] . "/path/prog.cgi");
wouldn't make sense... let's say your cookie name is sessionID then you would try to include
sessionID/path/prog.cgi (in addition there might be potential security issues)
 

Featured Threads

Hot Threads This Week

Hot Threads This Month