/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Send variable to unknown page

I wish to send and read a variable from one page to an unknown page, and not necessarily immediately. My solution so far is to write the data to a file, and then read it back. And that works, but is there a way using global variables?

I am trying to log IP addresses, but not log the IP if the previous IP was the same. Crawlers can pound on the site 20 times or more in just a few seconds. I just want it logged once.

I don’t think cookies will work since I don’t think crawlers enable cookies. Do they?

The reason pages are unknown is my site uses SEO addresses, and the actual page is not what the address is.

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@SrWebDeveloperNov 18.2009 — One suggestion is to learn how to work with PHP sessions. You have full control over the data being passed and how long each session should last. The usual approach (simplified for this discussion) is create a database table or XML file storing a session ID, include the data you want stored and a timestamp as to when that record was last updated or created. It's then very easy to manage sessions indidually and time them out and remove them as you see fit. If your site has any form of login or authentication sessions are commonly used on the back end anyway.

Here's some help for you if this is new to you.

-jim
Copy linkTweet thisAlerts:
@DasherauthorNov 19.2009 — Thanks for your recommendation:

I have used sessions a some, and I tried to do it in this situation, but it was not working. I tried again just now, using some test code and have been passing data back and forth between two different pages.

Not sure how long the data will be available in the server. But then I don't need it to last a huge amount of time. I am just trying to prevent flooding from a bang bang crawler/bot.

[code=php]

session_start();
if (!isset($_SESSION['count'])){
$_SESSION['count'] = 1;
}else {$_SESSION['count']++ ;}

echo "The Count is = " . $_SESSION['count'];
[/code]


I made two test files one named test.php the other test1.php with the same code. I ran one file and then the other, and the $_SESSION['count'] value was incrementing between the two unrelated files, even with several minutes between execution.

That seems to work sort of, and should be better than pounding on a file with only 15 bytes of data in it. Just have to modify the code for IP addresses. Maybe I didn't have the setting of the session variable in the header.

I said it works [U]sort of [/U]because refreshes don't seem to increment the value but reloads do. Maybe the value is being cached.
Copy linkTweet thisAlerts:
@DasherauthorNov 19.2009 — OK - I have it working with sessions. Thanks for the suggestion. Not that I didn't try sessions, but that you encouraged me to try again. :-)
[code=php]
session_start();
if(isset($_SESSION['lastIP'])){
$lastIP = $_SESSION['lastIP'];
}else {$lastIP="0.0.0.0";}
$IP = $_SERVER['REMOTE_ADDR'];
$_SESSION['lastIP'] = $IP;
if($lastIP == $IP){$sameIP = 1 ;}else{$sameIP = 0 ;}

// and then

if ($sameIP == 0){
// do some stuff
}

[/code]


My problem with using sessions previously was I wasn't setting $_SESSION['lastIP'] before headers were sent.
×

Success!

Help @Dasher spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...