Howto identify the calling file in the file you are working

I am trying to run an update query depending on the outcome of this conditional statement but I don’t have any idea as to what I need to do to get what I want. I need the statement to run the update if it was called by either CRON or from the admin panel via a button click in the page googlesitemaps.php. Here is what I have and I know it does not work the way I want it to.

if (!eregi("googlesitemap.php", $_SERVER['PHP_SELF'])) { tep_db_query("update " . TABLE_CONFIGURATION . " set configuration_value = '" . tep_db_input('true') . "', last_modified = now() where configuration_id = 11 "); }else{ // Do nothing }

I know that PHP_SELF is returning the value of the current page this code is in so it is running no matter what page calls this page. I need the magic code that tells me what called the page that this code is in.

I have searched for two days trying to find an answer to this question (not here). I think my main problem is not knowing exactly what keywords to use when using the search engines. I really don’t know how else to ask this question. Perhaps someone more familiar with PHP could formulate a better question out of what I have explained.

Thank you!


Perhaps you’re looking for $_SERVER[‘HTTP_REFERER’]? Please read up on the PHP Manual about this before actually using it though.

I ended up trying this after I read your post and I was looking for more specifics on HTTP_REFERER.

if(strpos($_SERVER['REQUEST_URI'], 'googlesitemap.php') || strpos($_SERVER['REQUEST_URI'], 'sitemaps.index.php')) { tep_db_query("update " . TABLE_CONFIGURATION . " set configuration_value = '" . tep_db_input('false') . "', last_modified = now() where configuration_id = 11 "); }

It works but I don’t think that it going to work when CRON calls it. I don’t have a clue how to figure out what the referring url would be in that situation.

Thank you for responding. It helped me in the right direction.


HTTP_REFERER was what I was looking for but it returns the complete string of the URL including the session ID. While I was looking for help on stripping the session ID I came across the code I ended up using.

If anyone can tell me how to figure out how to identify CRON when it calls this script it would be really great!

Thanks again!


Can’t you tell the cron job to call the script with a URL query string? Some unique identifier that noone knows except for the cron job?

That’s kind of what I thought. I guess I will have to update this manually and turn CRON off or hopefully someone who is a CRON guru will enlighten us. ?!?

Thanks again for your help!


Sponsor our Newsletter | Privacy Policy | Terms of Service