Jump to content

Recommended Posts

Posted

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?

Posted

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?

Posted

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.

Posted

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;
}
?>

 

Posted
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>

Posted

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.

  • 2 months later...
Posted

Please give a more descriptive post next time. That does not help any of us.

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...