Snooble Posted January 30, 2007 Share Posted January 30, 2007 [code] <?php if($_SESSION['myemail']){ echo "Logged in as <strong>$_SESSION['fname'] $_SESSION['sname']</strong>. <br />Click here to log out";}else{echo '<a href="loginotd.php" target="mainpage">Login</a><br /> <a href="javascript:void window.open('register.php','Checkout','status=no, scrollbars=1, height=790, width=560')">Register</a>';} ?>[/code]I cant see it... I'm going blind i swear.Snooble Quote Link to comment Share on other sites More sharing options...
HuggieBear Posted January 30, 2007 Share Posted January 30, 2007 You're better off using something like isset()[code]<?php if (isset($_SESSION['myemail'])){ echo "Logged in as <strong>$_SESSION['fname'] $_SESSION['sname']</strong>. <br />\nClick here to log out";}else{ echo <<<HTML <a href="loginotd.php" target="mainpage">Login</a><br /> <a href="javascript:void window.open('register.php','Checkout','status=no, scrollbars=1, height=790, width=560')">Register</a>HTML;}?>[/code][b]Edit:[/b] Code correctedRegardsHuggie Quote Link to comment Share on other sites More sharing options...
Snooble Posted January 30, 2007 Author Share Posted January 30, 2007 lol i love you. Thank you once again. On my old thread i was told to use IF. But i get a blank page, so i assume there's a problem.Snooble :D Thanks Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 30, 2007 Share Posted January 30, 2007 Your second echo is still messed up though. Look at the post, see where the colors go all funky? You need to escape quotes. Quote Link to comment Share on other sites More sharing options...
Snooble Posted January 30, 2007 Author Share Posted January 30, 2007 yes you are right. i'll have a play in dreamweaver. Thanks for that. I was just about to repost :)I just assumed Huggy had it. Close! Will play around, thanks!Snooble Quote Link to comment Share on other sites More sharing options...
HuggieBear Posted January 30, 2007 Share Posted January 30, 2007 Sorry, I just copied and pasted your code for that bit. Didn't check it.Corrected the easy way! ;)Huggie Quote Link to comment Share on other sites More sharing options...
Snooble Posted January 30, 2007 Author Share Posted January 30, 2007 right...I have some trouble i've taken out the last echo and just put "ndawodw" in its place. It still wont show the page. I assume the first statement must mess it up too..Snooble Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 30, 2007 Share Posted January 30, 2007 Do you have session_start() at the top of the page? Try this and see where you get:<?php if (isset($_SESSION['myemail'])){ echo 'test1';}else{ echo 'test2';}?> Quote Link to comment Share on other sites More sharing options...
Snooble Posted January 30, 2007 Author Share Posted January 30, 2007 I get the output :test2So its not set. I dont have session start at the top lol (should i be embarrassed) this is my first time using sessions mysql. Could you explain? Should i create a page to include in each page's header?Snooble Quote Link to comment Share on other sites More sharing options...
HuggieBear Posted January 30, 2007 Share Posted January 30, 2007 You must have [url=http://uk.php.net/manual/en/function.session-start.php]session_start()[/url] at the top of every page that uses sessions. It has to appear before anything gets output to the browser.A quick read up on [url=http://uk.php.net/manual/en/ref.session.php]PHP's Sessions[/url] should help out hereRegardsHuggie Quote Link to comment Share on other sites More sharing options...
Snooble Posted January 30, 2007 Author Share Posted January 30, 2007 so in the header at the top before the styles i should add:<?phpsession_start()*Now what? Variables??>what do i put beneath session_start? I am learning... honestly. Thank you so much Snooble Quote Link to comment Share on other sites More sharing options...
HuggieBear Posted January 30, 2007 Share Posted January 30, 2007 That's pretty much it for initialising sessions, just session_start() but I'd certainly advise reading the manual.RegardsHuggie Quote Link to comment Share on other sites More sharing options...
HuggieBear Posted January 30, 2007 Share Posted January 30, 2007 [quote author=Snooble link=topic=124619.msg516659#msg516659 date=1170116881]I am learning... honestly. Thank you so much [/quote]My advice in that case is to always have the PHP manual open beside your code. As far as I'm concerned, it's the best manual of any programming language I've ever worked with.The main page is here: http://uk.php.net/manual/en/index.php (UK Mirror)And from there you can type in any function name in the box at the top right of the page and be taken straight to the details of it.RegardsHuggie Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 30, 2007 Share Posted January 30, 2007 "what do i put beneath session_start? "The rest of your code.Huggie: you know you can even just do php.net/function and it goes right to it? (I'm a sucker for any shortcuts)so php.net/array is for arrays, php.net/substr, etc. Quote Link to comment Share on other sites More sharing options...
Snooble Posted January 30, 2007 Author Share Posted January 30, 2007 I'm reading it as we speak. But it all seems so confusing :S.I have the login box working. But i dont know what happens after that. When i type session_start();if i was logged in would it be able to post the firstname and second name that are stored in the database? Thank you Huggy.Snooble Quote Link to comment Share on other sites More sharing options...
HuggieBear Posted January 30, 2007 Share Posted January 30, 2007 [quote author=Snooble link=topic=124619.msg516667#msg516667 date=1170117265]if i was logged in would it be able to post the firstname and second name that are stored in the database? [/quote]On your login page once you've authenticated a user, you can assign their details into session variables, then by placing session_start() at the top of any of your other pages on your site, you can retrieve those variables using the global $_SESSION array...[b]login.php[/b][code]<?php// Start the sessionsession_start();// Get my user details from the form$user = $_GET['frmUser'];$pass = $_GET['frmPass'];// My database query to authenticate the user would go here$sql = "SELECT real_name FROM users WHERE ....."; // get the idea// Process the query here with mysql_query()$result = mysql_query($sql) or die ("Unable to execute $sql: " . mysql_error());// Put the persons real name into a session variable$details = mysql_fetch_array($result, MYSQL_ASSOC);$_SESSION['name'] = $details['real_name'];?>[/code]Now to echo that on page two all I do is this:[b]page2.php[/b][code]<?php// Start the session againsession_start();// Check for usernameif (isset($_SESSION['name'])){ echo "Welcome " . SESSION['name']}else { header('Location: login.php');}?>[/code]RegardsHuggie Quote Link to comment Share on other sites More sharing options...
Snooble Posted January 30, 2007 Author Share Posted January 30, 2007 I will give it a go tomorrow morning. Thank you very much. Good night. If this will help: "login.php"[code]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Untitled Document</title><style type="text/css"><!--.style21 {font-family: ADMUI3Lg, serif, monospace, cursive; font-weight: bold; font-size: 16px; color: #FFFFFF; }body { margin-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px;}.style22 { color: #000000; font-size: 14px;}.style25 {font-size: 9px; color: #fbedc7; }.style26 {font-size: 14px}.style27 {color: #fbedc7}.style28 {color: #000000}.style29 { font-size: 10px; color: #FF0000;}.style30 {font-size: 9px}.style31 { font-size: 11px; color: #CCCCCC;}.style32 {font-size: 1px}.style34 {color: #000000; font-size: 12px; }.style36 {font-size: 13px}.style37 { color: #FFFFFF; font-size: 1px;}--></style></head><body> <form method="post" action="checklogin.php"><table width="100%" height="100%" border="0"> <tr> <td height="25" background="Untitled-4.gif"><div align="center"><span class="style21">Login </span></div></td> </tr> <tr> <td valign="top"><table width="100%" height="0%" border="0" cellpadding="0" cellspacing="0"> <tr> <td height="5" colspan="4" valign="top"><span class="style37">.</span></td> </tr> <tr> <td height="21" colspan="4" valign="top" background="fbedc7.gif"> </td> </tr> <tr> <td width="552" height="56%" valign="middle" background="fbedc7.gif"><div align="right"><span class="style22"> Email Address </span><span class="style26"><br /> <span class="style27">s</span><br /> <span class="style28">Passwor<span class="style22">d</span><span class="style22"> </span><span class="style22"> </span> </span></span></div></td> <td width="5" valign="top" background="fbedc7.gif"> </td> <td width="375" valign="top" background="fbedc7.gif"><input type="text" name="myemail" /> <br /> <span class="style25"> s </span> <br /> <input type="password" name="mypassword" /></td> <td valign="top" background="fbedc7.gif"> </td> </tr> <tr> <td height="12%" align="center" valign="middle" background="fbedc7.gif"><div align="right"><span class="style30"><span class="style31">Remember Me</span> <input name="radiobutton" type="radio" value="radiobutton" /> </span></div></td> <td height="12%" colspan="2" align="center" valign="middle" background="fbedc7.gif"><span class="style29"><a href="retrievepassword.php">Forgot Your Password?</a></span></td> <td width="294" valign="top" background="fbedc7.gif"><div align="center"> <input type="submit" name="Submit" value="Login"> </div></td> </tr> <tr> <td height="8" colspan="4" align="center" valign="middle" bgcolor="#FFFFFF"><span class="style37">a</span></td> </tr> <tr> <td height="25" colspan="4" align="center" valign="middle" background="Untitled-4.gif"><span class="style21">Security Notice </span></td> </tr> <tr> <td height="4" colspan="4" align="center" valign="middle" bgcolor="#FFFFFF"><span class="style32"> a </span></td> </tr> <tr> <td height="110" colspan="4" align="center" valign="middle" background="fbedc7.gif" bgcolor="#FFFFFF"><div align="left" class="style34"> <div align="center"><span class="style27">.</span><br /> <span class="style36">1. Look for http://www.onetimedeals.co.nr in the URL box.<br /> <br /> 2. Never give out your password to anyone. We will never ask for it, EVER.<br /> <br /> 3. If you feel you are not secure on our site at any time please ring us immeadiatly.</span><br /> <br /> <br /> </div> </div></td> </tr> <tr> <td height="8" colspan="4" align="center" valign="middle" bgcolor="#FFFFFF"> </td> </tr> </table> <br /> <br /> <br /> <br /></td> </tr></table></form><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /></body></html>[/code]checklogin.php[code]<?php$host="**********"; // Host name$username="********"; // Mysql username$password="********"; // Mysql password$db_name="***********"; // Database name$tbl_name="web_members"; // Table name// Connect to server and select databse.mysql_connect("$host", "$username", "$password")or die("cannot connect");mysql_select_db("$db_name")or die("cannot select DB");// username and password sent from signup form$myemail=$_POST['myemail'];$mypassword=$_POST['mypassword'];$sql="SELECT * FROM $tbl_name WHERE Email='$myemail' and Password='$mypassword'";$result=mysql_query($sql);// Mysql_num_row is counting table row$count=mysql_num_rows($result);// If result matched $myemail and $mypassword, table row must be 1 rowif($count==1){// Register $myusername, $myemail and redirect to file "login_success.php"$_SESSION['myemail'] = $myemail;$_SESSION['mypassword'] = $mypassword;$_SESSION['fname'] = $fname;$_SESSION['sname'] = $sname;$_SESSION['addno'] = $addno;$_SESSION['addone'] = $addone;header("location:index.php");}else {echo "Wrong Username or Password";}?>[/code]Registration Page[code]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Secure :: One Time Deals :: Register </title><style type="text/css"><!--.style21 {font-family: ADMUI3Lg, serif, monospace, cursive; font-weight: bold; font-size: 16px; color: #FFFFFF; }body { margin: 0px; padding-top: 2px; padding-right: 2px; padding-bottom: 4px; padding-left: 2px; background-image: url(fbedc7.gif);}.style37 { color: #FFFFFF; font-size: 1px;}.style38 {color: #CCCCCC}--></style></head><body><table width="100%" height="19%" border="0" background="fbedc7.gif"> <tr> <td height="25" background="Untitled-4.gif"><div align="center"><span class="style21">Register</span></div></td> </tr> <tr> <td height="131" valign="top" background="fbedc7.gif"><table width="100%" height="0%" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="100%" height="1" valign="top"><span class="style37">.</span></td> </tr> <tr> <td height="33" align="center" valign="middle" background="fbedc7.gif" bgcolor="fbedc7"><div align="center"><span xmlns:sitefunctions="urn:siteFunctions"> </span><img src="shoppingbasketheader.gif" alt="Shopping Basket" xmlns:sitefunctions="urn:siteFunctions" align="absmiddle" height="24" width="215" /> </div></td> </tr> <tr> <td height="8" valign="top" bgcolor="#FFFFFF"><div align="center"><span class="style37">.</span></div></td> </tr> <tr> <td height="11" valign="top" background="fbedc7.gif"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="898" background="fbedc7.gif" bgcolor="fbedc7"><div align="center"> <br /> <span class="style38"><?php echo $_POST["fname"]; ?> <?php echo $_POST["sname"]; ?>, Welcome To One Time Deals</span><br /> </div> <br /> <?php $host="********"; // Host name$username="********"; // Mysql username$password="*****"; // Mysql password$db_name="*******"; // Database name$tbl_name="web_members"; // Table name// Connect to server and select databse.echo '<form action="index.php" method="post"> <input type="hidden" name="email" value="'.$_POST['email'].'"> <input type="hidden" name="fname" value="'.$_POST['fname'].'"> <input type="hidden" name="sname" value="'.$_POST['sname'].'"> <input type="hidden" name="pass" value="'.$_POST['pass'].'"> <input type="hidden" name="passtwo" value="'.$_POST['passtwo'].'"> <input type="hidden" name="llno" value="'.$_POST['llno'].'"> <input type="hidden" name="mobno" value="'.$_POST['mobno'].'"> <input type="hidden" name="addno" value="'.$_POST['addno'].'"> <input type="hidden" name="addone" value="'.$_POST['addone'].'"> <input type="hidden" name="addtwo" value="'.$_POST['addtwo'].'"> <input type="hidden" name="addthree" value="'.$_POST['addthree'].'"> <input type="hidden" name="city" value="'.$_POST['city'].'"> <input type="hidden" name="other" value="'.$_POST['other'].'"> <input type="hidden" name="country" value="'.$_POST['country'].'"> <input type="hidden" name="noc" value="'.$_POST['noc'].'"> <input type="hidden" name="ccno" value="'.$_POST['ccno'].'"> <input type="hidden" name="expdate" value="'.$_POST['expdate'].'"> <input type="hidden" name="cvv" value="'.$_POST['cvv'].'"> <input type="image" src="register.gif" name="submit" alt="Log In" value="Log In" />'; mysql_connect("$host", "$username", "$password") or die ("cannot connect: " . mysql_error());mysql_select_db("$db_name") or die("cannot select DB: " . mysql_error());$sql = "INSERT INTO web_members (Email, Password, Firstname, Surname, AddNo, AddOne, AddTwo, AddThree, City, Country, Other Country, NOC, CCNO, ExpDate, ExpDatey, CVV) VALUES ('".$_POST['email']."', '".$_POST['pass']."', '".$_POST['fname']."', '".$_POST['sname']."', '".$_POST['addno']."', '".$_POST['addone']."', '".$_POST['addtwo']."', '".$_POST['addthree']."', '".$_POST['city']."', '".$_POST['country']."', '".$_POST['other']."', '".$_POST['noc']."', '".$_POST['ccno']."', '".$_POST['expdate']."', '".$_POST['cvv']."')";mysql_query($sql) or die ("Couldn't execute $sql: " . mysql_error());?> </td> </tr> </table> <div align="center"></div></td> </tr> <tr> <td height="19" align="center" valign="middle" background="fbedc7.gif" bgcolor="#FFFFFF"><span class="style37">a</span></td> </tr> </table> </td> </tr></table></body></html>[/code]Now you can have a good look at the site and what i want to achieve.I just want the fields to be carried around the site at all times when they are logged in. I will make a log out button using session_destroy();Thank you and i hope this information makes it clearer.Snooble Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.