View unanswered posts | View active topics It is currently Sun Dec 17, 2017 2:38 pm



Reply to topic  [ 3 posts ] 
 beginner needs help! 
Author Message
Junior Member

Joined: Fri Nov 19, 2004 8:05 am
Posts: 1
Post 
Hi!
I am just approaching php, and I can't find a basic information :(
Suppose I have a true/false condition in my php program: I'd like to evaluate it and make local browser display different pages (i.e. 'true.html' or 'false.html'). How can I do?
Next, I'd like to keep these pages in a non-exposed area of my server...
I know that Apache (i'm using ver. 2.0.52) can manage authentication, but I would prefer solving the problem directly with php.
Thanks a lot,
Muma


Fri Nov 19, 2004 8:30 am
Report this post
Profile
Junior Member

Joined: Tue Apr 13, 2004 11:34 pm
Posts: 16
Location: Gresham, Oregon. United States
Post 
Well, On a properly configured server, the PHP code is never accessable to the visitor - So keeping the 'bounce' pages in an accessable directory is not only pretty secure, its also the easiest way for you to work it.

PHP Syntax is very much like C, so it's pretty simple to pick up. For an example, let's just say you wanted to do it randomly. I know you don't, but it seems like the simplest example I can whip up.

Code:
<?php
if ( rand(1, 2) == 2 )
{
  header("location: false.html");
}
else
{
  header("location: true.html");
}
?>


That will cause a 50/50 chance to get redirected to one of those pages. The HEADER Command modifies the headers Apache (or whatever webserver you use) sends back to the client. When you set the location argument, you turn the whole page into a redirect. None of this code can be seen by the user access the page - In fact, all they should get back is a set of headers.

You might want to Google for some 'Introduction to PHP' tutorials or something similar. Or check out a 'PHP for Dummies' book from your local library - It gives you a real good start, and you should be able to jump right from there into php.net for more information.


Fri Nov 19, 2004 12:09 pm
Report this post
Profile WWW
Junior Member

Joined: Tue Apr 13, 2004 11:34 pm
Posts: 16
Location: Gresham, Oregon. United States
Post 
My apologies, you mentioned you wanted to check it for local browsers. The best way I can think of doing that is by IP address. I'll show you a slightly more complicated script for this, but i'll put comments in it:
(The // are comments)

Code:
<?php
//
// Secure Access Script
//

// Build an array of the legal IP addresses for access
// Change these to whatever you need, or add more. Your choice.
$Allow = array( "127.0.0.1", "127.0.0.1" );

// Fetch the clients IP and store it in MyIP
$MyIP = $_SERVER['REMOTE_ADDR'];

// Is the IP in the Allowed list? If so, kick them to TRUE.HTML
if ( in_array( $MyIP, $Allow ) )
{
  header( "location: true.html" );
}
else
{
  // Otherwise, take them to false.html
  header( "location: false.html" );
}
?>

There. That's a pretty simple solution to the problem. It's not solve all, no would I probably implement this for anything, but that isn't to say that it's not reliable or functional. This might serve your purpose just fine.


Fri Nov 19, 2004 12:14 pm
Report this post
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


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

Search for:
Jump to:  
cron
© Copyright 2003-2008 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.