Jump to content

PHP problem


Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

  • 2 months later...

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.   Paste as plain text instead

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