someone10 Posted December 4, 2010 Share Posted December 4, 2010 Hello everyone. I recently opened a website here at heliohost.org. I uploaded all my PHP files. Most of those files contain two basic built in functions: setcookie() & header(), both seem to malfunction. Did anyone else experience this kind of problem? if so, what to do? Quote Link to comment Share on other sites More sharing options...
Byron Posted December 4, 2010 Share Posted December 4, 2010 Here's an example of how I'm setting a cookie on one of my pages: $to = $_POST[sendto]; # Set Cookie & Expire Time $expire = time()+60*60*24*60; # (60 sec * 60 min * 24 hours * 60 days) setcookie("sendto", $to, $expire); Then down in my form: <input type="text" name=""sendto"" size="30" value="<?php echo $_COOKIE[sendto]; ?>"> Can you give an example of what your doing? Quote Link to comment Share on other sites More sharing options...
alteisenriese Posted December 4, 2010 Share Posted December 4, 2010 What error message did you get? Quote Link to comment Share on other sites More sharing options...
someone10 Posted December 4, 2010 Author Share Posted December 4, 2010 It shows me this: Warning: Cannot modify header information - headers already sent by (output started at /home1/someone/public_html/forum/loginforum.php:15) in /home1/someone/public_html/forum/loginforum.php on line 45 Warning: Cannot modify header information - headers already sent by (output started at /home1/someone/public_html/forum/loginforum.php:15) in /home1/someone/public_html/forum/loginforum.php on line 46 Warning: Cannot modify header information - headers already sent by (output started at /home1/someone/public_html/forum/loginforum.php:15) in /home1/someone/public_html/forum/loginforum.php on line 47 script: header( "Location: forum.php" ); I suppose it affects the cookie setting ( setcookie("forumpassword", "$_POST[pass]", time() + 3600); ). P.S. It's nice to get a reply in such a short amount of time. Quote Link to comment Share on other sites More sharing options...
Byron Posted December 4, 2010 Share Posted December 4, 2010 You can't have any html output before the header redirect. I'm guessing your using an if statement to detect a cookied login? If that's the case this should go to the top of your loginforum.php before any html output: <?php if ( $_COOKIE[pass] == "forumpassword" ) { header( "Location: forum.php" ); exit; } ?> Quote Link to comment Share on other sites More sharing options...
Byron Posted December 4, 2010 Share Posted December 4, 2010 Here's something else to consider. If that forum was pre-made and worked on another server, your problem might be this: http://www.geeklog.net/faqman/index.php?op=view&t=38 Quote Link to comment Share on other sites More sharing options...
someone10 Posted December 4, 2010 Author Share Posted December 4, 2010 Thank you very much!!! I had no idea of that condition with header(). It is working now. Quote Link to comment Share on other sites More sharing options...
Mak_Zetty Posted December 8, 2010 Share Posted December 8, 2010 does anyone know how to convert a JS variable to a PHP variable? Quote Link to comment Share on other sites More sharing options...
Night Baron Posted December 8, 2010 Share Posted December 8, 2010 does anyone know how to convert a JS variable to a PHP variable? You could use Ajax to send the JS variables to PHP Ajax Code: (found off of daniweb) <script type="text/javascript"> function Send() { function GetXmlHttpObject() { var xmlHttp=null; try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); } catch (e) { // Internet Explorer try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } } return xmlHttp; } xmlHttp=GetXmlHttpObject(); xmlHttp.onreadystatechange=changeofState; //change the page below to you php page name var url="something.php"; //change 'variable' to the name of the javascript variable that contains the dollar amount url = url+"?amt="+variable; url = url+"&sid"+Math.random(); xmlHttp.open("GET",url,true); xmlHttp.send(null); function changeofState() { if(xmlHttp.readyState==4) { document.write('ok'); } } } </script> Another way that you can do it is using JS to redirect the page. <script language="JavaScript"> var sendvar = 55; location.href="something.php?key=" + sendvar; </script> Quote Link to comment Share on other sites More sharing options...
Guest Geoff Posted December 8, 2010 Share Posted December 8, 2010 You can also use json_encode() to send a variable to js through ajax, then just eval() it in javascript and you have your variable. Quote Link to comment Share on other sites More sharing options...
freehost.cc Posted February 11, 2011 Share Posted February 11, 2011 i am waiting my free host created. Quote Link to comment Share on other sites More sharing options...
Guest Geoff Posted February 11, 2011 Share Posted February 11, 2011 Please give a more descriptive post next time. That does not help any of us. Quote Link to comment 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.