Jump to content

[SOLVED] php insert in asp using Microsoft.XMLHTTP


becca800

Recommended Posts

I have a PHP script that I am trying to include in asp. Most people say you can not do this but actually you can by using this include:

 

<%
Dim objHttp
set objHttp = Server.CreateObject("Microsoft.XMLHTTP")
objHttp.open "POST", "http://www.yoursite.com/ad/comments/comments.php", false
objHttp.Send
If objHttp.status = 200 Then
response.write(objHttp.responseText)
End If
set objHttp = nothing
%>

 

I found this code and it works great.

 

However, the script calls for one the url variable to be assessed by using the function:

 

<input type=hidden name="href" value="{$_SERVER['REQUEST_URI']}">

 

Instead of getting the correct url of the asp page in which it is inserted, it records the url from the insert: http://www.yoursite.com/ad/comments/comments.php I have done tests by inserting this into test php files, and of course, it works fine, so it is the insert method I am using above which is giving it trouble.

 

I am not a php expert, I know very little, I only know basic html so if you have any thouhts you might need to literally draw it out for me. I found one post in another forum which was similar and someone said that the person needed to add get variables but I didn't know what this meant.

 

Thank, Becca

Link to comment
Share on other sites

Okay, let's see if I can word this better. I am inserting a php script into an asp page using the insert above as shown, this is the only way it will run.  The script fills out a form and includes the url.  It obtains the url with the single line function described above.  However, it is not getting the correct url.  It is getting the url from the php page which I am inserting, rather than the new asp page which it is inserted into.  It has to do with the way I am inserting it.  There should be a way to correct this, I would think.

 

Make sense?  Forgive me, I am no a php expert and my techie lingo sucks.

Link to comment
Share on other sites

Okay i think i get you.. your calling from an ASP using XMLHTTP request to call a PHP page (to do stuff) but a form on the PHP page needs to contain the path of the ASP page ..

 

Okay.. if you doing 90% of the code in ASP i would do this

 

<%
Dim objHttp
set objHttp = Server.CreateObject("Microsoft.XMLHTTP")
'Get the current page (i thin the below will do it
set Thispage ="http://" & Request.ServerVariables("SERVER_NAME") & Request.ServerVariables("URL")
'Pass it via URL
objHttp.open "POST", "http://www.yoursite.com/ad/comments/comments.php?PAGE=" & Thispage, false

objHttp.Send
If objHttp.status = 200 Then
response.write(objHttp.responseText)
End If
set objHttp = nothing
%>

 

$ASPpage = urldecode($_GET['PAGE']);
<input type=hidden name="href" value="$ASPpage">

 

 

Other option is PHP only

<input type=hidden name="href" value="{$_SERVER['HTTP_REFERER']}">

Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted.

 

i think thats what your looking for

Link to comment
Share on other sites

i am trying this but i have a question.  i removed your comments and used:

<%
Dim objHttp
set objHttp = Server.CreateObject("Microsoft.XMLHTTP")
Request.ServerVariables("SERVER_NAME") & Request.ServerVariables("URL")
objHttp.open "POST", "http://www.advicediva.com.com/ad/comments/comments.php?PAGE=" & Thispage, false

objHttp.Send
If objHttp.status = 200 Then
response.write(objHttp.responseText)
End If
set objHttp = nothing
%>

 

is this correct?  Again, I am very poor with this.  Should I have put the actual www.address in the ? and thispage?  Right now, the way it is it turns me to a completely new url.

Link to comment
Share on other sites

you need the

Thispage =

i added that back

 

bascially you could do

Thispage="www.thisISmySITE.com"

but

Request.ServerVariables("SERVER_NAME") & Request.ServerVariables("URL")

gets those details

 

try it, see what happens

 

<%
Dim objHttp
set objHttp = Server.CreateObject("Microsoft.XMLHTTP")
Thispage=Request.ServerVariables("SERVER_NAME") & Request.ServerVariables("URL")
objHttp.open "POST", "http://www.advicediva.com.com/ad/comments/comments.php?PAGE=" & Thispage, false

objHttp.Send
If objHttp.status = 200 Then
response.write(objHttp.responseText)
End If
set objHttp = nothing
%>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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

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

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.