Okay, Ive searched around and found how this is supposed to be done. For example, finding this question. However it is not working for me, so I must be doing something wrong, but darned if I know what.

Okay... here is my little code block:

<?php
    session_start();

    if(!isset($_SESSION['didit'])) {
        $url = "http://www.mysite.com/clients/vatera.asmx/DoSomething";
        file_get_contents($url);
        $_SESSION['didit'] = true; 
    }
?>

The url file_get_contents is all working perfectly. The only thing not working is the "run once" check. It is running the url code EVERY time through the page. It should only run it the first time you hit the page in a session. This block is located immediately following the <html> tag in my page.

Some other things I have tried:

if(empty($_SESSION['didit']))
if($_SESSION['didit'] != true)
if($_SESSION['didit'] <> true)

I also tried moving the line setting the variable to precede the $url assignment.

None of these have worked. It continues to run the code EVERY time the page is loaded. Thanks in advance!

没有正确的解决方案

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top