Board index   FAQ   Search  
Register  Login
Board index PHP PHP Scripts

PHP Session

Links for php scripts

Moderators: macek, egami, gesf

PHP Session

Postby bobbygerez » Thu Feb 09, 2012 9:22 am

Hi everyone, I'm having problem how to create session. I've been searching but no luck.

Code: Select all
if($count==1){
      // Register $myusername, $mypassword and redirect to file "login_success.php"
      
      session_register("myusername");
      session_register("mypassword");
      header("location:login_success.php");
         
         }
         
          else {
         
         echo "Wrong Username or Password";
         }


login_success.php
Code: Select all
<?
session_start();
if(!session_is_registered(myusername)){
header("location:login.php");
}
?>
<html>
<body>
<a href="logout.php">logout</a>
</body>
</html>


logout.php
Code: Select all
<?
session_start();
session_destroy();
?>


If I click the logout then return to login_success.php, still it doesn't redirect to login.php. I don't know if the session is correct or I'm just missing something. Thanks.
bobbygerez
New php-forum User
New php-forum User
 
Posts: 18
Joined: Mon Jan 23, 2012 7:40 pm

Re: PHP Session

Postby bobbygerez » Thu Feb 09, 2012 6:37 pm

I don't know what is going on I tried this code.
Code: Select all
if($count==1){
      // Register $myusername, $mypassword and redirect to file "login_success.php"
      
      $_SESSION['test'] = "hi";
      header('location:welcome.php');
      
         
         }

welcome.php
Code: Select all
<?php
session_start();
echo $_SESSION['test'];
?>


Works fine in chrome but not in mozilla. Please help!
bobbygerez
New php-forum User
New php-forum User
 
Posts: 18
Joined: Mon Jan 23, 2012 7:40 pm

Re: PHP Session

Postby bobbygerez » Thu Feb 09, 2012 6:53 pm

Thanks anyway guys, I have figured it out!

Code: Select all
                session_start();
      $_SESSION['test'] = $_POST['username'];
      header('location:welcome.php');


I keep trying it since midnight but glad I have figured it out.
bobbygerez
New php-forum User
New php-forum User
 
Posts: 18
Joined: Mon Jan 23, 2012 7:40 pm


Return to PHP Scripts

Who is online

Users browsing this forum: No registered users and 0 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron