Wrox Programmer Forums
|
BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6
This is the forum to discuss the Wrox book Beginning PHP, Apache, MySQLWeb Development by Michael K. Glass, Yann Le Scouarnec, Elizabeth Naramore, Gary Mailer, Jeremy Stolz, Jason Gerner; ISBN: 9780764557446
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 13th, 2004, 12:55 AM
Registered User
 
Join Date: Sep 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Issues with Session_start()

Hi,
I'm facing the following difficulty. I tried the below code. Got to work the first time around. Ever since then I'm not able to get it work again. The $_SESSION['authuser'] or $_SESSION['username'] variable values in movie_site.php are blank, these variables are referenced from movie_1.php file. I have the session_start() in either of the files. I have also set the session.save_path & session.cookie_path appropriately in c:\winnt\php.ini file. And I can see the directory path in phpinfo() listings as well

Please advise.

phpinfo()
1) session.cookie_path c:\php\cookiefiles
2) session.save_path c:\php\sessiondata

Source code as below....

File one movie_1.php

<?php
session_start();
$_SESSION['username']="Joe12345";
$_SESSION['authuser']=1;
?>
<HTML>
<HEAD>
<TITLE>Find my Favorite Movie!</TITLE>
</HEAD>
<BODY>
<?php
     $myfavmovie=urlencode("Life of Brian");
     //echo "<a href='http://localhost/Coding_ini_php/movie_site.php?favmovie=$myfavmovie'>";
     echo "<a href='http://localhost/Coding_ini_php/movie_site.php?favmovie=$myfavmovie&sid=".session_ id()."'>";
     echo "Click here to see information about my favorite movie!";
     echo "</a>";
?>
</BODY>
</HTML>

File two movie_site.php

<?php
session_start();
//check to see if user has logged in with a valid password
     if ($_SESSION['authuser']!=1) {
     echo "Sorry, but you don't have permission to view this page, you loser!";
     exit();
     }
?>
<HTML>
<HEAD>
<TITLE>My Movie Site - <?php echo $_REQUEST['favmovie'] ?></TITLE>
</HEAD>
<BODY>
<?php
     echo "Welcome to our site, ";
     echo $_SESSION['username'];
     echo "! <br>";
     echo "My favorite movie is ";
     echo $_REQUEST['favmovie'];
     echo "<br>";
     $movierate=5;
     echo "My movie rating for this movie is: ";
     echo $movierate;

?>
</BODY>
</HTML>


Preeth Raj Eldhose
 
Old September 13th, 2004, 03:55 PM
Registered User
 
Join Date: Sep 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Furthermore what I noticed was, the movie_site.php stopped getting the $_SESSION['username'] & $_SESSION['authuser'] values once I add setcookie('username', 'Joe', time()+60); line on to movie_1.php source code.

Summary: I believe once I use setcookie('username', 'Joe', time()+60); with in movie_1.php which was an addition I made to the code, the issue I face is movie_site.php's if statement becomes true. In the sense the $_SESSION['authuser'] & $_SESSION['username'] are not available in movie_site.php. Although I have used the syntax which is appropriate when register_globals=Off & phpinfo() points to the correct path of both session.save_path & session.cookie_path (both with write to privilleges I have the issue of if failing. Please advice.

movie_1.php source code again with the inclusion of setcookie()
<?php
setcookie('username', 'Joe', time()+60);session_start(); //New line added
$_SESSION['username']="Joe12345";
$_SESSION['authuser']=1;
?>

<HTML>
<HEAD>
<TITLE> Find my Favourite Movie!!! </TITLE>
</HEAD>
<BODY>
<?php
    $myfavmovie=urlencode("Life is Brian");
    echo "<a href='http://localhost/codinginphp/Movie_site.php?favmovie=$myfavmovie'>";
    echo "Click on the link to see the information";
    echo "</a>";
?>
</BODY>
</HTML>


movie_site.php source code

<?php
session_start();
    if($_SESSION['authuser']!=1) { //$_SESSION['authuser'] is blank hence the loop is executed. The value for $_SESSION['authuser'] is set on movie_1.php with register_globals=Off & the syntax used is appropriate. Once setcookie(...) is used as shown within movie_1.php, if statement becomes true.And then I can't get this to work or get the value for $_SESSION['authuser']. Please advise. echo "Sorry!!!";
         exit();
    }
?>

<HTML>
<HEAD>
<TITLE> My Movie Site - <?php echo $_REQUEST['favmovie'] ?></TITLE>
</HEAD>
<BODY>

<?php
    echo "Welcome to our site, ";
    echo $_SESSION['username'];
    echo "! <br>";
    echo "My favourite movie is ";
    echo $_REQUEST['favmovie'];
    echo "<br>";
    $movierate=5;
    echo "My Movie rating for this movie is: ";
    echo $movierate;
?>
</BODY>
</HTML>


Preeth Raj Eldhose





Similar Threads
Thread Thread Starter Forum Replies Last Post
Warning: session_start(): tanybrw989 Beginning PHP 9 May 10th, 2009 06:16 PM
connection string issues, web.config file issues kaliaparijat ASP.NET 2.0 Professional 1 June 12th, 2008 08:07 AM
session_start() changusee2k PHP How-To 2 February 11th, 2006 05:32 AM
Problem with session_start() jmrdeuce32 Beginning PHP 4 May 8th, 2005 05:09 PM
Problem with Session_Start() jmrdeuce32 PHP How-To 2 April 29th, 2005 12:32 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.