someone10 Posted December 4, 2010 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?
Byron Posted December 4, 2010 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?
someone10 Posted December 4, 2010 Author 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.
Byron Posted December 4, 2010 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; } ?>
Byron Posted December 4, 2010 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
someone10 Posted December 4, 2010 Author Posted December 4, 2010 Thank you very much!!! I had no idea of that condition with header(). It is working now.
Mak_Zetty Posted December 8, 2010 Posted December 8, 2010 does anyone know how to convert a JS variable to a PHP variable?
Night Baron Posted December 8, 2010 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>
Guest Geoff Posted December 8, 2010 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.
Guest Geoff Posted February 11, 2011 Posted February 11, 2011 Please give a more descriptive post next time. That does not help any of us.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now