richever Posted April 9, 2008 Share Posted April 9, 2008 I'm new to php and to web programming, to some extent, and I'm trying to do the following. First, I am trying to set a number of values returned from a server using calls to setcookie(). From what I understand, for these cookies to be 'enabled' and be contained with $_COOKIE I need to reload the page. So, what does this exactly mean? 1) Should I reload the page I'm on (redirect to self?) or can I just load another page with in the same session? 2) If I'm correct about either of these then if I were to examine the cookies that my browser thinks it has, should I expect to see these same cookies there? What I'm trying to do now is redirect to the page on which I loaded my cookies. Below is some code but with all the cookie setting code removed. It's just the redirect I'm concerned about now because it seems to be in an infinite loop. <?php session_start(); if (!isset($_SERVER['cookies_set'])) { // set cookies here and then prepare to redirect... $_SERVER['cookies_set'] = 1; header("Location: ". $_SERVER['PHP_SELF']); die; } else { $_SERVER['cookies_set'] = NULL; unset($_SERVER['cookies_set']); } ?> <html> cookies_set: <? echo $_SERVER['cookies_set']; ?> <br> </html> Can anyone give me some help. I'd really appreciate it! Link to comment https://forums.phpfreaks.com/topic/100250-redirect-to-self-page-isnt-redirecting-properly/ Share on other sites More sharing options...
discomatt Posted April 9, 2008 Share Posted April 9, 2008 Read up on the setcookie() function. You access cookie variables with the suberglobal $_COOKIE['cookie name'] Link to comment https://forums.phpfreaks.com/topic/100250-redirect-to-self-page-isnt-redirecting-properly/#findComment-512578 Share on other sites More sharing options...
richever Posted April 9, 2008 Author Share Posted April 9, 2008 Thanks for the reply discomatt, but I'm using $_SERVER to store a value and nothing else. I am familar with setcookie() and I understand how to use it. I didn't include that code because it's not how to call this function that I don't understand, but rather what its behaviour is. I've called setcookie() and I don't see the cookies I've set being set. My second problem is trying to redirect to the same page without getting a infinite loop in the browser. Again, thanks for the reply though. Rich Link to comment https://forums.phpfreaks.com/topic/100250-redirect-to-self-page-isnt-redirecting-properly/#findComment-513110 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.