Jump to content


Photo

superglobals error


  • Please log in to reply
3 replies to this topic

#1 remzone

remzone
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 22 June 2006 - 07:06 AM

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\" /]

#2 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 22 June 2006 - 07:14 AM

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...
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#3 shortj75

shortj75
  • Members
  • PipPipPip
  • Advanced Member
  • 118 posts
  • LocationPort Huron,mi

Posted 22 June 2006 - 07:27 AM

what type of server are you useing and what is the name of it maybe some one here is useing the same type and can help you find you php.ini so you can check and change what you need
The Short One

hopfully this helps if it doesn't sorry
i won't write the code for you!!! you don't learn that way

#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 22 June 2006 - 09:55 AM

Run this code:
<?phg
phpinfo ();
?>
Look for a line called Configuration File (php.ini) Path 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 register_globals 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:
echo 'your ip is: ' . $REMOTE_ADDR;





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users