Log in

View Full Version : Need some help with a PHP script for my user system.



benzie852
04-07-2007, 04:28 PM
Hello,

Ok i got this script that hides any content if your not logged in, as it checks if username is active *code below*:


if($_SESSION["s_username"]

if the username is logged in it will display the content that is wrapped in between "?>" and "<?php } ?>". heres an example below:


<?php

if($_SESSION["s_username"]){


?>

<p><DIV class=content-page-register style="width: 342px; height: 2px">
<font color="#808080">Welcome Back, <?php echo $_SESSION['s_username'] ?>!</font></DIV></p>

<?php } ?>

And that would display "if logged in" (Welcome Back, Username!).

But what i am after is that while it hides the content i want it to display a message something like:

"You must be registered or logged in, to use this feature" but i don't know what statement i would need to use to display that ? Any help would be very much appreciated :).

Thanks,
Ben

thetestingsite
04-07-2007, 04:31 PM
Try adding this to your script (the part in red):



<?php

if($_SESSION["s_username"]){


?>

<p><DIV class=content-page-register style="width: 342px; height: 2px">
<font color="#808080">Welcome Back, <?php echo $_SESSION['s_username'] ?>!</font></DIV></p>

<?php }

else {
?>
<p><DIV class=content-page-register style="width: 342px; height: 2px">
<font color="#808080">You must be registered or logged in, to use this feature!</font></DIV></p>
<?php
}
?>



Hope this helps.

benzie852
04-07-2007, 04:35 PM
Thanks thetestingsite,

That worked great!

And thanks for the help :)

Ben

thetestingsite
04-07-2007, 04:35 PM
No problem, let us know if you need any more help.

benzie852
04-07-2007, 05:11 PM
Well this another thing, that i got a comment system for my news articles.
But the problem lays on the date & time posted, it displays the date correctly but the time and timezone are posted incorrectly as it will display PDT timezone. And i don't know how it make it use GMT timezone.

This is how it's echoed:


<input type="hidden" name="posted" value="<?php echo date("F j, Y, g:i a T"); ?>">

Any ideas why it's using PDT timezone? and any ideas how to fix this?

Any help would be appreciated! :)

Ben

thetestingsite
04-07-2007, 05:16 PM
Is your server hosted in the PDT timezone? If so, that is the reason why it is displaying like so. A fix would be to use gmdate, an example is like so:



echo gmdate("F j, Y, g:i a T", time());


Hope this helps.

benzie852
04-07-2007, 05:22 PM
Thanks,

But the problem is that now its displaying the wrong time like an hour behind this is what i just got when i posted a comment:

April 7, 2007, 5:18 pm GMT

Which it should of been 6:18pm

i know it would be something like GMT+1, something like that.

Ben

thetestingsite
04-07-2007, 05:23 PM
It may be due to daylight savings time or something to that effect. Other than that, it should be fine.
Hope this helps.

benzie852
04-07-2007, 05:25 PM
Thanks for your help :)

It's probably due to that clocks went back, but i could be wrong but im happy with it. And it isn't a big issue to be honest so thanks anyways!

Ben