Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 25th, 2005, 11:58 AM
JSB JSB is offline
Registered User
 
Join Date: Nov 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem with using cookies

For whatever reason, at least one beyond my experience, I cannot figure out why my cookies work in test trials but when I actually try to use them in the way that I have within my application, they do not work.

First the scenario and then show some code:
(from the way I am using cookies in my application)

A Web page, and at the bottom of it there is a small form which is nothing more than a few hidden fields and single button which when pushed, will send the user to another (processing) page.

The processing page/file does some processing one of which, checks to see if the user is logged in. If the user is not logged in, a cookie is created (holding the value zero) and the user is immediately sent right back to the page with the form button. From the user's point of view, they have never left the original web page (it all happens so quickly).

However, when checking to see if the cookie exists, there never seems to be one.

**** original web page with form button:

<form action="/directory/anotherdirectory/user_addfavs_tally.php" method="post">
<input type="hidden" name="theband" value="{ARTIST_ID}" />
<input type="hidden" name="thispage" value="<?php echo $_SERVER['REQUEST_URI']; ?>" />
<td align="right">
    <table width="200" cellpadding="0" cellspacing="0" border="0">
        <tr>
            <td align="center"></td>
        </tr>
        <tr>
            <td align="center"><input type="submit" value="ADDtoFAVS" /></td>
        </tr>
        <tr>
            <td align="center"><span class="style1"><?php @include("http://www.somedoamin.com/directory/anotherdirectory/user_spot_message.php"); ?></span></td>
        </tr>
    </table>
</td>
</form>

**** from processing page/file
if($_SESSION['visitors_username'] == '' || $_SESSION['someothervar'] == '') {
    // If listener is not logged in, then do nothing but tell them they need to log in before adding favs
    $user_spot = "0"; //message id
    if ($user_spot) setcookie("thisdude", $user_spot, time()+30, "/directory/");
    $gobackto = trim($_POST['thispage']);
    header("Location: $gobackto");
    exit;
}

**** from the include that you see on the original page
$message_to_show = $_COOKIE["thisdude"];
if ($message_to_show) {
    switch ($message_to_show) {
        case "0":
            // User is not logged in. Show the following message:
            echo "You must log in before you can add an artist to your favs.";
            break;
        case "1":
            // Artist in question is already in User's top ten list
            echo "This artist is already in your favs list.";
            break;
        case "2":
            // There is no empty spot in User's top ten list
            echo "Your top ten favs list is full.";
            break;
        default:
            // default action is to show no message.
            echo "did we get through the switch?";
            break;
    }
}

******* end code

Any help would be much appreciated as I have been working on this single, cookie, problem for roughly two days...

Thanks in advance.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with cookies khb3283 ASP.NET 2.0 Basics 1 October 1st, 2008 11:11 AM
cookies problem kanoorani Servlets 0 December 22nd, 2006 10:54 AM
Cookies Problem dparsons ASP.NET 1.0 and 1.1 Professional 0 November 28th, 2006 01:47 PM
Problem with cookies :( Varg_88 Classic ASP Databases 2 December 13th, 2004 11:34 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.