Set The $SERVER Variable To $_SERVER['SERVER_ADDR'] In The Class?

I have a simple class like this:

class packet {
private $SERVER = "";

This works fine on localhost but on the server the $SERVER variable needs to be "" instead. It's a pain having to keep changing this manually and using "localhost" doesn't work for some reason.I wanted to use $_SERVER['SERVER_ADDR'] but it errors when I use it. I have an issue with PHP/Apache which means I can't see the error that it I could set the $SERVER variable to $_SERVER['SERVER_ADDR'] in the class?



I'm on HostMonster and I'm trying to setup cron to play nicely with a Drupal install I have running and I'm running into problems trying to code for a condition that says, "IF I'm the server and I'm making the request to do CRON, then do the following..."Basically (in layman's terms), I'm having a hard time trying to figure out how I should code for cron requests from the server, which brings me to the following questions:1.) Do cron jobs always execute from the host server? For example, if $_SERVER[SERVER_ADDR] is always "", does this mean that the 583 bytes sent for cron jobs always come from the same IP address or are there exceptions to this? The reason I ask this is because I have a poor man's byte counter in this cron code I'm working with that sets up a file read and keeps you in the reading loop until the byte count reaches 583 (which, according to my IP logs, is the number of bytes sent with each cron "ping" that gets made.) The code isn't firing, however, because I'm having a hard time making the code run from either cron requests or else from an inconsistency between the IP comparison code I have.2.) Before any cron code gets executed, I have "ignore_user_abort(true);" called at the beginning of the page. Will this effectively process all proceeding code thereafter if cron pings the page? In other words, will using this make the page get processed as if someone traveled to the cron.php page in their browser?

View 7 Replies View Related

$_server['server_addr'] = '';

Which is totally wrong as it should be the network IP address instead. What must I change and where to fix this, sorry I absolutely don't know and couldn't find it online anywhere.

View 3 Replies View Related


I've just begun exploring php and have a question about the $_SERVER[SERVER_ADDR] variable.

My dilemma is as follows. Recently i created a webpage that use an embedded php script to stream audio from my site. The trouble i have is that i'm on dynamic IP connection.

Whenever my IP changes the absolute adresses on my index.html page to the php components break and the site don't work properly until i've manually corrected this. Since this requires constant monitoring of the site i've been trying to find a solution to fix this.

My thought then went to using the $_SERVER[SERVER_ADDR] variable in these url' to update them automatically. However, it only worked partially.

In the following lines it was possible to change the IP number part in the url with a variable containing the $_SERVER[SERVER_ADDR] string........

View 2 Replies View Related

$_SERVER['SERVER_ADDR'] Isn't Returning Anthing?

Does anyone know why $_SERVER['SERVER_ADDR'] isn't returning anthing? and which global array i should use to return "localhost" and (localhost default IP).

View 9 Replies View Related

Identifying Class Names From $_SERVER['SCRIPT_FILENAME']?

What is the best way to obtain the class name for a requested php file? This question is a subset of another open question What are some PHP Object Oriented Framework Initialization Techniques? If my unknown class follows the following pattern:


class NotIndex extends View

For testing I want to create an instance of the NotIndex class within the startup.php script.


//Include the script again to bring in the class definition[code]...

I'm thinking a regex solution might be simple since the desired data will always be between 'class' and 'extends'. I don't have much experience formulating the desired expression and would appreciate some insight.


The following solution may or may not be a good way of doing this, but it did lead me to a non regex solution which is always a plus. If anyone can improve on this, then I will gladly give them credit for both my questions above. Credit actually goes to @Nik answering this question: Extracting function names from a file (with or without regex) If I do this in my startup script then I can probably count on the unknown class being the last one in the array. However, I plan on integrating this into my framework and would like a more complete solution.

Since the class name is unknown, you may ask how can we be sure? Well the abstract class View comes right before the unknown class in the array. Any solution would surely have to check for this. So without guarantee the last class is the needed class, I probably need to traverse backwards in the array until I have identified the abstract View class and the previous value in the array would be the unknown subclass.


//Include the script again to bring in the class definition

//Make sure I'm seeing any errors[code]...


So this solution only works if I include my abstract View class immediately before I include the unknown subclass script again via the: include($_SERVER['SCRIPT_FILENAME']); So this implies the get_declared_classes() function adds the classes in the order they were defined or included. This could be a problem. I'm going to sleep on it and hopefully I will have a refreshed view tomorrow.

//Include the script again to bring in the class definition

View 2 Replies View Related

Oop - Assign Session Variable To Class Variable While Initialize The Class Variable?

I have a problem regarding assign session variable to class variable while initialize the class variable.

Check my below code

class ModifyProfile
var $userType=$_SESSION['wb_user_type'];


so can i assign the session variable to class variable as above or not.

EDIT: What is the use of public, private and protected keyword while declaring class variable?

View 4 Replies View Related

SERVER_ADDR Undefined Index?

I am getting an undefined index on my config page and it reads:

Notice: Undefined index: SERVER_ADDR in inc/config
.inc.php on line 3

how I can fix that? I know its warning, but would still like to get at it. I am using it to check for the address whether to use my local or remote config settings.

View 4 Replies View Related

Server - Can $_SERVER Variables In It Be Changed By The User?

I need to use $_SERVER variables like SCRIPT_FILENAME for a mvc framework I'm writing. I'm wondering if a user can change things like that. Say the user requests index.php, can they fake the SCRIPT_FILENAME variable and rename it to something else that is being sent over?

View 3 Replies View Related

$_SERVER['TEMP'] Variable Missing (PHP 4.3.1)

I'm attempting to use JpGraph ( with
PHP (4.3.1) and Apache (1.3.26) runnning on WindowsXP. However, I receive
the following notice:

Notice: Undefined index: TEMP in
c:apachehtdocscprgsspphplibjpgraphjpgraph.p hp on line 189

Lines 187-193 of jpgraph.php are:

if (!defined('CACHE_DIR')) {
if (strstr( PHP_OS, 'WIN')) {
} else {

So I'm looking for $_SERVER['TEMP'] in the output of phpinfo() and I do not
find it. Here is the output from the set command under Windows:

lsENGLISH;C:java in;C:Perlin;C:php;C:m
ysqlin;C:Program FilesSSH Communications SecuritySSH Secure Shell;Z:.;

'TEMP' is set as a system environment variable. Several other system
environment variables appear in the output of phpinfo() such as
$_SERVER['SystemRoot'] ('C:WINDOWS') and $_SERVER['PATH'] (which appears
exactly as it appears in the output of the set comand above.)

Any assistance you could offer would be greatly appreciated. Thanks for your
time and attention.

View 1 Replies View Related

Undefined Variable _SERVER Error


echo('<p>' . $_SERVER['PHP_SELF'] . '</p>');


this is my code. Whenever I try to view it in the Browser I am getting the following error:

Warning: Undefined variable: _SERVER in c:inetpubwwwrootphpincludesincludessimpleParagraph.php on line 3 ...

View 1 Replies View Related

$_SERVER['PHP_SELF'] Inside A Variable

Can someone tell me what is wrong with this please:

//create the login form
$loginform .= '<table width="300" border="2" align="center">
<td><form name="form1" id="form1" method="post" action="<? $_SERVER['PHP_SELF']?>" />
<p align="left">
<input name="admin_email" type="text" id="admin_email" />
Primary Email Address</p>
<p align="left">
<input name="pwd" type="password" id="pwd" />
<p align="left">
<input type="submit" name="Submit" value="Submit" />
</table>' ;

I am going to echo $loginform later on in the script, if needed.

The $_SERVER['PHP_SELF'] does not work - it looks for it as a file name and I just get a 404. I have tried escaping it a bunch of different ways, creating another variable to hold it, putting curly brackets and/or periods around it, etc.

View 1 Replies View Related

Server - Create Back Link With $_SERVER['HTTP_REFERER']?

just a short question, is it save to create an back link with :

$backLink = htmlentities($_SERVER['HTTP_REFERER']);

or is there an better solution ?

View 6 Replies View Related

Definitive Matrix Of $_SERVER Values For Different Web Server Software Out There?

I'm write PHP applications to distribute publicly, and am trying to ensure they run correctly on all popular web server software (IIS, Apache, NGINX, Lighttpd).

Does anybody know if someone has created definitive matrix of $_SERVER array items for each different popular server software package? Sounds like a good idea, and I just want to make sure that it hasn't been created already before I attempt to do so myself...

View 1 Replies View Related

Compare Variable To $_SERVER['PHP_SELF'] Safe Usage?

I am a newbie to PHP still, so excuse this question if it seems silly, but I was wondering if this is safe usage of $_SERVER['PHP_SELF']. From my reading about what's wrong with it (prone to injection), I was wondering if it safe to compare it. For example, I want the PHP/CSS stylesheet to change depending on the page the person is on, so in the PHP/CSS, it would have an if statement checking $_SERVER['PHP_SELF'] to see if the page their visiting requires a different stylesheet. Example:

if ($_SERVER['PHP_SELF'] === $thisPage) { }

Could malicious code affect me this way? Could I simply validate/cleanse it, then use it?

View 2 Replies View Related


Is there a way to use opendir() using some sort of absolute path?
I want a file to open the same directory on my site, no matter from what directory it is called.

For example, I have the following variables, but no combination seems to work for me.

Q: Does opendir() ONLY deal with relative paths?
Q: If opendir() works with absolute path, am I missing something?PHP Code:

View 1 Replies View Related

Setting A $_SERVER Value ($_SERVER['something']) Using Apache .htaccess?

Is it possible using .htaccess or other apache powers to set a custom server value in the php array $_SERVER.

for example
if($_SERVER['is_special']) {
echo "Yeah for us!";
} else {

I realize I ask a lot of questions that the answer is no so feel free to say so.

View 2 Replies View Related


what's the difference between them? how to use them. i print_r($_SERVER). there is no result of $_SERVER['PATH_INFO'] and $_SERVER['PORIG_PATH_INFO'] .why? how to enable it.i have read the php manual on them, but still don't understand them.

View 2 Replies View Related


What is the difference between:


View 3 Replies View Related

Determine The Server Path Of A File Of A Class File, From That Class's Parent Class?

I'm trying to find a way to determine the server location of a class from within the class' parent, without hardcoding any values. In other words there is a class called Child.php inside /root/classes/Child/Child.php and it extends Parent.php which is in /root/classes/Parent/Parent.php.

I need a way to have a method inside Parent.php return the path to Child.php

class Parent
// Normal constructor stuff[code]....

View 2 Replies View Related

Track Existing Number Of Objects Of A Given Class Without Introducing A Non-class Member Variable?

i get some collection of solutions please help me to find correct one.
-> add member variable increment in default constructor and decrement in destructor.
-> add local variable that goes incremented in each constructor and decremented in destructor.
-> add static member variable that get incremented in each constructor and decremented in the destructor.
-> cannot be accomplished since the creation of the objects is being done dynamically via "new".

these are my four points select me the best.

View 1 Replies View Related

Class Inheritance In 5.2: Overriding Static Variable In Extension Class?

I need to bea be able to use a static variable set in a class that extends a base class.

class Animal {
public static $color = 'black';
public static function get_color()


This works wonderfully in PHP 5.3.x (Dog::get_color() prints 'brown') since it has late static binding. But my production server runs PHP 5.2.11 and so I need to adapt my script.

EDIT: this is a very much simplified example of what I am trying to accomplish. If I provide you with the two options I have used to solve my problem (and the problem itself) someone might have a different solution than I... I have built a base database model that contains functions like "find", "find_by" and "find_all" (all static).

In PHP 5.3 there is a function called get_called_class() which I currently use to determine the called class's name, and then use it to map against the correct database table. Ex class User would point to users. get_called_class() doesn't exist in PHP 5.2.x and the hack implementations I've found are very unreliable. Then I turned to this option of using a static variable in all model classes which contain the class name.

View 2 Replies View Related

Shared Variable Across Multiple Class Instances That I Can Change Outside The Class?

the code explains it better:

class Class{
$var = 0;

View 4 Replies View Related

Update Variable Of Parent Class From Child Class

I have a function in a child class which counts the number of SQL queries in a page load. In the child class which extends the parent class, after every: mysql_query($query);. I put parent::update_query_function();

where update_query_function() is:
function update_query_function(){

the $query_num variable in the parent class is not being updated. Why?

View 1 Replies View Related

Can't Access The Value Of A Public Variable In A 5 Class From Class Functions?

I'm using CodeIgniter 2.0 with PHP5.3.2 on Apache 2.2.14 with MySQL 5.1.48-community. I created a small test controller to isolate another problem and discovered that my problem appears to be caused by public variable accessibility. Calling test1 or test2 will result in errors because they can't see the value of the array elements set in the other functions. Does anyone have any idea why this doesn't work? If so, what is the solution as I need to be able to access class-wide variables.

class Test extends CI_Controller
public $data;
function __construct()

View 1 Replies View Related

Constant Member Of Class Called Using A Variable Name For The Class

Say, I have a const 'table_name' in derived class Girl. And, I want to get its value in base class Person. I'm currently returning the name of the derived class from a method call to my registry in the base class constructor. So, the below code works fine:

$class_name = $this->registry->loader->get_class_controller_main_name();echo $class_name::table_name; 

However, I was wondering if there's any way to not have to first store the name of the derived class in a variable?

View 1 Replies View Related


If i need to fix the page name from which the click was originated, what is better to fix: $_SERVER['PHP_SELF'] or $_SERVER['HTTP_REFERER']? I mean the click to an external resource.

View 1 Replies View Related


I simply love this site! Hope you all have a great Christmas holiday, and wish everyone have a prosperous 2010!

Anyway, I have a quick question regarding the global variables

View 5 Replies View Related


what's the difference between them? how to use them. i [ICODE]print_r($_SERVER).[/ICODE] there are no result of $_SERVER['PATH_INFO'] and $_SERVER['PORIG_PATH_INFO'] .why? how to enable it.i have read the php manual about them, but still don't understand

View 1 Replies View Related

Calling Class Method Of Variable Class.

Yes, it's the week of OO here in c.l.php

If I want to call the method a class (not an object), one normally uses:

which works fine.

However, what if I don't know the classname yet?
doesn't work, neither does

I've got solved it like this now:

View 1 Replies View Related

Oop - Share Class Variable With A Child Class?

This is a follow up from yesterday's scope I want to share the "$template_instance" variable with a child class.How is this accomplished?


View 2 Replies View Related

Set Class Variable To Apply To All Instances Of Class?

I'm probably asking the question badly, so I'm going to give an example. I have a class that is something similar to this:


My issue is when using this object, the template should always be the same, and the record is what changes for each instance of the object. Is there a way to have the value for $template carry over to each new instance? Something like

$a = new myclass(1,500);
$b = new myClass(2);

Where b has the value for $this->template that was already generated when creating $a. Maybe I'm approaching this from the wrong angle entirely.

View 1 Replies View Related

Class Design - Get The $str Variable (below) Into Class/classes?

How do I get the $str variable (below) into my class/classes? The function is used to call each class dynamically rather tan have "lots" of if(class_exists) statements.

on page:

echo rh_widget('Search');

the function (on functions page):

function rh_widget($str) {[code]...

What I cannot get to happen is to "pull" $str through from the function call through function to the class.

View 1 Replies View Related

Use Main Class Variable In Extended Class?

class a{
$array = array();
class b extends a{
**I need to get that array here !**

use main class variable in extended class?

View 3 Replies View Related

Change Class Variable/function From Outside The Class?

Can I change a function or a variable defined in a class, from outside the class, but without using global variables?this is the class, inside include file #2:

class moo{

View 3 Replies View Related

Save Session Variable Into A Static Class Variable?

Below code works fine:

<?php session_start();

$_SESSION['color'] = 'blue';

class utilities[code]...

I get this error: Parse error: syntax error, unexpected T_VARIABLE in C:Inetpubvhostsmorsemfgco.comhttpdocssecure2scrapclass.php on line 7.Php doesn't like session variables being stored outside of functions. Why? Is it a syntax problem or what? I don't want to have to instantiate objects because for just calling utility functions and I need a few session variables to be stored globally. I do not want to call a init() function to store the global session variables every time I run a function either.

View 2 Replies View Related

Access Global Variable As Static Class Variable?

I have the following class:

class SQLMapper{
static find_user_by_id($id){
//sql logic here, using the $_DATABASE global to make a connection

I could simply call:

global $_DATABASE;

at the top of my function, but I don't want to do that for ALL of my static methods. Is there a way to get a static variable inside my class to reference the global $_DATABASE array?

EDIT: I can't assign it in the constructor, since this is all static, and the constructor is never called.

View 3 Replies View Related

Access A Static Variable For A Class Using A Variable As The Classname?

I need a way to access a static variable for a class using a variable as the classname. Due to how PHP handles static methods and inheritance, I need to access the variable itself and not a static function.

class Item
public static $name = 'parent';


The nature of how PHP handles static methods, an attempt to define a static method in the class Item will always return "parent" instead of "child" if called for the class SubItem.

View 2 Replies View Related

Access Class In Class Variable?

I have this code:

class A
public $db


how can I call a method in class B from class A?

View 2 Replies View Related

Update Class Variable Outside Class

I'm gonna make this too complicated, just going to break it down to the main parts. I have a form that changes the boolean of a variable when the form gets submitted, however it gets called by a function, the function has to change the variable.


So how come I cannot get the variable to print out true in a seperate script?


View 2 Replies View Related

Copyrights 2005-15, All rights reserved