Jump to content

cant get this cookie to work properly


seany123

Recommended Posts

why aint this working??

 

<?php
                                if ($_COOKIE['watch_id']){
                                    $cookie = $_COOKIE['watch_id'];
                                    $cookie_query = mysql_query("SELECT * FROM user WHERE cookie='$cookie'");
                                    if (mysql_num_rows($cookie_query) >= 1){
                                    ?>
                                    <li><a href="/index.php">Home</a></li>
                                    <li><a href="/cpanel.php">C-Panel</a></li>
                                    <li><a href="/logout.php">Logout</a></li>
                                    pass
                                    <?php   
                                    }
                                    if (mysql_num_rows($cookie_query) <= 1){
                                    ?>
                                    <li><a href="register.php">Register</a></li>
                                    <li><a href="#" onclick="OPEN_login();">Login</a></li>
                                    <li><a href="index.php">Home</a></li>
                                   fail1
                                    <?php
                                    }
                                }
                                
                                if(!$_COOKIE['watch_id']){
                                ?>
                                <li><a href="register.php">Register</a></li>
                                <li><a href="#" onclick="OPEN_login();">Login</a></li>
                                <li><a href="/index.php">Home</a></li>
                                fail2
                                <?php
                                }
                                ?>

 

i have checked in the browser and the cookies match but it always echos fail2 which means that this line is returning false:

 

if ($_COOKIE['watch_id']){

 

i have tried using isset but that didnt help either!

 

any help?

Link to comment
https://forums.phpfreaks.com/topic/250807-cant-get-this-cookie-to-work-properly/
Share on other sites

Either the cookie isn't set properly and/or PHP isn't being given the cookie by the web server.

 

Since I don't see print_r($_COOKIE); anywhere, I'm going to assume you haven't actually checked if it exists.

 

If it does exist, ensure the value is what you'd expect.

 

If it doesn't, there's an issue with your cookie or your web server. Verify that your client is actually sending the cookie along with the request.

it doesnt show what im expecting however when i look in the chrome cookie manager my website is listed twice

 

as domain.com and www.domain.com

 

and its the domain.com cookies that are echoing.

 

how can i set my cookie to domain.com instead of www.domain.com

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.