TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   [help] Cookies douesnt register why why !!!!! (http://www.talkphp.com/absolute-beginners/1836-help-cookies-douesnt-register-why-why.html)

webtuto 01-01-2008 01:55 PM

[Solved] Cookies douesnt register why why !!!!!
 
hi

MY SCRIPT STAND ON THIS
FOR NOW I DONT CARE ABOUT SECURITY THATS WILL COME LATER
here is another problem that i had in my news script

here is the code --->

PHP Code:

<?php
if (!empty($_POST[name]) and !empty($_POST[pass]) ) {
include(
"config.php") ;
$result mysql_query("select * from members") ;
while (
$row mysql_fetch_array($result) ) {
$id $row[id] ;
}
$query "select user from members where pass='$_POST[pass]'";
$res mysql_query($query) ;
$count mysql_num_rows($res) ;
if (
$count == ) {
 if (!isset(
$_COOKIE[user]) and !isset($_COOKIE[pass]) ) {
   
$timestamp_expire time() + 365*24*3600// Le cookie expirera dans un an
setcookie('user', ($_POST['name']), $timestamp_expire); // On écrit un cookie
setcookie('pass', ($_POST['pass']), $timestamp_expire); // On écrit un autre cookie...
setcookie('id'$id $timestamp_expire); // On écrit un autre cookie...
echo"<meta http-equiv='refresh' content='0;url=user_p.php' ";  
 }else{ echo
"<meta http-equiv='refresh' content='0;url=user_p.php' ";   }
}else{ echo 
"the nickname or password are false try again" ; }
}else{ echo 
"would you please full the forms" ; }
?>

but the cookie douesnt register and it gaves this error --->
PHP Code:

WarningCannot modify header information headers already sent by (output started at C:\wamp\www\news\log2.php:1in C:\wamp\www\news\log2.php on line 10

Warning
Cannot modify header information headers already sent by (output started at C:\wamp\www\news\log2.php:1in C:\wamp\www\news\log2.php on line 11 

*!* so whats the problem !!

Alan @ CIT 01-01-2008 02:13 PM

Hi,

This message means that your script has already output something before the cookie information is sent.

Often this is caused by a notice/warning that PHP is sending. Try putting:

PHP Code:

error_reporting(E_ALL); 

as the very first line of your script and see if PHP then shows the errors.

Also, check that config.php isn't sending any output (even a blank space/line) and make sure that "display_errors" is set to true in your php.ini (if you have access to it)

Alan

webtuto 01-01-2008 02:19 PM

Quote:

Originally Posted by Alan @ CIT (Post 7441)
Hi,

This message means that your script has already output something before the cookie information is sent.

Often this is caused by a notice/warning that PHP is sending. Try putting:

PHP Code:

error_reporting(E_ALL); 

as the very first line of your script and see if PHP then shows the errors.

Also, check that config.php isn't sending any output (even a blank space/line) and make sure that "display_errors" is set to true in your php.ini (if you have access to it)

Alan

here is the error when i added error_reporting(E_ALL)

PHP Code:

Notice: Use of undefined constant id assumed 'id' in C:\wamp\www\news\log2.php on line 7

Notice
: Use of undefined constant user assumed 'user' in C:\wamp\www\news\log2.php on line 13

Notice
: Use of undefined constant pass assumed 'pass' in C:\wamp\www\news\log2.php on line 13

Warning
Cannot modify header information headers already sent by (output started at C:\wamp\www\news\log2.php:1in C:\wamp\www\news\log2.php on line 15

Warning
Cannot modify header information headers already sent by (output started at C:\wamp\www\news\log2.php:1in C:\wamp\www\news\log2.php on line 16

Warning
Cannot modify header information headers already sent by (output started at C:\wamp\www\news\log2.php:1in C:\wamp\www\news\log2.php on line 17 

and i think the config.php is fine

Kalle 01-02-2008 11:08 AM

You can fix the constant notices by altering the $_POST references to $_POST['user'], $_POST['pass'] and so on.

The cannot modify header information is caused that you printed something out before sending an HTTP header. This can be fixed by either removing all output being printed above that code. (Tip from experince i sometimes came to add an extra space or newline after my ending ?> which caused these warnings). Or you can use output buffering functions to fix this.

To fix this using output buffering, then add ob_start() to the very start of you script, and ob_end_flush() to the very end and it should work alright.

Hope this helps,
Kalle

webtuto 01-02-2008 11:17 AM

PHP Code:

<?php
ob_start
()
if (!empty(
$_POST[name]) and !empty($_POST[pass]) ) {
error_reporting(E_ALL);  
include(
"config.php") ;
$result mysql_query("select * from members") ;
while (
$row mysql_fetch_array($result) ) {
$id $row[id] ;
}
$query "select user from members where pass='$_POST[pass]'";
$res mysql_query($query) ;
$count mysql_num_rows($res) ;
if (
$count == ) {
 if (!isset(
$_COOKIE[user]) and !isset($_COOKIE[pass]) ) {
   
$timestamp_expire time() + 365*24*3600// Le cookie expirera dans un an
setcookie('user', ($_POST['name']), $timestamp_expire); // On écrit un cookie
setcookie('pass', ($_POST['pass']), $timestamp_expire); // On écrit un autre cookie...
setcookie('id'$id $timestamp_expire); // On écrit un autre cookie...
echo"<meta http-equiv='refresh' content='0;url=user_p.php' ";  
 }else{ echo
"<meta http-equiv='refresh' content='0;url=user_p.php' ";   }
}else{ echo 
"the nickname or password are false try again" ; }
}else{ echo 
"would you please full the forms" ; }
ob_end_flush()
?>

the script become like that right
but it gaves error
PHP Code:

Parse errorsyntax errorunexpected T_IF in C:\wamp\www\news\log2.php on line 3 


Kalle 01-02-2008 11:19 AM

You forgot the ending ; after ob_start() and ob_end_flush() function calls =)

ob_start();
ob_end_flush();

Sorry that I wasn't very clear with that, Just thought you added them yourself =P

xenon 01-02-2008 11:19 AM

You don't have a column after ob_start, and neither do you after ob_end_flush. Correct that and it should work fine.

webtuto 01-02-2008 11:23 AM

Quote:

Originally Posted by xenon (Post 7488)
You don't have a column after ob_start, and neither do you after ob_end_flush. Correct that and it should work fine.

when i add a column like that =>
ob_start(members) ;

it gaves this error

PHP Code:

WarningWrong parameter count for ob_end_flush() in C:\wamp\www\news\log2.php on line 22 


webtuto 01-02-2008 11:26 AM

Quote:

Originally Posted by Kalle (Post 7487)
You forgot the ending ; after ob_start() and ob_end_flush() function calls =)

ob_start();
ob_end_flush();

Sorry that I wasn't very clear with that, Just thought you added them yourself =P

lol sorry i was so happy that it can be the solution so i was in rush i didnt think lol sorry again
but anyway it didnt work here is the script online =>


username = aze password = aze

Kalle 01-02-2008 11:35 AM

Quote:

Originally Posted by webtuto (Post 7489)
when i add a column like that =>
ob_start(members) ;

it gaves this error

PHP Code:

WarningWrong parameter count for ob_end_flush() in C:\wamp\www\news\log2.php on line 22 


Are you calling ob_start() with a parameter now? Because you shouldn't unless you use an output handler. And you're error is very odd as ob_end_flush() doesn't take any parameters.

webtuto 01-02-2008 11:37 AM

i didnt gave it any parameter in the first time
just xenon who told me that :d

webtuto 01-02-2008 11:38 AM

try this please to see the error

http://81.192.223.238/news/login.php

webtuto 01-03-2008 11:45 PM

up
up
up!!

ReSpawN 01-03-2008 11:59 PM

don't be inpatient...
don't be inpatient...
don't be inpatient!!

First off, your page does NOT open, so I can't help you on that side.

Try this one, and first off, you need to improve your scriptskill because it's a damn mess. Sorry, but at first it was like finding a needle in a haystack ... and no, in_array didn't work. :-P

PHP Code:

<?php
    
    ob_start
();
    
    include(
"config.php") ;
    
error_reporting(E_ALL);  
    
    if ((!empty(
$_POST[name])) && (!empty($_POST[pass]))) {
    
        
$result mysql_query("SELECT * FROM `members`") ;
        
            while (
$row mysql_fetch_array($result)) {
                
$id $row[id] ;
            }
            
        
$query 'SELECT user FROM members WHERE pass = "'.$_POST[pass].'"';
        
$res mysql_query($query) ;
        
$count mysql_num_rows($res) ;
        if (
$count == 1) {
             if ((!isset(
$_COOKIE[user])) && (!isset($_COOKIE[pass]))) {
                   
$timestamp_expire time() + 365*24*3600;
                
setcookie('user'$_POST['name'], $timestamp_expire);
                
setcookie('pass'$_POST['pass'], $timestamp_expire);
                
setcookie('id'$id $timestamp_expire);
                
                echo 
'<meta http-equiv="refresh" content="0;url=user_p.php"';  
             } else {
                echo 
'<meta http-equiv="refresh" content="0;url=user_p.php"';
            }
        } else {
            echo 
"the nickname or password are false try again"
        }
    } else { 
        echo 
"would you please full the forms";
    }
    
    
ob_end_flush();
    
?>


webtuto 01-04-2008 12:11 AM

respawn about the link it wont work bcz i put wamp offline now
about the mess lol , im a begginer , u have any good suggesions about order
and that code that u gave me
it didnt work

webtuto 01-04-2008 12:12 AM

and im patient lol

Salathe 01-04-2008 12:21 AM

Quote:

Originally Posted by webtuto (Post 7586)
and that code that u gave me
it didnt work

Please, if code does not work for you, give everyone some details. At the very least, copy and paste any error message(s). We can't help if all you give us is "it didnt work". :-P

webtuto 01-04-2008 12:25 AM

here is the errors =>

PHP Code:

Notice: Use of undefined constant name assumed 'name' in C:\wamp\www\news\log2.php on line 8

Notice
: Use of undefined constant pass assumed 'pass' in C:\wamp\www\news\log2.php on line 8

Notice
: Use of undefined constant id assumed 'id' in C:\wamp\www\news\log2.php on line 13

Notice
: Use of undefined constant id assumed 'id' in C:\wamp\www\news\log2.php on line 13

Notice
: Use of undefined constant id assumed 'id' in C:\wamp\www\news\log2.php on line 13

Notice
: Use of undefined constant pass assumed 'pass' in C:\wamp\www\news\log2.php on line 16

Notice
: Use of undefined constant user assumed 'user' in C:\wamp\www\news\log2.php on line 20

Notice
: Use of undefined constant pass assumed 'pass' in C:\wamp\www\news\log2.php on line 20

Warning
Cannot modify header information headers already sent by (output started at C:\wamp\www\news\log2.php:1in C:\wamp\www\news\log2.php on line 22

Warning
Cannot modify header information headers already sent by (output started at C:\wamp\www\news\log2.php:1in C:\wamp\www\news\log2.php on line 23

Warning
Cannot modify header information headers already sent by (output started at C:\wamp\www\news\log2.php:1in C:\wamp\www\news\log2.php on line 24 

that script make me very mad

Salathe 01-04-2008 12:33 AM

Please take the time to read through, and act on, all of the information made available to you in this topic. The Notice errors that you're getting have already been identified and a solution given to you earlier in the topic (thanks Kalle). You should not use $_POST[name] unless name is defined as a constant in your script (which is isn't, and you shouldn't!). To access the name item in the $_POST array, you need to use: $_POST['name']. Note the single quotes around name.

The final three Warnings are because PHP sent output to the page already: the Notice errors.

webtuto 01-04-2008 12:35 AM

thanks buti tried it and the same problem


All times are GMT. The time now is 11:50 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0