Jump to content

Recommended Posts

HI all, I am trying to learn PHP and MYSql been doing it a grand total of 4 Days and enjoying it tbh. I have been playing with superglobals to get used to them but have come across a problem with them which you guys will prob think it's peice of cake but I got to start somewhere eh [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /] .

<?php echo "Hi! Your IP is: $_SERVER['REMOTE_ADDR']"; ?>

Produces : Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING.

I tried something outta my own head but dunno if I did right but still it didn't wortk anywayz.

<?php
$sip = $_SERVER['REMOTE_ADDR'];
echo $sip;
?>

With this I get a variable not assigned error but as far as I was awear superglobals are predfined so didn't think I had to assign a value to $_SERVER, unless there is a problem with assigning $sip the value of a superglobal?

I've tried to find my php.ini to see if globals are switched off but a, they have it hidden i guess and b, I thought that superglobals would still work with that switched off?

any help would be appreciated [img src=\"style_emoticons/[#EMO_DIR#]/wink.gif\" style=\"vertical-align:middle\" emoid=\":wink:\" border=\"0\" alt=\"wink.gif\" /]
Link to comment
https://forums.phpfreaks.com/topic/12619-superglobals-error/
Share on other sites

idk what the problem is, but it's not with your code. at least, the 2nd one. i understand the parse error in the first, but the 2nd one is okay. yes, it should work even if globals are off. this is more of a wild stab in the dark than anything, but try doing

<?php
var $sip;
$sip = $_SERVER['REMOTE_ADDR'];
echo $sip;
?>

i know it shouldn't be necessary, but perhaps there is some setting in .ini that's turned off or something. wish i could help more...
Link to comment
https://forums.phpfreaks.com/topic/12619-superglobals-error/#findComment-48396
Share on other sites

Run this code:
[code]<?phg
phpinfo ();
?>[/code]
Look for a line called [b]Configuration File (php.ini) Path[/b] this will show you the location of the php.ini file. NOTE: if you're on a shared hosting account it is likely you will not be able to access the php.ini to edit it.

Secoundly scroll down a bit further and find [b]register_globals[/b] both columns should state Off, if the right column is set to on then you have register_globals on and thus you cannot use superglobals. Instead you'll have to do this:
[code]echo 'your ip is: ' . $REMOTE_ADDR;[/code]
Link to comment
https://forums.phpfreaks.com/topic/12619-superglobals-error/#findComment-48416
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.