homepage Welcome to WebmasterWorld Guest from 23.20.63.27
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
PHP Includes and Cookies
Passing the Cookie
ILLstyle




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

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.

 

ILLstyle




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

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?

ergophobe




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

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

ILLstyle




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

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!

ergophobe




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


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?

freeflight2




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

you might pass cookies / data by setting enviroment variables before an other script

ILLstyle




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

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

ILLstyle




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

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.

freeflight2




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

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)

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved