---
title: "översätta kod från asp till PHP"
type: "forum-thread"
url: "https://www.webforum.nu/amne/php/64373-översätta-kod-från-asp-till-php"
topic: "PHP"
topic_url: "https://www.webforum.nu/amne/php"
author: "hakan@4u2.se"
published: "2003-01-10T09:42:30.000Z"
updated: "2003-01-15T08:55:21.000Z"
replies: 12
views: 585
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/php/64373-översätta-kod-från-asp-till-php"
---

# översätta kod från asp till PHP

## #1 — hakan@4u2.se, 2003-01-10T09:42Z

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

Permalänk: https://www.webforum.nu/p/64373

## #2 — pimme, 2003-01-10T12:29Z

```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";
}
```

tror att detta ska funka

titta även på programmen asp2php
<http://asp2php.naken.cc/>

Permalänk: https://www.webforum.nu/p/908936

## #3 — hakan@4u2.se, 2003-01-13T10:42Z

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

Permalänk: https://www.webforum.nu/p/911130

## #4 — pimme, 2003-01-13T11:48Z

testa
if(!isset($\_COOKIE\[timestamp\]))
istället

Permalänk: https://www.webforum.nu/p/911177

## #5 — hakan@4u2.se, 2003-01-13T11:56Z

Blir samma sak!

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

Permalänk: https://www.webforum.nu/p/911184

## #6 — Matte, 2003-01-13T12:20Z

```
if(!isset($_COOKIE['timestamp']))
```

 
Indexet är en sträng och ska därmed omges av citationstecken.

Permalänk: https://www.webforum.nu/p/911199

## #7 — hakan@4u2.se, 2003-01-13T12:29Z

Samma sak!

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

Permalänk: https://www.webforum.nu/p/911207

## #8 — Matte, 2003-01-13T12:42Z

> **hakan@4u2.se skrev:**
>
> Samma sak!
> 
> 
> 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.

Permalänk: https://www.webforum.nu/p/911214

## #9 — prey, 2003-01-13T12:48Z

en sak ingen nämner: 

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 \<? ?\>)

Permalänk: https://www.webforum.nu/p/911221

## #10 — prey, 2003-01-13T12:57Z

Borde det inte va nåt sånt här?:

```php
<?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";
   }
}
?>
```

(otestat)

Permalänk: https://www.webforum.nu/p/911230

## #11 — hakan@4u2.se, 2003-01-13T14:56Z

Blir så här...

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

Permalänk: https://www.webforum.nu/p/911351

## #12 — pimme, 2003-01-13T15:26Z

Det här ska funka, nu har jag tillochmed testat det  :)

```php
$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";
}
```

Permalänk: https://www.webforum.nu/p/911384

## #13 — hakan@4u2.se, 2003-01-15T08:55Z

Tack det fungerar med att han skriver ut text.
Men ändrar jag till en popup så kommer det ingen popup
vad gör jag för fel?

```
$time = 1;   // 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  "<html>";
		echo  "<head>";
		echo  "<script language='JavaScript'>";
		echo  "<!-- ";
		echo  "  window.open('http://www.aftonbladet','msp','width=365,height=430,top=10,left=5,resizable=false,scrollbars=yes');" ;
		echo  "//-->";
		echo  "</script>";
		echo  "</head>";
		echo  "</html>";
}
```

Permalänk: https://www.webforum.nu/p/912861

---

Tråden på webben: https://www.webforum.nu/amne/php/64373-översätta-kod-från-asp-till-php
