Jump to content

Session name


TehBlizzy

Recommended Posts

  • Replies 54
  • Created
  • Last Reply

Ok. I put the session_redirect script inside session_redirect.php and in the checklogin.php I putinclude("session_redirect.php"); at the top. When the if statement is true, I put the line session_redirect('login_success.php'); and thats it. Still comes up a blank screen... I should probably put $_SESSION['myusername'] = '$myusername'; before the session_redirect function call

Link to comment
Share on other sites

K. This is the checklogin.php script:

<?phpinclude("session_redirect.php");ob_start();$host="localhost"; // Host name$username="gdhghfh"; // Mysql username$password="dfghdhd"; // Mysql password$db_name="randomchatrooms_zxq_net_login"; // Database name$tbl_name="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");// Define $myusername and $mypassword$myusername=$_POST['myusername'];$mypassword=$_POST['mypassword'];$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";$result=mysql_query($sql);// Mysql_num_row is counting table row$count=mysql_num_rows($result);// If result matched $myusername and $mypassword, table row must be 1 rowif($count==1){// Register $myusername and redirect to file "login_success.php"$_SESSION['myusername'] = $myusername;session_redirect('Location: login_success.php');}else {echo "Wrong Username or Password";}ob_end_flush();?>

Link to comment
Share on other sites

Ya, I accidentally deleted the = at first, I edited it real quick though, a lil too quick..I added session_start(); and it works, but now the login_success.php doesn't show anything where I had the session name to be shown. No "Array ()" or anything.

Link to comment
Share on other sites

Nevermind my last post, it seems that instead of going to login_success.php and staying, the PHP to check if the session exists seems to be having a problem and sends me to the index. When a user goes to a page that requires to be logged in, it redirects to the index.php. BUT, my index.php will display two different pages depending on if your logged in or not, and it seems to be displaying the one saying I'm logged in. o_o

Link to comment
Share on other sites

I'll post it in a bit. My index is having the "switched around" problem where if your not logged in it says you are... It switches around for some reason.K, this is the login_success.php page:

<?phpsession_start();if(!isset($_SESSION['myusername'])){echo("<html><head><title>Random Chatrooms - Login Successful</title><link href='css/default.css' rel='stylesheet' type='text/css'></head><body><center><table border='1' width='800'><tr><td colspan='3' height='150' width='800'>Header</td></tr><tr height='600'><td width='100'><div align='center'><h2>Navigation</h2><br><br><a href='index.php'>Index</a><br><a href='updates.php'>Updates</a><br><a href='rooms.php'>Chatrooms</a><br><a href='profile.php'>My Profile</a><br><a href='viewpf.php'>View Profile</a><br><a href='logout.php'>Logout</a></div></td><td width='550'>Login Successful!<br></td><td>Ads</td></tr></table></body></html>");print_r($_SESSION);}else {header("location:http://randomchatrooms.zxq.net/index.php");}?>

It redirects me to the index after I log in, and the index says I'm not logged in either

Link to comment
Share on other sites

I tried your suggestion, but it seems the session is not being made or the index.php is.. messed up.When you first visit the index, it states "Not Logged In" in the body table. If you are logged in, it says "Logged In".After I log into the site, I am redirected to the index and it says "Not Logged In" so I guess the changes I've made to the session seems to have stopped working. Idk..

Link to comment
Share on other sites

Ok! I got it now. I guess I removed session_start(); on accident so I added it back again but I also included the $myusername variable inside the if statement just in case it happened to get lost.Now "Array ( [myusername] => TehBlizzy )" appears at the bottom of the page. I'm guessing thats right?--Edit...Oh, and btw, this was w/o using your session_redirect function.

Link to comment
Share on other sites

Yep. The session name works fine now. Unfortunately, something seems to be wrong in my posting script. I have the username in a will-be hidden text box. The problem is I can only get one variable in the message to work. If I just put "lol says: $msg" it appears as "lol says: (the message)" in the chat file, and if I do "$username says: lol" it works that way too, but if I put both "$username says: $msg" it doesn't work... but thats how it is in the original working chatroom code I made. Wtf? o_0

<?php$msg = $_POST["UserMsg"];$username = $_POST["Username"];$file = fopen("chat_text/room1.htm","a+");fwrite($file,"$username says : $msg <br>");fclose($file);?>

Link to comment
Share on other sites

Sweet. It works now. >>All that is left is trying to get my registering code to work :)Oh, and I'm looking for ways to prevent HTML from being sent in, so people can't change their text colors and mess it up. >>--EditWell not really "prevent" html from being sent, but replace any <'s and >'s with < and > and remove any other possible bad data such as PHP and stuff

Link to comment
Share on other sites

The register script works now, but I'm making it so if its empty or the username/password is taken, it will redirect to an error page. If the $myusername or $mypassword field is empty, it redirects to the empty error page.But, the problem is, the part where it checks if the Username/Password is taken, it will redirect to the taken error page, but if the person types in a different password than what is registered, it takes them to the empty error page.

if($count==1){header("location:register_err.php?err=taken");}else if(empty($myusername[$mypassword])) {header("location:register_err.php?err=empty");}

If you want to experience it yourself, go to randomchatrooms.zxq.net/register.php and type the username "test" and the password "test". After that, hit the back button and type in username"test" but password "tst" or something else and see for yourself :S

Link to comment
Share on other sites

Ahahah... nevermind that. I used the same code as the login code making it grab the username AND password data. I just removed the password part and it works fine now.All I need now is someone to help me replace < and > with < and >.. and I guess remove other PHP things for the chatrooms from the message that someone sends.Oh, and something that checks if someone tries to register a name and password with unwanted characters

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.


×
×
  • Create New...