User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 374,546 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,672 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 1204 | Replies: 5
Reply
Join Date: Jul 2005
Posts: 155
Reputation: aparnesh is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 8
aparnesh's Avatar
aparnesh aparnesh is offline Offline
Junior Poster

Question Redirecting - Newbie Question

  #1  
Jun 21st, 2006
How can I redirect a page to another ? For example, if the user is registered he gets to see the members section and if he is not, he is redirected to a 'Register Now' page when he clicks on a members area link.

Also how will it work if he types in the address in the address bar ? For example, he types www.somesite.com/members_area.php. So when this page loads, it checks if the user is logged in. If he is not, it redirects him to a 'Guest' page or something.

The logging in checking can be done by setting a cookie, if I am not mistaken. How can I redirect to a different page or different site ?

I am a newbie at Php, so sorry if this is too trivial.

Regards
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2006
Location: shenzhen CHINA
Posts: 26
Reputation: shaocpa is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
shaocpa's Avatar
shaocpa shaocpa is offline Offline
Light Poster

Re: Redirecting - Newbie Question

  #2  
Jun 21st, 2006
IM interested in PHP.I can solve your question
I think this is a question about "SESSION"
please write out your code
Colin Shao
Reply With Quote  
Join Date: Jul 2004
Location: North East Indiana
Posts: 491
Reputation: Puckdropper is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 20
Puckdropper Puckdropper is offline Offline
Posting Pro in Training

Re: Redirecting - Newbie Question

  #3  
Jun 22nd, 2006
No, it has nothing to do with session. It has everything to do with HTML headers. You can send a header such as refresh using:
header(header field

I haven't looked up the exact syntax (not on my computer with that info at my finger tips) of a redirect, but this'll give you a good place to start.
www.uncreativelabs.net

Old computers are getting to be a lost art. Here at Uncreative Labs, we still enjoy using the old computers. Sometimes we want to see how far a particular system can go, other times we use a stock system to remind ourselves of what we once had.
Reply With Quote  
Join Date: Jun 2006
Location: shenzhen CHINA
Posts: 26
Reputation: shaocpa is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
shaocpa's Avatar
shaocpa shaocpa is offline Offline
Light Poster

Re: Redirecting - Newbie Question

  #4  
Jun 22nd, 2006
redirect a page to another
I know three methods
1 : use header()
for example
<? header("location: $url"); ?>
2: use HTML <META>
for example
<meta http-equiv="refresh" content="5";url=<? echo $url; >>
3: use javascript
for example
<?
echo "<!--<script language='javascript'>";
echo "location.href='$url'";
echo "</script>-->";
?>
AT the same time ,I think it is better if you combine this means with SESSION!
Colin Shao
Reply With Quote  
Join Date: Jul 2005
Posts: 155
Reputation: aparnesh is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 8
aparnesh's Avatar
aparnesh aparnesh is offline Offline
Junior Poster

Re: Redirecting - Newbie Question

  #5  
Jun 22nd, 2006
Thanks a lot.
Reply With Quote  
Join Date: May 2006
Location: Italy
Posts: 9
Reputation: Astegiano is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 1
Astegiano's Avatar
Astegiano Astegiano is offline Offline
Newbie Poster

Re: Redirecting - Newbie Question

  #6  
Jun 22nd, 2006
The best way to set authorization for each page is to use the sessions. The best way to do it is to set two sessions variable: one that contain the level of authorization (for the normal users 1, for moderators 2, the administrator 3) or if you dont want different level just a boolean, the other one that contain the id number of the user that you will need to retrive from the database the user's personal data.

I wrote a very simple function to check the authorization:
[php]function check_auth($lev, $url){
if (@$_SESSION['auth']<$lev) {
header ("Location: http://".ADDRESS.$url);
exit;
}
}[/php]

This function check if the level of authorization contained in the session variable "auth" is lower than the one inserted when the function is used and if it is it redirect to the url decided.
The costant ADDRESS contain the website domain.
This function can be used like this:

[php]
check_auth(1, "/mypage.php");
// To allow any registered user to see this page
check_auth(2, "/mypage.php");
// To allow just user with an authorization level of two[/php]

Usinfg cookie for this purpose wouldn't be secure.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb PHP Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 4:07 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC