Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

php5 disabling or refusal of cookies.

Programming languages, Coding, Executables, Package Creation, and Scripting.
Post Reply
Message
Author
User avatar
philo_neo
Posts: 77
Joined: 2010-06-18 16:48

php5 disabling or refusal of cookies.

#1 Post by philo_neo »

hello, on one of my php programs I'm going to a page redirection and then firefox returns the following message:
The page is not redirected correctly
Firefox has detected that the server is redirecting the request for this address in a way that will not succeed.
The cause of this problem may be the disabling or refusal of cookies.
i'm trying on another browser (chromium) and then i have the same mistake!
I have removed all the coockies from my browsers in the menu: tools> preferences
when looking on the internet I found this: deleted the

Code: Select all

cookies.sqlite and cookies.sqlite-journa
l files in the folder "profiles" of firefox

I can not find the location in the tree of my hard disk file:

Code: Select all

cookies.sqlite
however, since another computer on my local network I have the same error, I do not think it comes from browser but apache2.2 bug!
someone know the problem?

here my php's code

Code: Select all

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title>Mini-chat</title>
    </head>
    <style>
    form
    {
        text-align:center;
    }
    </style>
    <body>
    
    <form action="minichat_post.php" method="post">
        <p>
        <label for="pseudo">Pseudo</label> : <input type="text" name="pseudo" id="pseudo" /><br />
        <label for="message">Message</label> :  <input type="text" name="message" id="message" /><br />

        <input type="submit" value="Envoyer" />
	</p>
    </form>

<?php
 
// Connexion à la base de données
try
{
	$bdd = new PDO('mysql:host=localhost;dbname=test;charset=utf8', 'root', '');
}
catch(Exception $e)
{
        die('Erreur : '.$e->getMessage());
}


// Récupération des 10 derniers messages
$reponse = $bdd->query('SELECT pseudo, message, DATE_FORMAT(date_message, \'%d/%m/%Y à %Hh%imin\') AS date_message_fr FROM minichat ORDER BY ID DESC LIMIT 0, 10');

// Affichage de chaque message (toutes les données sont protégées par htmlspecialchars)
while ($donnees = $reponse->fetch())
{
	echo '<p><strong>'  . htmlspecialchars($donnees['date_message_fr']).' >>  Pseudo -> '. htmlspecialchars($donnees['pseudo']) . '</strong> : ' . htmlspecialchars($donnees['message']) . '</p>';
}

$reponse->closeCursor();

?>
<?php header('Location: minichat_post.php');?>
    </body>
</html>
Regards
Philippe

User avatar
debiman
Posts: 3063
Joined: 2013-03-12 07:18

Re: php5 disabling or refusal of cookies.

#2 Post by debiman »

philo_neo wrote:hello, on one of my php programs I'm going to a page redirection and then firefox returns the following message:
The page is not redirected correctly
Firefox has detected that the server is redirecting the request for this address in a way that will not succeed.
The cause of this problem may be the disabling or refusal of cookies.
i'm trying on another browser (chromium) and then i have the same mistake!
i'm sometimes seeing this error when i access a bloated multi-cross-scripting site with my addons set to full protection (noscript, requestpolicy).
clearly the site expects me to allow all sorts of scripts and does not have a safe fallback.
keyword: graceful degradation.

never seen it on my own webpages though.
makes me wonder what exactly you have been coding there (or copy-pasting).

User avatar
philo_neo
Posts: 77
Joined: 2010-06-18 16:48

Re: php5 disabling or refusal of cookies.

#3 Post by philo_neo »

I coded a chat , I'm redirecting to a page that should not be displayed, and from this page I redirect to the end of the php script to minichat.php

you did not understand my problem because my code works, but since I introduced the coockies, I have problems on my redirects.

i have coded my coockies like this :

Code: Select all

<?php   setcookie('pseudo', $_POST['pseudo'], time() + 365*24*3600, null, null, false, true);?>
-----------------------------------------------------------------------------------------------------------------------------------------------------------
é ! Je me souviens de toi !<br />
    Tu t'appelles <?php echo $_COOKIE['pseudo']; ?> 
    setcookie('pseudo', 'pseudo', time() + 365*24*3600, null, null, false, true);
    
    


TonyT
Posts: 575
Joined: 2006-09-04 11:57

Re: php5 disabling or refusal of cookies.

#4 Post by TonyT »

I don't understand that this should work:
<?php header('Location: minichat_post.php');?>
because headers have already been sent earlier.
Setting a cookie sends headers.

Try using a meta refresh:
<meta http-equiv="refresh" content="0;url=./minichat_post.php">

Or better yet, use php sessions and read the session cookie to create vars.

Post Reply