/    Sign up×
Community /Pin to ProfileBookmark

Define user as Guest – help

I have on each page
script for session:

[code=php]
session_start();
if(!isset($_SESSION[‘logged’]) or $_SESSION[‘logged’] != TRUE)
{
$_SESSION[‘caller’] = $_SERVER[‘PHP_SELF’];
header(‘Location: index.php’);
}
[/code]

How can I define user as guest. So, he can just look for pages and not redirect
to index.php? Please help. ?

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@SheldonOct 01.2005 — you could have this in the top of each page

[code=php]
session_start();
if(!isset($_SESSION['logged']) or $_SESSION['logged'] != TRUE)
{
$_SESSION['caller'] = $_SERVER['PHP_SELF'];
header('Location: page.php?guest=yes');
}

[/code]
then do a check on the page to see if guest is set.
Copy linkTweet thisAlerts:
@SheldonOct 01.2005 — Or better yet start a session as guest.


[code=php]
<?php
session_start();
if(isset($_SESSION['logged']) && $_SESSION['logged'] == 1) {
// DO NOTHING
}
else {
$_SESSION['guest'] = 'Guest';
//start session as a guest.
}
?>
[/code]
Copy linkTweet thisAlerts:
@bokehOct 02.2005 — [code=php]session_start();
if(empty($_SESSION['logged'])){ // if you are checking for boolean true this is all you need
$_SESSION['caller'] = $_SERVER['PHP_SELF'];
header('Location: guest_page.php');
exit; // after a redirect you need to exit so the script stops at that point
} // no need for an else statement

// page content here[/code]
Copy linkTweet thisAlerts:
@toplisekauthorOct 02.2005 — If visitor is redirected to start Guest page (welcome) I would like that each page which is marked as allowed to guest will be visable and visitor will be defined as guest.

What do you think can be changed your script? I have also LgIN page for registered users. I'm new to this. Need help.
Copy linkTweet thisAlerts:
@bokehOct 02.2005 — [code=php]print 'if you are a guest or a logged in user you can read this part';

if(!empty($_SESSION['logged']) and empty($_SERVER['guest'])){
print 'only members can read this part';
}

if(!empty($_SESSION['logged']) and !empty($_SERVER['guest'])){
print 'only guests can read this part';
}[/code]
Copy linkTweet thisAlerts:
@toplisekauthorOct 03.2005 — I would like that registered user can be also as Guest if he decides.

I will show in table what are possibilities:

Guest Non logged Logged

Non registered YES No NO

Registered YES YES YES


So, if registered user clicks on link in page

there will be $_SESSION['guest'] = TRUE;

How to do this with PHP? Please suggest.

I put in guest_page.php following code and Submit button does not work. Please help why.
[code=php]
<?
session_start();
echo 'If you would like to be just Guest please click on Submit&nbsp;';
?>
<FORM>
<br /><center><input type="image" name="guest" src="images/submit.gif" /></center>
</FORM>
<?PHP

if(isset($_POST['submit']))
{
$_SESSION['guest'] = TRUE;
$_SESSION['logged'] = FALSE;
}
else { $_SESSION['guest'] = FALSE;};
?>
[/code]
×

Success!

Help @toplisek spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...