I have a file called 2.php and it should write a cookie and then file 3.php read it back. 2.php contains 3.php contains However when I have opened 2.php and then 3.php nothing happens! I looked at the error log and got the following Please help, I really need this to work, Cheers Web-Master
your parameter deficient you must post a time example <?php setcookie("username", "john",time()+60*60); ?> time()+60*60 = 1 Hour
Got the following when I did that Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/adscheme/public_html/h3/2.php:1) in /home/adscheme/public_html/h3/2.php on line 1 Warning: Cannot modify header information - headers already sent by (output started at /home/adscheme/public_html/h3/2.php:1) in /home/adscheme/public_html/h3/2.php on line 2
Hello ! In 2.php put : <?php print "<script SRC=cookies.js LANGUAGE='JavaScript'></script><script>Set_Cookie( 'username', 'john', '1', '/', '', '' );</script>"; ?> HTML: and In 3.php put this : <?php if(!empty($_COOKIE['username'])) { $username = $_COOKIE['username']; }else{ // it's empty $username = " "; } echo "Username is : $username"; ?> HTML: Add This JS file in the same Dir with 2.php & 3.php : cookies.js function Set_Cookie( name, value, expires, path, domain, secure ) { // set time, it's in milliseconds var today = new Date(); today.setTime( today.getTime() ); /* if the expires variable is set, make the correct expires time, the current script below will set it for x number of days, to make it for hours, delete * 24, for minutes, delete * 60 * 24 */ if ( expires ) { expires = expires * 1000 * 60 * 60 * 24; } var expires_date = new Date( today.getTime() + (expires) ); document.cookie = name + "=" +escape( value ) + ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + ( ( path ) ? ";path=" + path : "" ) + ( ( domain ) ? ";domain=" + domain : "" ) + ( ( secure ) ? ";secure" : "" ); } function Get_Cookie( name ) { var start = document.cookie.indexOf( name + "=" ); var len = start + name.length + 1; if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) { return null; } if ( start == -1 ) return null; var end = document.cookie.indexOf( ";", len ); if ( end == -1 ) end = document.cookie.length; return unescape( document.cookie.substring( len, end ) ); } function Delete_Cookie( name, path, domain ) { if ( Get_Cookie( name ) ) document.cookie = name + "=" + ( ( path ) ? ";path=" + path : "") + ( ( domain ) ? ";domain=" + domain : "" ) + ";expires=Thu, 01-Jan-1970 00:00:01 GMT"; } HTML: enjoy you can find more tutorials about Set_Cookie & cookies.js ... Any more Help , we will be happy to help you Best Regards
Hello ; web-master ; I'm Happy to help you , if you need more help PM me ; Thank's Best Regards CHEMORUI.
The error "Cannot modify header information - headers already sent by ..." usually means that you have something other than an end-of-file marker after the closing ">". Remove any spaces, new lines, etc.
That is an incredibly bad method of using cookies, there is so much work there that you don't need to do. The OP was doing it perfectly, but there may have been some whitespace (new lines, tabs) before the opening "<?php". When there is some text, anything at all, before the "<?php" the script will send out the http headers for the page immediately. When this happens, no cookies can be written. As far as i can remember, they can still be read. "web-master", check 2.php and make sure that the VERY first 5 bytes of the file are "<?php". Doing this should get the script working. If not, there are some issues with either your php settings, or your Apache settings (providing that you are using Apache).