aminnuto Posted October 23, 2006 Share Posted October 23, 2006 I have a php file that I would like to show a different .inc file to visitors the 2nd time they visit that php page. Perhaps code that uses an inc file if no session (while also setting a session) and then if the session exists, to display a different inc file with the cookie being reset at the end of the session.Does anyone know how I would do this? Quote Link to comment https://forums.phpfreaks.com/topic/24884-help-need-code-to-make-a-cookie-to-displace-different-html-when-revisited/ Share on other sites More sharing options...
localhost Posted October 24, 2006 Share Posted October 24, 2006 you mean like...[code]<?phpsession_start();if ($_SESSION['name']){include('incfile');} else {include('otherincfile');$_SESSION['name'] = "value";}?>[/code]??? Quote Link to comment https://forums.phpfreaks.com/topic/24884-help-need-code-to-make-a-cookie-to-displace-different-html-when-revisited/#findComment-113435 Share on other sites More sharing options...
aminnuto Posted October 24, 2006 Author Share Posted October 24, 2006 doesnt work. i get this error at the top of the page.Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /home/pire/phpfile.php:7) in /home/pire/phpfile.php on line 20Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/pire/phpfile.php:7) in /home/pire/phpfile.php on line 20this is the code i used<?phpsession_start();if ($_SESSION['name']){include('inc/DISCOUNT-file.inc');} else {include('inc/file.inc');$_SESSION['name'] = "value";}?> Quote Link to comment https://forums.phpfreaks.com/topic/24884-help-need-code-to-make-a-cookie-to-displace-different-html-when-revisited/#findComment-113449 Share on other sites More sharing options...
HuggieBear Posted October 24, 2006 Share Posted October 24, 2006 I would imagine that one of the other include pages, either DISCOUNT-file.inc, or file.inc, is also trying to send headers.Look at the include files and adjust accordingly.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/24884-help-need-code-to-make-a-cookie-to-displace-different-html-when-revisited/#findComment-113510 Share on other sites More sharing options...
aminnuto Posted October 24, 2006 Author Share Posted October 24, 2006 I figured it out... its working now. thanks Quote Link to comment https://forums.phpfreaks.com/topic/24884-help-need-code-to-make-a-cookie-to-displace-different-html-when-revisited/#findComment-113578 Share on other sites More sharing options...
aminnuto Posted October 24, 2006 Author Share Posted October 24, 2006 ok, one more questions. I have a different webpage on that site where i want to check and see if this cookie is set and if it is, show one page and if its not, show another BUT i dont want it to set the cookie...only check if its there and then displace an inc file if its there.so pretty much the same cookie without setting itself. just checking if its there and showing an inc file if it is.How would I do that? Quote Link to comment https://forums.phpfreaks.com/topic/24884-help-need-code-to-make-a-cookie-to-displace-different-html-when-revisited/#findComment-113685 Share on other sites More sharing options...
HuggieBear Posted October 24, 2006 Share Posted October 24, 2006 You need to use isset().[code]<?phpif (isset($_COOKIE['cookie_name'])){ // If set do something}else { // else do something else}?>[/code]RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/24884-help-need-code-to-make-a-cookie-to-displace-different-html-when-revisited/#findComment-113693 Share on other sites More sharing options...
aminnuto Posted October 24, 2006 Author Share Posted October 24, 2006 I'm missing something. I tried your code and it didnt work. Here is my original code, [code]<?phpsession_start();if ($_SESSION['discount']){include('/home/pire/www/products/DISCOUNT.php');} else {include('/home/pire/www/products/REGULAR.php');$_SESSION['discount'] = "value";}?>[/code]that code works great...on the next page, that i want to check for that cookie, i have this[code]<?phpif (isset($_COOKIE['discount'])){include('/home/pire/www/products/DISCOUNT.php');}else {include('/home/pire/www/products/REGULAR.php');$_SESSION['discount'] = "value";}?>[/code]but that doesnt work. it only displays my REGULAR.php file weather the session is set or not. Quote Link to comment https://forums.phpfreaks.com/topic/24884-help-need-code-to-make-a-cookie-to-displace-different-html-when-revisited/#findComment-113698 Share on other sites More sharing options...
HuggieBear Posted October 25, 2006 Share Posted October 25, 2006 OK, a session and a cookie, aren't technically the same.If you mean you want to check for a session variable then use the code I've posted but with session...[code]<?phpif (isset($_SESSION['discount'])){ include('/home/pire/www/products/DISCOUNT.php');}else { include('/home/pire/www/products/REGULAR.php'); $_SESSION['discount'] = "value";}?>[/code]RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/24884-help-need-code-to-make-a-cookie-to-displace-different-html-when-revisited/#findComment-114063 Share on other sites More sharing options...
aminnuto Posted October 25, 2006 Author Share Posted October 25, 2006 Does't work. What i'm looking to do is, if someone visits one page on my site they will see a page with the regular price of a product.if they go back to that same page within the session, they see different html which will display a discounted price.This is the code i'm using.[code]<?phpsession_start();if ($_SESSION['discount']){include('/home/pire/www/products/DISCOUNT-course.php');} else {include('/home/pire/www/products/REGULAR-course.php');$_SESSION['discount'] = "value";}?>[/code]That code is working perfectly.BUT, I have a different page on my site which also has the price of that product and I want that page to do the same thing but I DONT want it to set anything (cookie or session). I want that second page to only check and see if the first page has been visited (one or twice doesn’t matter). If that visitor has been to that first page, then i want to display different htmlThis is the code i'm using[code]<?phpif (isset($_SESSION['discount'])){ include('/home/pire/www/products/REGULAR-index.php');}else { include('/home/pire/www/products/DISCOUNT-index.php'); $_SESSION['discount'] = "value";}?>[/code]This page displays the /home/pire/www/products/DISCOUNT-index.php page wheater they have been to that first page 0 times, 1 time, 2 times 10 times, doesn’t matter. the /home/pire/www/products/DISCOUNT-index.php page is always shown and I don’t want that. What code would I put on the second page to check if that visitor has been to the first page and if they have, then show them different html?By the way...Is it possible to make the first code last longer then just the session. I'd like it to be saved as a cookie and then expire after 10 visits (or if thats not possible, 10 days). Quote Link to comment https://forums.phpfreaks.com/topic/24884-help-need-code-to-make-a-cookie-to-displace-different-html-when-revisited/#findComment-114259 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.