...

View Full Version : Run an else/if query



TrainReq
06-04-2007, 04:56 AM
Alright.. I want to run a query that says if $_SESSION['vip'] = yes ... dont do anything ...

if vip isnt in the session than run a query that says if refferrer is
http://site.com or http://site2.com or http://www.site3.com or http://www.site4.com

, set $_SESSION['vip'] to yes. if not header location to http://www.google.com

How would I go about doing that?

whizard
06-04-2007, 05:03 AM
Try this:

if($_SESSION['vip'] != "yes")
{
$urls = array("site.com","site2.com","site3.com","site4.com");
if(in_array($_SERVER['HTTP_REFERER'],$urls))
{
$_SESSION['vip'] = "yes";
}
else
{
header("Location: http://www.google.com");
}
}

HTH
Dan

TrainReq
06-04-2007, 05:06 AM
I am geting an unexpected "{" around this part



$_SESSION['vip'] = "yes";
}
else

the problem closing point is coming from between the "$_SESSION['vip'] = "yes";" and the "else"

whizard
06-04-2007, 05:12 AM
look at my updated code... the bracket issue was i forgot a closing paranthesis on the if statement, and the referer is fixed.. I forgot for a minute that there was a superglobal for the referer, and I was assuming that you had that defined somewhere

Dan

TrainReq
06-04-2007, 05:17 AM
EDIT: Nvm.. i got it.

TrainReq
06-04-2007, 05:22 AM
Alright.. another thing.. how do i get it to destroy or empty only the $_SESSION['id'] and not the $_SESSION['vip']

whizard
06-04-2007, 05:26 AM
Can you store the value of $_SESSION['vip'] in a database so that when the user logs in, it will pull the stored value?

I think that once you destroy the session ID, it doesn't matter whether other session data was left, since PHP won't have an ID to reference it with. (I could be wrong about that)

HTH
Dan

TrainReq
06-04-2007, 05:31 AM
well.. is it possible to reset the value of a session or empty it? cause i dont feel like dealing with storing things in databases. That or could you go "destory session, then reset the cookie for VIP"

whizard
06-04-2007, 05:38 AM
You could definitely save it as a cookie... that could be a good solution

(Of course, whenever cookies are mentioned there is always someone who brings up the point that people often have cookies turned off, or periodically delete them, so that is something to consider, although I would imagine most people who aren't involved in web dev don't even know how to turn cookies off)

HTH
Dan



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum