kevinyeandel Posted September 14, 2008 Share Posted September 14, 2008 Hi I have been developing an application in Windows, porting it to a Centos Linux server in-house, testing then porting it to a hosted environment which is generic linux. I've had no end of problems with the hosting company and getting my code to work. Right now, cookies and header dont seem to work so I wrote cookietest.php which calls cookietest2.php and should pass a cookie. I am asking you experts if you could validate my code before I get on the back of the hosting company. I dont profess to be a php expert but am baffled why my code works in WAMP and on Centos but not on a hosting company server!. File 1: cookietest.php <html> <?php setcookie("test123","abc"); ?> <body>Hello.. You should not be able to read this because it will be too fast <?php header("Location: testcookie2.php"); ?></body> </html> File 2: <html> <body> Hello <?php if(isset($_COOKIE['test123'])) { echo "cookie is set >>" .$_COOKIE ['test123'] ; } else echo "cookie not set"; ?></body></html> It runs find on my Centos box. On the hosted companies, Header does not redirect, if I try echo'ing javascript href.location..... I can get to the second file but no cookie info. When I try running php -version on the hosted system I am told there are missing libs: [pow@cpanel6 ifp]$ php -version Failed loading /usr/local/IonCube/ioncube_loader_lin_5.2.so: /usr/local/IonCube/ioncube_loader_lin_5.2.so: cannot open shared object file: No such file or directory On my Centos at home: # php -version PHP 5.1.6 (cli) (built: Sep 20 2007 10:04:27) Copyright © 1997-2006 The PHP Group Zend Engine v2.1.0, Copyright © 1998-2006 Zend Technologies Many thanks in advance. Kevin Quote Link to comment https://forums.phpfreaks.com/topic/124167-php-please-validate-my-test-code-before-i-complain-to-hosting-company/ Share on other sites More sharing options...
BlueSkyIS Posted September 14, 2008 Share Posted September 14, 2008 this should NOT work, because you have output to the browser before the header() function is used. You should have NO output before header(): File 1: cookietest.php <html> <?php setcookie("test123","abc"); ?> <body>Hello.. You should not be able to read this because it will be too fast. Actually, you might be able to read this because the header() function should fail and leave this on the page with an error message like 'headers already sent.' <?php header("Location: testcookie2.php"); ?></body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/124167-php-please-validate-my-test-code-before-i-complain-to-hosting-company/#findComment-641048 Share on other sites More sharing options...
thebadbad Posted September 14, 2008 Share Posted September 14, 2008 Cookies and headers MUST be sent before ANY output. Have you errors turned off or something? Your code should look like this: testcookie.php <?php setcookie('test123', 'abc'); header('Location: testcookie2.php'); ?> testcookie2.php <?php if (isset($_COOKIE['test123'])) { echo "Cookie 'test123' is set to {$_COOKIE['test123']}"; } else { echo 'Cookie not set'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/124167-php-please-validate-my-test-code-before-i-complain-to-hosting-company/#findComment-641051 Share on other sites More sharing options...
thebadbad Posted September 14, 2008 Share Posted September 14, 2008 @ BlueSkyIS Remember that cookies also need to be set before any output. Quote Link to comment https://forums.phpfreaks.com/topic/124167-php-please-validate-my-test-code-before-i-complain-to-hosting-company/#findComment-641053 Share on other sites More sharing options...
BlueSkyIS Posted September 14, 2008 Share Posted September 14, 2008 Have you errors turned off or something? good call. maybe it's "working" locally because errors are turned off and not working on the host server because errors are not turned off. it technically shouldn't be working. yes, cookies before output also, as they are also header content. Quote Link to comment https://forums.phpfreaks.com/topic/124167-php-please-validate-my-test-code-before-i-complain-to-hosting-company/#findComment-641054 Share on other sites More sharing options...
thebadbad Posted September 14, 2008 Share Posted September 14, 2008 To OP: Maybe you got this right, but remember to set the expire, path and domain parameters in setcookie(), to control when the cookie expires, in which directories the cookie is available and on which (sub)domains it's available, respectively. Quote Link to comment https://forums.phpfreaks.com/topic/124167-php-please-validate-my-test-code-before-i-complain-to-hosting-company/#findComment-641060 Share on other sites More sharing options...
wildteen88 Posted September 14, 2008 Share Posted September 14, 2008 The code should not work at all no matter whatever error_reporting or display_errors is set to. The only way the code will work is if the OP has a setting called output_buffering set to On within the php.ini for thier WAMP setup, quote from the php.ini ; Output buffering allows you to send header lines (including cookies) even ; after you send body content, at the price of slowing PHP's output layer a ; bit. You can enable output buffering during runtime by calling the output ; buffering functions. You can also enable output buffering for all files by ; setting this directive to On. If you wish to limit the size of the buffer ; to a certain size - you can use a maximum number of bytes instead of 'On', as ; a value for this directive (e.g., output_buffering=4096). Quote Link to comment https://forums.phpfreaks.com/topic/124167-php-please-validate-my-test-code-before-i-complain-to-hosting-company/#findComment-641062 Share on other sites More sharing options...
Mchl Posted September 14, 2008 Share Posted September 14, 2008 Output buffering is enabled by default in WampServer. I think they enabled it in version 2, because WAMP5 had it disabled AFAIR. Quote Link to comment https://forums.phpfreaks.com/topic/124167-php-please-validate-my-test-code-before-i-complain-to-hosting-company/#findComment-641072 Share on other sites More sharing options...
wildteen88 Posted September 14, 2008 Share Posted September 14, 2008 That'll be the problem then. Quote Link to comment https://forums.phpfreaks.com/topic/124167-php-please-validate-my-test-code-before-i-complain-to-hosting-company/#findComment-641077 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.