Find Host IP address

  • wpas
  • Proficient
  • Proficient
  • User avatar
  • Posts: 328
  • Loc: Canada

Post 3+ Months Ago

Thanks for your response

Can I still use my if(isset()) function idea.
Not a great programmer so would appreciate how to do this properly

Thanks
  • may
  • Proficient
  • Proficient
  • User avatar
  • Posts: 328
  • Loc: Holland [NL]

Post 3+ Months Ago

Hi Wpas,

I think you isset function will work.
Logic : If var is not set (read is var defined?), then define the variable using the following value. Else do nothing because the var is allready there.

PHP Code: [ Select ]
session_start();
if(!isset($_SESSION{'HTTP_REFERER'})){
       $_SESSION{'HTTP_REFERER'} = $_SERVER{'HTTP_REFERER'};
}
 
  1. session_start();
  2. if(!isset($_SESSION{'HTTP_REFERER'})){
  3.        $_SESSION{'HTTP_REFERER'} = $_SERVER{'HTTP_REFERER'};
  4. }
  5.  


rgrds,
  • wpas
  • Proficient
  • Proficient
  • User avatar
  • Posts: 328
  • Loc: Canada

Post 3+ Months Ago

Hi May

When I first tried it, it did not work.

As I had mentioned before I have a joomla website and it has some issues with standard PHP sessions as it has its own session manager.

However, when I replaced !isset with just !, it worked perfectly.

Thank you for your help
  • may
  • Proficient
  • Proficient
  • User avatar
  • Posts: 328
  • Loc: Holland [NL]

Post 3+ Months Ago

I have seen allot in my days, but your last comment doesnt make any sense.

!$_SESSION{'something'} might trigger and PHP NOTICE message if the var $_SESSION{'something'} isnt defined, this is why you want to test it with isset first.
  • wpas
  • Proficient
  • Proficient
  • User avatar
  • Posts: 328
  • Loc: Canada

Post 3+ Months Ago

Hi May

As mentioned previously, my website is a Joomla CMS site.

Joomla uses their own session management so when you use standard php session it won't work. This is why I had to use the joomla session management.

As everything in Joomla is powered by it's own internal framework, I cannot use pure PHP for something like sessions, as Joomla overwrites old session variables when it initializes it's own internal session management code. Joomla has its own class for session handling that is only applicable inside its system.

For a PHP sesssion we set as:

$_SESSION['name']

For Joomla, we actually have a function to set the session;

$session->set('name', $data)

And to get the session we have another function:

$session->get('name', $data)

To go back to your PHP isset function then, you had to test for the presence of the session:

if(!isset($_SESSION{'name'})){

For joomla, since it is a function, the equivalent would be

If(!$session->get('name', $data)){

Hopefully you see why I changed !isset() to just ! because a function is already used to get the session.
  • may
  • Proficient
  • Proficient
  • User avatar
  • Posts: 328
  • Loc: Holland [NL]

Post 3+ Months Ago

Just glad it works.

I understand that most MVC frameworks will unregister the globals for obvious security related reasons.

I dont now the Joomla internals, and depending on the return values the object method supports your approach might or might not be the right one. Im just glad it worked out for you :)

Rgrds,

Post Information

  • Total Posts in this topic: 36 posts
  • Users browsing this forum: No registered users and 48 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.