Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SetCookie - Client and Server

Status
Not open for further replies.

Shal2

Programmer
Dec 3, 2001
52
NZ
Hello,
>
> The cookie from the file below seems to work fine if all of our code
> files are on a one machine. But if it is moved to the server and the
> webpage is accessed from a client machine, the cookie is not being
> set.
>
> Below is the code, could anyone please give some more information about Cookie behaviour,
> as it is very confusing for us (still learning PHP).
>
> The variable $i is declared as a global variable, as this file gets
> the value for $i from another php file, which passes the value through
> query string.
>
> We need this cookie value in another application.
>
> Thank you,
> Shal
>
> <?php
> // Connection String
> define('DB_NAME','sample');
> @ $dbc = mysql_connect(&quot;localhost&quot;, &quot;myname&quot;, &quot;mypassword&quot;);
> mysql_select_db(DB_NAME);
> import_request_variables('gpc', 'r_'); $i = &$r_idsearch;
> error_reporting(E_ERROR) ;
> setcookie(&quot;testcookie&quot;, $i, time()+3600); echo $_COOKIE[&quot;testcookie&quot;];
> include 'css1.html'; echo '<p align=&quot;center&quot;><b><u><font size=&quot;2&quot;
> color=&quot;blue&quot;> Click on the form to open</font></u></b></p>'; echo
> '<b><a href=&quot;C:\Inetpub\ Forms -
> report</a></b><br> <b><a
> href=&quot;C:\Inetpub\ Form -
> Report</a><b><br />'; ?>
 
Cookies don't actually set until the page is reloaded or you move to another page. Try moving your test stuff to another page or using some JS to force a reload after the cookie is set

Bastien

Any one have a techie job in Toronto, I need to work...being laid off sucks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top