canadabeeau Posted December 20, 2009 Share Posted December 20, 2009 Okay I have a page index.php which has an if statement basically like this: if $var == "" then redirect else do nothing Now it redirects to loading.php now my question is that how do I make a session variable remember this page so when the person goes to loading.php and it does its functions as required they can be redirected back to that page, I ask becuase this action will take place on all pages in my website so yeah.... and as always thanks in advance, and this time season greetings as well :-) Link to comment https://forums.phpfreaks.com/topic/185747-if/ Share on other sites More sharing options...
nafetski Posted December 20, 2009 Share Posted December 20, 2009 Well, you can do it a few different ways. Most important part about using sessions (that a lot of people forget) is you need to tell PHP that you're USING sessions At the very very very beginning of your script. I'm not 100% sure what your logic is, but something like this might get you started. <?php session_start(); $_SESSION['var'] = $var; if($_SESSION['var'] == ""){ // redirect } ?> Link to comment https://forums.phpfreaks.com/topic/185747-if/#findComment-980780 Share on other sites More sharing options...
canadabeeau Posted December 20, 2009 Author Share Posted December 20, 2009 knew how to do the if part but not the remember the pages URL part Link to comment https://forums.phpfreaks.com/topic/185747-if/#findComment-980782 Share on other sites More sharing options...
nafetski Posted December 20, 2009 Share Posted December 20, 2009 Ohhhh ok There is a PHP SERVER variable that you can check against, to see if they are coming from your index page. $_SERVER['REQUEST_URI'] So... if($_SERVER['REQUEST_URI'] == "index.php"){ // redirect logic } Link to comment https://forums.phpfreaks.com/topic/185747-if/#findComment-980784 Share on other sites More sharing options...
canadabeeau Posted December 20, 2009 Author Share Posted December 20, 2009 $loc = $_SERVER['REQUEST_URI']; echo $loc; If I run the above and echo it on the page that index.php redirected to it says $loc is the page I am on Link to comment https://forums.phpfreaks.com/topic/185747-if/#findComment-980792 Share on other sites More sharing options...
nafetski Posted December 20, 2009 Share Posted December 20, 2009 Oops, meant $_SERVER['HTTP_REFERER']; Link to comment https://forums.phpfreaks.com/topic/185747-if/#findComment-980795 Share on other sites More sharing options...
canadabeeau Posted December 20, 2009 Author Share Posted December 20, 2009 now it echo s nothing Link to comment https://forums.phpfreaks.com/topic/185747-if/#findComment-980798 Share on other sites More sharing options...
nafetski Posted December 20, 2009 Share Posted December 20, 2009 I guess I'm not 100% sure what you're trying to do. http://php.net/manual/en/reserved.variables.server.php Here are the variables that are available from the server. See if any of those suit your fancy, or post a bit more code so I can know what you're trying to accomplish Link to comment https://forums.phpfreaks.com/topic/185747-if/#findComment-980799 Share on other sites More sharing options...
canadabeeau Posted December 20, 2009 Author Share Posted December 20, 2009 Okay index.php <?php if($_SESSION['clientmac'] == ""){ header('location: clientmac.php'); };?> clientmac.php then does its job and then we have <?php $loc = $_SERVER['HTTP_REFERER']; echo $loc;?> so it should echo index.php and later I can change the echo to a redirect Link to comment https://forums.phpfreaks.com/topic/185747-if/#findComment-980800 Share on other sites More sharing options...
teamatomic Posted December 20, 2009 Share Posted December 20, 2009 $path=$_SERVER['SCRIPT_FILENAME'];//give you the whole thing basename($path);// give you the file name HTH Teamatomic Link to comment https://forums.phpfreaks.com/topic/185747-if/#findComment-980811 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.