Re: [PHP] Newbie question about good coding practice [isset]
When $var is 0? ? $var = 0; // Output: $var: $var not exists if ( $var ) echo '$var: $var existsbr'; else echo '$var: $var not existsbr'; // Output: isset(): var exists if ( isset($var) ) echo 'isset(): $var existsbr'; else echo 'isset(): $var not existsbr'; ? Larry E . Ullman wrote: if($var) do something; verses if(isset($var)) do something; The simple form if($var) seems to work fine and I see it in code often. Is there a good reason for using isset? Yes, if you don't use isset(), you may see notices (errors) if the variable is not set. This depends upon the error reporting settings of the server. However, if you use isset() you won't see notices regardless. Larry -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Understanding sessions
You can use $sid = session_name().'='.session_id(); instead of SID or you can define o constant define('SID', session_name().'='.session_id()); at the start of script ( after session_start() ). Todd Cary wrote: I am trying to understand sessions are done with php. My learning script has the following: session_start(); if (isset($_SESSION['firstname'])) { $_SESSION['firstname'] = 'Todd'; } else { $_SESSION['firstname'] = 'Nobody'; } echo SESSION: . $_SESSION['firstname'] . br; echo 'SID: ' . SID . 'br'; echo 'br /a href=page_2.php?' . SID . 'page 2/a'; SID is always empty. What have I missed? Todd -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: combining variables...
$i = 2; $var = view_request_$i; $value = $$var; Tristan Pretty wrote: Simply put, can I connect 2 variables, to make one... I want to output: $view_request_$i making for example a string: view_all_2 But I'm getting errors..? Parse error: parse error in /home/risk/public_html/download/results3.php on line 675 is there a simple explination...? * The information contained in this e-mail message is intended only for the personal and confidential use of the recipient(s) named above. If the reader of this message is not the intended recipient or an agent responsible for delivering it to the intended recipient, you are hereby notified that you have received this document in error and that any review, dissemination, distribution, or copying of this message is strictly prohibited. If you have received this communication in error, please notify us immediately by e-mail, and delete the original message. *** -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Wrong IP address
I'm using this one: function FetchIP() { $client_ip = $_SERVER['HTTP_CLIENT_IP']; $x_forwarded_for = $_SERVER['HTTP_X_FORWARDED_FOR']; $remote_addr = $_SERVER['REMOTE_ADDR']; if ( !empty ($client_ip) ) { $ip_expl = explode('.',$client_ip); $referer = explode('.',$remote_addr); if($referer[0] != $ip_expl[0]) { $ip=array_reverse($ip_expl); $return=implode('.',$ip); } else { $return = $client_ip; }; } elseif ( !empty($x_forwarded_for) ) { if(strstr($x_forwarded_for,',')) { $ip_expl = explode(',',$x_forwarded_for); $return = end($ip_expl); } else { $return = $x_forwarded_for; }; } else { $return = $remote_addr; }; unset ($client_ip, $x_forwarded_for, $remote_addr, $ip_expl); return $return; } Ascll wrote: Greetings, I make use of these: - ?php echo($_SERVER[REMOTE_ADDR]); ? to get the web IP address for my machine once my PC is connected to Internet.. Anyway, sometime I get the correct IP address, but sometime NOT. Does anyone know why? Thanks in advance. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Relative Url
I'm using this on Apache. You need to include 'inc/globals.php' in your script. inc/globals.php ? require_once('functions.php'); define('RELPATH', GetRelativePath()); ? inc/functions.php function GetRelativePath() { $RELPATH = str_replace(UpDirectory(__FILE__), '', dir_name($_SERVER['SCRIPT_NAME])); $RELPATH = substr_count($RELPATH, '/'); if ( $RELPATH0 ) $RELPATH = str_repeat('../', $RELPATH); else $RELPATH = '/'; return ConvertSlashes($RELPATH); } function UpDirectory($directory, $level=1) { while ( $level-- 0 ) $directory = dirname(dirname($directory)); return ConvertSlashes($directory); } function ConvertSlashes($st) { $st = str_replace('', '/', $st); $st = str_replace('\\', '/', $st); return $st; } function dir_name($directory) { return ConvertSlashes(dirname($directory)); } Chris Thomas wrote: Is there anyway that i can get a url relative to my server for a script that is being run?? The script is being included in mulitple files and $_SERVER['SCRIPT_NAME'] just gives me the name of the file that is including the other scripts. Also $_SERVER['SCRIPT_FILENAME'] is returning nothing. Thanks Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php