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

Apr 18, 2011

I have a simple class like this:

<?php
class packet {
private $SERVER = "192.168.1.100";
}
?>

This works fine on localhost but on the server the $SERVER variable needs to be "72.20.32.58" 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 returns.how I could set the $SERVER variable to $_SERVER['SERVER_ADDR'] in the class?

ADVERTISEMENT

Cron With $_SERVER[REMOTE_ADDR] And $_SERVER[SERVER_ADDR]

Mar 28, 2011

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 "123.123.123.123", 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'] = '127.0.0.1';

Dec 28, 2005

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

Using $_SERVER[SERVER_ADDR] In SRC Url?

Aug 30, 2006

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?

Mar 4, 2007

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

View 9 Replies View Related

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

Apr 20, 2011

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:

index.php

<?php
require_once("startup.php");
class NotIndex extends View
{[code]...

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

startup.php

<?php
require_once("view.php");
//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.

UPDATE:

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.

startup.php

//Include the script again to bring in the class definition
include($_SERVER['SCRIPT_FILENAME']);

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

UPDATE 2:

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.

<?php
require_once("view.php");
//Include the script again to bring in the class definition
include($_SERVER['SCRIPT_FILENAME']);[code]....

View 2 Replies View Related

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

Jan 29, 2010

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

Check my below code

<?php
class ModifyProfile
{
var $userType=$_SESSION['wb_user_type'];

[code].....

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?

Jan 21, 2009

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?

Oct 3, 2009

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)

Jul 16, 2005

I'm attempting to use JpGraph (http://www.aditus.nu/jpgraph/index.php) 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')) {
DEFINE('CACHE_DIR', $_SERVER['TEMP'] . '/');
} else {
DEFINE('CACHE_DIR','/tmp/jpgraph_cache/');
}
}

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:

....
PATH=C:WINDOWSsystem32;C:WINDOWS;C:WINDOWSSys tem32Wbem;C:WINDOWSsyst
em32
ls;C:WINDOWSsystem32
lsENGLISH;C:java in;C:Perlin;C:php;C:m
ysqlin;C:Program FilesSSH Communications SecuritySSH Secure Shell;Z:.;
....
TEMP=C:WINDOWSTemp
....

'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

Aug 15, 2005

<?php

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

Dec 19, 2003

Can someone tell me what is wrong with this please:

//create the login form
$loginform .= '<table width="300" border="2" align="center">
<tr>
<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" />
Password</p>
<p align="left">
<input type="submit" name="Submit" value="Submit" />
</p>
</form></td>
</tr>
</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']?

Sep 18, 2009

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?

Sep 6, 2010

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?

Aug 29, 2010

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

Opendir With $_SERVER['HTTP_HOST'] Or $_SERVER['DOCUMENT_ROOT']

Oct 20, 2003

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?

Mar 4, 2009

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 {
[code]...

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

View 2 Replies View Related

Apache - $_SERVER PATH_INFO And $_SERVER PORIG_PATH_INFO'?

Apr 12, 2011

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

Difference Between: $_SERVER SCRIPT_NAME And $_SERVER PHP_SELF?

Jun 24, 2011

What is the difference between:

$_SERVER['SCRIPT_NAME']
and
$_SERVER['PHP_SELF']

View 3 Replies View Related

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

Mar 25, 2011

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?

Dec 23, 2010

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?

Jun 10, 2010

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()

[code]....

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?

Jul 4, 2011

the code explains it better:

class Class{
$var = 0;
[code]........

View 4 Replies View Related

Update Variable Of Parent Class From Child Class

Sep 24, 2010

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(){
$this->query_num++;
}

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?

Apr 1, 2011

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.

<?php
class Test extends CI_Controller
{
public $data;
function __construct()
{
parent::__construct();
[Code].....

View 1 Replies View Related

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

Jul 14, 2010

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

$_SERVER['PHP_SELF'] Or $_SERVER['HTTP_REFERER']?

Jan 11, 2005

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

Get Value $_SERVER['REMOTE_ADDR'] And/or $_SERVER REMOTE_HOST?

Dec 28, 2009

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
$_SERVER['REMOTE_ADDR'] and/or $_SERVER['REMOTE_HOST']
[code]...........

View 5 Replies View Related

$_SERVER['PATH_INFO'] And $_SERVER['PORIG_PATH_INFO']?

Apr 11, 2011

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.

Aug 18, 2006

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:
classname::method();

which works fine.

However, what if I don't know the classname yet?
$classname::method();
doesn't work, neither does
{$classname}::method();

I've got solved it like this now:
call_user_func(array($classname,'method'));

View 1 Replies View Related

Oop - Share Class Variable With A Child Class?

Jul 22, 2010

This is a follow up from yesterday's scope question.stackoverflow.com/questions/3301377/class-scope-question-in-phpToday I want to share the "$template_instance" variable with a child class.How is this accomplished?

require_once("/classes/Conf.php");
require_once("/classes/Application.php");
[code]....

View 2 Replies View Related

Set Class Variable To Apply To All Instances Of Class?

Mar 4, 2010

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:

[code]...

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?

Nov 25, 2010

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?

Sep 4, 2010

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?

Feb 10, 2011

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{
[code]...........

View 3 Replies View Related

Save Session Variable Into A Static Class Variable?

Oct 13, 2009

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?

Nov 11, 2009

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?

Mar 10, 2011

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';
}

[code]...

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?

Jun 4, 2011

I have this code:

class A
{
public $db
}

[code]...

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

View 2 Replies View Related

Update Class Variable Outside Class

Mar 16, 2011

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.

[code]...

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

[code]...

View 2 Replies View Related

Run Page On WAMP Server Which Include Session Variable But It Is Giving An Error : Undefined _SESSION Variable?

Aug 4, 2010

I am trying to run my live page on WAMP server which include session variable but it is giving a Error:undefined _SESSION variable

View 2 Replies View Related

Store The Code In A Variable And Have That Variable String Parsed By The Server?

Apr 23, 2009

I've created a "CMS" of sorts for a project I'm working. I created 1 template page and then pass variables to it for the menu, header, and content. I'm liking using a database to store the content because I can store secure=true/false and public=true/false with each portion of content. From that there is no way to view secure content without passing the security_check.php. Also adding and changing content is a lot easier.

The issue I'm having is some of my content has php code in it. I.E.:

PHP Code:

<input type=text value="<? echo $_POST['name']; ?>"> 

All that is being output as plain text rather than being parsed by the server. Is there any way to store the code in a variable and have that variable string parsed by the php server?Something else I've played with is storing content in separate files and including them as needed in the template. I can make this work as well but I can't get include to use a variable. I.E.:

PHP Code:

 $content = "/content.php";
include ($content);

View 8 Replies View Related

$_SERVER['PHP_SELF'] Vs $SERVER[PHP_SELF]

May 23, 2003

I am moving a script to a different server.

This works on the old server $_SERVER ['PHP_SELF '] but not on the new.

If I do it this way on the new it works $_SERVER[PHP_SELF].

I was up rather late last night attempting to figure this out.

Any help would certainly be appreciated as I fear it is something obvious to everyone but me.

View 5 Replies View Related

Class - Variable That Points To Another Variable?

Apr 19, 2010

Was wondering if it is possible to make a variable point to another variable instead of having it have a value of its own. What I'm trying to do is to have a class instance like:

$users = new User_Model();
and then have
$user
simply point to
$users

instead of making a new class instance. Is this possible? Think I saw something about it in the php manual, but cant find it..

Would
$users = new User_Model();
$user = $users;

simply do it or is somehow possible (as I've asked above) to make $user act simply as a "wormhole" to $users?

View 2 Replies View Related

Turning Variable Into Class Variable?

Dec 30, 2010

In my PHP class I have

public $a;
public $b;
public $c;
public $d;

and I set there values in the construct. I am now attempting to write a update function, and i'm trying to check if they are updating, say $a, to be the same as it is.

function update($what, $to) {
if ($to == $this->what) return false;
...
}
$updated = $instance->update($a, "Foobar");
if ($updated) echo "Updated";
else echo "You didn't change the value";

but since I know this line

if ($to == $this->what) return false;

View 3 Replies View Related

ADVERTISEMENT