Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to do this ASP in PHP - utter newbie

Status
Not open for further replies.

codestorm

Programmer
Apr 11, 2001
504
AU
Hopefully some here know both ASP and PHP. I'd like to know if it's possible to do something akin to the code below in PHP.

---ASP Page---
<%@enablesessionstate=&quot;false&quot; language=&quot;javascript&quot;%>
<html>
<head>
<title>Execute Database Stored Code Test</title>
</head>
<body>
<script runat=&quot;server&quot; language=&quot;javascript&quot;>
var str_TestVar = &quot;How are you?&quot;
var lng_CodeID = Request.QueryString(&quot;CodeID&quot;);
if (!isNaN(lng_CodeID)){
var obj_Connection = Server.CreateObject(&quot;ADODB.Connection&quot;);
obj_Connection.Open(&quot;driver={SQL Server};server=hrwbausdev1;database=test1;uid=sa;pwd=<sa pwd>&quot;);
var obj_Recordset = obj_Connection.Execute(&quot;select C_Body from A_Code where C_CodeID=&quot; + lng_CodeID);
if (!(obj_Recordset.BOF && obj_Recordset.EOF))
eval(obj_Recordset.Fields(&quot;C_Body&quot;).Value);
obj_Recordset = null;
obj_Connection = null;
}
</script>
</body>
</html>
---SQL Server Script---
create database test1
use test1
create table A_Code (C_CodeID int identity(1,1) not null primary key, C_Body varchar(8000) not null)
insert A_Code (C_Body) values ('Response.write(''Hello World. '' + str_TestVar)')
---end---
In essence this is just reading a string from a database field which happens to be executable code, and dynamically executing in within the page. Can it be done in PHP?

PS I've just started learning PHP and have yet to actually code anything in it. exec() initially sounded like the go, but not sure if it can execute a string as well as a file?



codestorm
Fire bad. Tree pretty. - Buffy
select * from population where talent > 'average'
You're not a complete programmer unless you know how to guess.
I hope I never consider myself an 'expert'.
<insert witticism here>
 
i don't know exactly ASP, but i'm going to try to help you.


$str_TestVar=&quot;How are you?&quot;;
$lng_CodeID=$_GET['CodeId'];
if (!...){ // what does that function (isNaN) ?
$conn=mssql_connect(&quot;hrwbausdev1&quot;,&quot;sa&quot;,&quot;<sa pwd>&quot;);
mssql_select_db(&quot;test1&quot;);
$query=&quot;SELECT C_Body from A_code where C_CodeId=$lng_CodeID&quot;;
$result=mssql_query($query);
if(list($cbody)=mssql_fetch_row($result)){
eval($cbody);
}
mssql_free_result($result);
mssql_disconnect($conn);
}

Hope this helps. If you tell me what does that function isNaN is suppose to do, i can help you in that too.

Another thing, as my knowledge of ASP is very limited, i'm not sure of every piece of code, but i hope that helped. Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
Thanks, I'll have to test that - didn't realise that the function in PHP in this instance is called the same name as the function in ASP.

isNaN stands for isNotaNumber - which has one might presume returns true or false depending on whether the argument can be converted into a number. (any kind I think) codestorm
Fire bad. Tree pretty. - Buffy
select * from population where talent > 'average'
You're not a complete programmer unless you know how to guess.
I hope I never consider myself an 'expert'.
<insert witticism here>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top