General Question

webmasterwilliam's avatar

External Link to PHP module execute twice?

Asked by webmasterwilliam (165points) September 22nd, 2008

When I link to a PHP module from an external document, such as an email or word document, the link is executed twice. However, if I execute the link from a browser URL, the module is executed only once, as desired.

For testing, I created the simple module http://localhost/Website/testentry.php which has the following simple code;
<?php
session_start();
$_SESSION[‘testSession’] = “Hello World”;
?>

If I execute if from an external link, the module sets two session files, with the exact same info in it; testSession|s:11:“Hello World”;

If I execute the module from the URL, only one session file is created.

This is just a simple example. My real problem is an application I’m developing having the same problem, where the first entry verifies the presence of a mySql row, and moves it to another table. The second trip can’t find the moved row and signals an error condition.

Does anyone have any suggestions why this behavior is different between submitting an external link versus a URL submission?

Observing members: 0 Composing members: 0

4 Answers

jasonjackson's avatar

I’m not sure I understand the question correctly, but if I do: it sounds like whatever program you’re embedding your link in (“email or word document”) is loading the URL more than once.

It’s also probably not sending cookies; since you’re getting two session files, that seems to indicate that the session cookie that would let PHP deal with both requests under the same session isn’t being sent by whatever your web client is.

I would say you’ll probably have to modify your web app’s logic so that not finding the row in the first table isn’t considered an error. Or maybe you can check the second table as well, before signaling the error, so that one second & subsequent hits to the URL, it just verifies that the row has been moved, and only raises an error if the appropriate row can’t be found in either table.

webmasterwilliam's avatar

@jasonjackson – Thanks for the input. I’ll try checking the second table before throwing an error condition.

Anaphase's avatar

I have no idea, but localhost links are typically of no use to anyone else.

Vincentt's avatar

@Anaphase – it’s for testing :) (and Fluther automatically made it into a link)

Anyway, what exactly do you mean by module? Like a PECL extension? Or is my PHP lingo outdated already after two days without internet? ;-)
It might also be because I’m not that sharp tonight

Answer this question

Login

or

Join

to answer.

This question is in the General Section. Responses must be helpful and on-topic.

Your answer will be saved while you login or join.

Have a question? Ask Fluther!

What do you know more about?
or
Knowledge Networking @ Fluther