04. januar 2008 - 11:08
Der er
3 kommentarer og 1 løsning
Hvordan ændrer jeg text i asp-fil uden brug af db
Jeg har en config.asp fil med et username og password, hvor brugerne skal have mulighed for at ændre passwordet. Det skal ske gennem fso eller anden asp uden brug af database. Altså ikke via en database. Det er denne lille script-snippet der skal kunne opdateres. <% username="Peter" password="4Ty68MKl9" %> ... så det bare har ændret pasordet.. <% username="Peter" password="5GQh8788p" %>
Annonceindlæg fra FPT Software
04. januar 2008 - 14:45
#1
Config.asp skal ligge i samme mappe som denne fil: <html> <head> <title>Ændre brugernavn og kodeord i tekstfil</title> <style type="text/css"> div, input { font-family:trebuchet ms; font-size:11px; } input { margin-left:5px; width:200px; vertical-align:middle; } div.headerDiv { color:#FF0000; font-size:14px; text-decoration:none; margin-bottom:5px; } div.headerDiv2 { color:#FF0000; font-size:14px; text-decoration:none; margin-bottom:5px; margin-top:10px; } </style> </head> <body> <% If Request.QueryString("cmd") = "save" Then strNewFile = "<" & chr(37) & VbCrlf strNewFile = strNewFile & "username = """ & Request.Form("new_username") & """" & VbCrlf strNewFile = strNewFile & "password = """ & Request.Form("new_password") & """" & VbCrlf strNewFile = strNewFile & chr(37) & ">" Set FSO = Server.CreateObject("Scripting.FileSystemObject") Set MyFile = fso.CreateTextFile(Server.MapPath("config.asp"), True) MyFile.WriteLine(strNewFile) MyFile.Close Set MyFile= Nothing Response.Redirect "." End If Set FSO = Server.CreateObject("Scripting.FileSystemObject") Set File = FSO.OpenTextFile(Server.MapPath("config.asp"), 1) While Not File.AtEndOfStream arrSplitTextFile = arrSplitTextFile & File.Readline Wend Set FSO = Nothing arrSplitTextFile = Replace(arrSplitTextFile,"<" & chr(37),"") arrSplitTextFile = Replace(arrSplitTextFile,chr(37) & ">","") arrSplitTextFile = Replace(arrSplitTextFile,"username","") arrSplitTextFile = Replace(arrSplitTextFile,"password","") arrSplitTextFile = Replace(arrSplitTextFile,"""","") arrSplitTextFile = Split(arrSplitTextFile,"=") Response.Write "" &_ "<form action=""?cmd=save"" method=""post"">" &_ "<div class=""headerDiv"">Følgende info bliver hentet fra config.asp:</div>" &_ "<div>Nuværende brugernavn: <b>" & arrSplitTextFile(1) & "</b></div>" &_ "<div>Nuværende adgangskode: <b>" & arrSplitTextFile(2) & "</b></div>" &_ "<div class=""headerDiv2"">Følgende nye information skal skrives til config.asp:</div>" &_ "<div>Username: <input type=""text"" name=""new_username"" style=""vertical-align:middle;""></div>" &_ "<div>Password: <input type=""text"" name=""new_password"" style=""margin-left:7px;""> <input type=""submit"" value=""OK!"" style=""width:40px;""></div>" &_ "</form>" %> </body> </html>