Norman Posted March 8, 2009 Share Posted March 8, 2009 $pt2="http://$SERVER_NAME$SCRIPT_NAME";$pt2= substr($pt2,0,strlen($pt2)-21); I don't understand completely this code. What does the first line do? And.. why it will need to specify the file name lenght (-21)? (http://www.plus2net.com/articles/php_newsletter_script.php) Link to comment Share on other sites More sharing options...
jlhaslip Posted March 9, 2009 Share Posted March 9, 2009 Try this code: <?php$pt2="http://$SERVER_NAME$SCRIPT_NAME";echo $pt2 . '<br />';$pt2= substr($pt2,0,strlen($pt2)-21);echo $pt2 . '<br />';?> The substr() finds a sub-string in a string from a starting point for a given length. In this case, starting at the first (0) character for a length of (string_length minus 21) characters.http://ca3.php.net/substr Link to comment Share on other sites More sharing options...
Norman Posted March 9, 2009 Author Share Posted March 9, 2009 Ok, I understand the second line. Now I still need to understand the first line. In my localhost I get this php error message: Notice: Undefined variable: SERVER_NAME in C:\Programmi\EasyPHP 3.0\www\php-test\index.php on line 46 Why? I know I *should* set those two variables ($SERVER_NAME, $SCRIPT_NAME).. but, how?Maybe it should be like this.. $pt2="http://$_SERVER[SERVER_NAME]$_SERVER[SCRIPT_NAME]"; ? Link to comment Share on other sites More sharing options...
jlhaslip Posted March 9, 2009 Share Posted March 9, 2009 Do you have the $_GLOBALS array available? <?php$pt2="http://$SERVER_NAME$SCRIPT_NAME";echo '$SERVER_NAME : ' . $SERVER_NAME . '<br />';echo '$SCRIPT_NAME : ' . $SCRIPT_NAME . '<br />';echo $pt2 . '<br />';$pt2= substr($pt2,0,strlen($pt2)-21);echo $pt2 . '<br />';echo '<pre>';print_r( $GLOBALS );echo '</pre>';?> Try that script to see what your output is. $SERVER and $SCRIPT_NAME are listed a $_GLOBALS on my output. (As well as in the $_SERVER array.) Link to comment Share on other sites More sharing options...
Norman Posted March 9, 2009 Author Share Posted March 9, 2009 Using that code I get this output. Notice: Undefined variable: SERVER_NAME in C:\Programmi\EasyPHP 3.0\www\php-test\test.php on line 3Notice: Undefined variable: SCRIPT_NAME in C:\Programmi\EasyPHP 3.0\www\php-test\test.php on line 3Notice: Undefined variable: SERVER_NAME in C:\Programmi\EasyPHP 3.0\www\php-test\test.php on line 5$SERVER_NAME :Notice: Undefined variable: SCRIPT_NAME in C:\Programmi\EasyPHP 3.0\www\php-test\test.php on line 6$SCRIPT_NAME :http://Array( [GLOBALS] => Array *RECURSION* [_POST] => Array ( ) [_GET] => Array ( ) [_COOKIE] => Array ( [visits] => 56 ) [_FILES] => Array ( ) [pt2] => ) Link to comment Share on other sites More sharing options...
boen_robot Posted March 11, 2009 Share Posted March 11, 2009 Maybe it should be like this..$pt2="http://$_SERVER[SERVER_NAME]$_SERVER[SCRIPT_NAME]"; ? Close enough... it's more like:$pt2="http://{$_SERVER['SERVER_NAME']}{$_SERVER['SCRIPT_NAME']}"; I don't see why would you want a code that stripts the last 21 characters from a URL though... still, I believe that is what this code is supposed to do. Where did you see it from anyway? Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.