Jump to content

brianbayer1

New Members
  • Posts

    5
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

brianbayer1's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. also, if i close the browser, and then log in under a diff name, it works. so how do i stop having to close the browser?
  2. i'm getting a duplicate user_id error here. i wanted to assign a new session id everytime someone logs in. what am i doing wrong? here's the code: <?php $username =$_POST['username']; $password =$_POST['password']; if (strlen($username) <= 25 && strlen($password) <= 25) { mysql_connect('localhost', 'user', 'password'); mysql_select_db('users'); $sql = "SELECT username, password FROM info WHERE username = '$username' AND password = password('$password');"; $result = mysql_query($sql) or die(mysql_error()); $newResult = mysql_fetch_array($result, MYSQL_ASSOC); if ($newResult['password'] = $password) { $_POST['logged'] = true; session_start(); $_SESSION['name'] = session_id(); $session_id = $_SESSION['name']; $_SESSION['username'] = $_POST['username']; $_SESSION['password'] = $_POST['password']; $sql = "UPDATE info SET user_id='$session_id' WHERE username='$username';"; $result2 = mysql_query($sql) or die(mysql_error()); mysql_close(); header("Location: http://localhost/test/members/index.php"); } else { $_POST['not_logged'] = true; header("Location: http://localhost/test/login.php"); } } ?>
  3. i wanna start a session per user from the time they login. i'm learning so i wanna write this myself. So, if i use a class to generate the page a member logs into, can i assume i have to $_POST the session id from page to page or is there a way i can do that in the class? I am afraid when generating new pages that the class will generate a new session id per instance of the class and i don't want that. here is the class i am using(basic i know), and then the code for the page created from it. page_class.php <?php // Page class class Page { // Declare a class member variable var $page; // declare session variable var $PHPSESSID; // The constructor function function Page() { $this->page = ''; } // Generates the top of the page function addHeader($title) { $this->page .= <<<EOD <html> <head> <title>$title</title> </head> <body> <table width="800" border="1" cellspacing="2" align="center"> <tr> <td colspan="2"><p> <h1 align="center">$title</h1> </td> </tr> EOD; } // add navigation function addNav($page1, $page2, $page3, $page4, $page5) { $this->page .= <<<EOD <tr> <td align='center' colspan='2'> <a href='$page1.php'>About Us</a> / <a href='$page2.php'>Contact</a> / <a href='$page3.php'>Register</a> / <a href='$page4.php'>Login</a> / <a href='$page5.php'>home</a> </td></tr> EOD; } // Adds some more text to the page function addContent($content) { $this->page .= <<<EOD <td>$content</td> </tr> EOD; } // adds an image function addImage($attribute, $image, $height, $width) { $this->page .= <<<EOD <tr> <td> <div align='$attribute'><p><img src='../images/$image.jpg' height='$height.px' width='$width.px'><p> </td> EOD; } // Generates the bottom of the page function addFooter($year, $copyright) { $this->page .= <<<EOD <tr><td colspan="2"> <div align="center">© $year $copyright</div> </td></tr></table> </body> </html> EOD; } // Gets the contents of the page function get() { return $this->page; } } ?> index.php created from page class <?php session_start(); // does session_start() carry the sess_id from page to page or // do i need to $_POST it from page to page??????? $username = $_SESSION['username']; $password = $_SESSION['password']; // members only area if ($_POST['logged'] = true) { echo "<b>Members Only Area</b><p>"; require_once 'page_class.php'; // Instantiate the Page class $webPage = new Page(); // Add the header to the page $webPage->addHeader('Know Your Enemy'); // add menu $webPage->addNav(about, contact, register, login, page); // add image $webPage->addImage(center, me, 200, 100); // Add something to the body of the page $webPage->addContent("<p align='center'>Welcome $username</p>\n"); // Add the footer to the page $webPage->addFooter(date('Y'), 'Shamrock Productions LLC'); // Display the page echo $webPage->get(); } else { $_POST['logged'] = !true; header("Location: http://localhost/test/login.php"); } ?>
  4. ok, i am new to both php and mysql. i downloaded the apache2triad from the same name .net i downloaded several books relating to php/mysql web developement and none of them seem to work with mysql 5.0 i can connect to mysql from my page using php, but i can not seem to create tables and fields and such. any books you would recommend for use with wamp? apache2, php5, mysql5 in windows env. secondly, if no books would be available yet, where would you recommend to find how to send queries to mysql5 from php5?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.