Jump to content

Can you run a PHP script using JS?? (I know it's weird)


Recommended Posts

OK, this is strange, I know.  Let's just approach it as a learning exercise for now.  Here's what I want to happen:

 

1.  Page loads.  There's an image in the page, of a random size.  This size will be different every time the page loads.

2.  JS finds the size of the image - easy enough for JS, but tough for PHP since the image will have to load before the size can be found.  (Right?)

3.  JS somehow passes the size (width and height) of the image to some PHP function (This is the tough part)

4.  PHP returns a third number, some function of the first two.  JS uses it, and goes on its merry little way.

 

Here's another thing - the PHP function (page, whatever) will only process input from some specific URL - ie, some third party could not use a parallel JS to accomplish the same task.

 

Also, the whole works should happen without any user input.

 

If this outside the scope of what's possible, just reply "impossible" and move on to more useful things.  Thanks in advance,

 

    - markis.

OK, I see.  That's exactly what I'm looking for, but here's one more question -

 

I see how to make a request to the server by placing my variables in the URL with JS, but how do I make sure this request cannot be replicated by any other than the page itself?

 

Thanks for turning me on to this.  I didn't know that the heck AJAX was before today!

There are a few different ways, but really, the ajax portion should not contain sensitive data in itself. One way to verify it is by using session and storing a hash that is randomly generated each page call and check that the hash is correct.

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.