Jump to content

simple problem


dekonstruct

Recommended Posts

Hello, I'm quite a noob at all this php stuff, here's my problem:

I have some simple strings:

<?php
$day = date(z);
$counter = 1;

echo $day;
echo $day - $counter;
?>

and I'm wondering how to create a link that adds 1 to the counter everytime you click it. I know that ++ is incremental but php in links completely baffles me at the moment. any prodding in the right direction would be most appreciated. THANK YOU!
Link to comment
Share on other sites

hmmm sessions seem to be what I need. I tried one out and got this error:
Warning: session_start(): Cannot send session cookie - headers already sent by...

I don't see how anything is being sent when there's only one session on the darn page. I am viewing this off a server through firefox if that's any help to anyone.

do i need to setup my server differently to be able to handle sessions perhaps?

Thanks everyone!
Link to comment
Share on other sites

it would help if you actually showed your code.  But based on your error, you are attempting to output html before sending header information.  You can't do that.  Not even a blank line.  headers must come before any html output.  If you absolutely have to have html output before headers in your code, use ob_start() at the very beginning of your script and ob_end_flush() at the end. This will create a buffer for your html code so that the header info can be parsed first.
Link to comment
Share on other sites

[code]<?php
session_start();

if(isset($_SESSION['counted'])){
$new = $_SESSION['counted'] + 1;
$_SESSION['counted'] = $new;
echo $_SESSION['counted'];
}else {
$_SESSION['counted'] = 1;
}
?>[/code]

I just cut and pasted what mgallforever had posted... there's nothing else on the page, and it's called phptest.php

here's the error:
[b]Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /xxx/xxx/xxx/xxx/xxx/xxx/xxx/test/phptest.php:1) in /xxx/xxx/xxx/xxx/xxx/xxx/xxx/test/phptest.php on line 2[/b]

sorry if this all seems too easy... The only language-ish thing I've known before trying php was actionscript so I'm a little broken  ;)
Link to comment
Share on other sites

Low and behold I finally found a fix to my problem. I found it here:[url=http://us2.php.net/function.session-start]http://us2.php.net/function.session-start[/url]

Turns out that when you edit it in notepad, you shouldn't select utf-8 encoding because it puts two hidden characters before the document starts, thus you can't start a session. everything works beautifully for me, thanks everyone for your help!

here's what the smart dude that found this out said:

[quote] saykyo (mail at gmail dot com)
12-Jul-2006 08:23
Watch out for using UTF-8 encoding in your php scripts!

I don't know about other enviroments, but in Windows XP, if you edit a document and set it to be UTF-8, the editor (notepad for exapmle) inserts two invisible bytes at the beginning of the file (they read FF FE in hex for me). I suppose this happens so Windows can identify the file as UTF-8.

Since these two bytes are placed before anything else in the file, including <? ?> tags, when you execute the php script, they get outputed to the browser (even tough they won't be shown in the source of the result document, they're there!) before your php code gets a chance to run anything. This effectively cripples functions like session_start() ($_COOKIE to be exact).

The solution is to save the php file in a different encoding, or to manually remove them (I prefer the former).

I hope I helped somebody.
[/quote]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.