Har lite asp kod som jag skulle behöva motsvarigheten till i PHP, nu kan inte jag någon PHP alls skall jag väl säga.
Koden ska kolla när en användare har varit på hemsidan i mer än 2 minuter, då skall en popup starta(nästa gång han trycker på en länk).
På den här sidan finns inga frames och går inte att lägga dit heller om man inte bygger om den helt.
Har ni något bra script till mig..en asp kodare ;)
Global.asa
<SCRIPT RUNAT=server LANGUAGE="VBScript">
Sub Session_OnStart
' Aktiva på siten
Application.Lock
Application("deltagareStart") = time
Application.UnLock
End Sub
</SCRIPT>
[kod]
Kod som körs hela tiden
[kod]
cookie_id = 212044
antal_minuter = 1
if Request.Cookies("MKraft"&Cookie_Id) = "" then
if DateAdd("n", antal_minuter, Application("deltagareStart")) < time then
'Sätt Cookie
Response.Cookies("MKraft"&Cookie_Id) = Date & " " & Time
Response.Cookies("MKraft"&Cookie_Id).Expires = DateAdd("d", 90, Date)
Response.Write "<html>" & vbcrlf
Response.Write "<head>" & vbcrlf
Response.Write "<script language=""JavaScript"">" & vbcrlf
Response.Write "<!--// Response.Write " window.open([url]www.idg.se,[/url]'msp','width=365,height=430,top=10,left=5,resizable=false,scrollbars=yes');" & vbcrlf
Response.Write "//-->" & vbcrlf
Response.Write "</script>" & vbcrlf
Response.Write "</head>" & vbcrlf
Response.Write "</html>"
end if
end if
$time = 2; // ange tiden som personen ska varit inloggad innan popupen ska komma
if(!$_COOKIE[timestamp])
{
setCookie("timestamp", time());
}
else if($_COOKIE[timestamp] < time() + 60 * $time)
{
echo "Skriv ut javascriptkod för att öppna popup";
}
Får lite felmeddelande när jag kör dit script, är säkert jag som gör något simpelt fel. Har du någon lösning på det?
------------------------------------------------------------
Notice: Use of undefined constant timestamp - assumed 'timestamp' in c:\inetpub\wwwroot\php\cookie.php on line 3
Notice: Undefined index: timestamp in c:\inetpub\wwwroot\php\cookie.php on line 3
Warning: Cannot modify header information - headers already sent by (output started at c:\inetpub\wwwroot\php\cookie.php:3) in c:\inetpub\wwwroot\php\cookie.php on line 5
<?PHP
$time = 2; // ange tiden som personen ska varit inloggad innan popupen ska komma
if(!$_COOKIE[timestamp])
{
setcookie("timestamp", time());
}
else if($_COOKIE[timestamp] < time() + 60 * $time)
{
echo "Skriv ut javascriptkod för att öppna popup";
}
?>
Notice: Use of undefined constant timestamp - assumed 'timestamp' in c:\inetpub\wwwroot\php\cookie.php on line 3
Warning: Cannot modify header information - headers already sent by (output started at c:\inetpub\wwwroot\php\cookie.php:3) in c:\inetpub\wwwroot\php\cookie.php on line 5
Notice: Use of undefined constant timestamp - assumed 'timestamp' in c:\inetpub\wwwroot\php\cookie.php on line 3
Warning: Cannot modify header information - headers already sent by (output started at c:\inetpub\wwwroot\php\cookie.php:3) in c:\inetpub\wwwroot\php\cookie.php on line 5
Notice: Use of undefined constant timestamp - assumed 'timestamp' in c:\inetpub\wwwroot\php\cookie.php on line 3
Warning: Cannot modify header information - headers already sent by (output started at c:\inetpub\wwwroot\php\cookie.php:3) in c:\inetpub\wwwroot\php\cookie.php on line 5
Om detta är rad 3
if(!isset($_COOKIE['timestamp']))
så ska du inte kunna få det felmeddelandet. Kanske sidan har lagt sig i cachen eller nåt.
php skriptet måste ligga i början på filen, därav får du felet "header already...". Du åste alltså anropa cookie-funktionen innan NÅGON SOM HELST html text skrivs ut (antingen genom 'echo' eller utanför taggarna <? ?>)
<?PHP
$tid = 2; // ange tiden som personen ska varit inloggad innan (i munuter) popupen ska komma
$tid = 60 * $tid;
if(!$_COOKIE[timestamp]){
setcookie("timestamp",date()); //Cookien kommer dö när webbläsarfönstret stängs
} else {
$förut = $_COOKIE["timestamp"];
if($förut < (date() + $tid)){ //Om 2 min gått:
echo "Skriv ut javascriptkod för att öppna popup";
}
}
?>
Notice: Use of undefined constant timestamp - assumed 'timestamp' in c:\inetpub\wwwroot\php\cookie.php on line 4
Notice: Undefined index: timestamp in c:\inetpub\wwwroot\php\cookie.php on line 4
Warning: Wrong parameter count for date() in c:\inetpub\wwwroot\php\cookie.php on line 5
Warning: Cannot modify header information - headers already sent by (output started at c:\inetpub\wwwroot\php\cookie.php:4) in c:\inetpub\wwwroot\php\cookie.php on line 5
Det här ska funka, nu har jag tillochmed testat det :)
$time = 2; // ange tiden som personen ska varit inloggad innan popupen ska komma
if(!array_key_exists("timestamp", $_COOKIE))
{
setcookie("timestamp", time());
}
else if($_COOKIE["timestamp"] + 60 * $time < time())
{
echo "Skriv ut javascriptkod för att öppna popup";
}