KirstyScott Posted December 22, 2008 Share Posted December 22, 2008 Hiya, Well basically what i wanted to do, was for the below code to be only accessable useable for the registered members and any other unregistered members would be either re-directed to the /index.php or not able to access/view the file, but i'm stuck on this as i'm really new to php and sql, and if anyone can give me some advice or help me do this, it'll be much appreciated - it'll keep you busy for like, at least 1 min The almighty php code <? include('./settings.php'); if ($security == 1) { $loginform = ' <hr color="#9f7401"> Logged in as : '.$_SESSION['sesuser'].', ($_SESSION['sesadmin'] <table border="0" width="100%"> <tr width="100%"> <td align="left" width="25%"> <td align="left" width="70%"> ..:: <a href="/index.php">Home</a> | <a href="/index.php?act=user&actu=support">Read rules</a> | <a href="/index.php?act=logout">Logout</a> ::.. </td> </tr> </table><hr color="#9f7401"> <table width="556" border="0" cellspacing="0" cellpadding="0"> <tr> <td colspan="3"><img src="./news_top.gif" width="556" height="49"></td> </tr> <tr> <td width="13" valign="bottom" background="./news_slice_left.gif"> </td> <td width="530" align="left" valign="top" bgcolor="#e7dbc3"> <table width="530" border="0" cellspacing="0" cellpadding="6"> <tr> <td width="143" height="35" colspan="2" bgcolor="#25120B" class="textwhite"></font><font color="#bd8e00">Contact owner</font></td> <td width="296" height="35" bgcolor="#25120B" class="textwhite"></font><font color="#bd8e00"></font></td> </tr> <tr> <td width="546" colspan="3" rowspan="6" valign="top" bgcolor="#e7dbc3" class="bodytextnews"> <br /> <form action="/web_dialogs" method="POST"><table border="0" cellpadding="3"><tr><td valign="top"><font face="times" color="black" size="2">Send to which department?</td><td><label><input name="web_dialog[client_department_id]" type="radio" id="web_dialog_client_department_id_119" value="119"><font face="times" color="black" size="2">report</label><br><label><input name="web_dialog[client_department_id]" type="radio" id="web_dialog_client_department_id_120" value="120">Website bug</label><br><label><input name="web_dialog[client_department_id]" type="radio" id="web_dialog_client_department_id_121" value="121"><font face="times" color="black" size="2">problem</label><br><label><input name="web_dialog[client_department_id]" type="radio" id="web_dialog_client_department_id_122" value="122"><font face="times" color="black" size="2">(Other)</label><br><p></td></tr><tr><td><font face="times" color="black" size="2"><i>Characters</i> name:</td><td><input name="web_dialog[fname]" size="30" type="text" id="web_dialog_fname"></td></tr><tr><td><font face="times" color="black" size="2">Account secret code:</td><td><input name="web_dialog[lname]" size="30" type="text" id="web_dialog_lname"></td></tr><tr><td><font face="times" color="black" size="2">Valid e-mail - <font face="times" color="black" size="1">so we can contact you<br></td><td><input name="web_dialog[email]" size="30" type="text" id="web_dialog_email"></td></tr><tr><td colspan="2"><hr></td></tr><tr><td><font face="times" color="black" size="2">Subject:</td><td><input name="web_dialog[visitor_subject]" size="39" type="text" id="web_dialog_visitor_subject"></td></tr><tr><td valign="top"><font face="times" color="black" size="2">Message:</td><td><textarea name="web_dialog[message]" id="web_dialog_message" rows="10" cols="30"></textarea></td></tr><tr><td colspan="2"><hr></td></tr><tr><td colspan="2"><font face="times" color="red" size="2"> </td></tr><tr><td></center><p><br><input name="commit" type="submit" value="Send message" onclick="this.setAttribute('originalValue', this.value);this.disabled=true;this.value='Processing...';;result = (this.form.onsubmit ? (this.form.onsubmit() ? this.form.submit() : false) : this.form.submit());if (result == false) { this.value = this.getAttribute('originalValue'); this.disabled = false };return result"></td></tr></table><input name="store" type="hidden" id="store" value="62"><input name="rand" type="hidden" id="rand" value=""><input name="web_dialog[visitor_language_id]" type="hidden" id="web_dialog_visitor_language_id" value="1"></form><script src="/javascripts/loadcaptcha.js" type="text/javascript"></script><script type="text/javascript" language="JavaScript">LoadCaptcha(875,"5f6070a9f53935b04b6e54033fa28e08");</script><br> </td> </tr> <tr></tr> <tr height="15"></tr> <tr height="15"></tr> <tr height="15"></tr> <tr height="184"></tr> <tr height="14"> <td class="bodytextnews" colspan="3" valign="top" bgcolor="#e7dbc3" width="446" height="14"> </td> </tr> </table> </td> <td width="13" valign="bottom" background="./news_slice_right.gif"> </td> </tr> </table> <img src="./tble_btm.gif" width="556" height="49"> </form> <table width="95%" border="0" cellspacing="0" cellpadding="0"> <tr> </table> </p> </td> </tr> </table></td> </tr> <tr> <td height="57" colspan="2" style="background-image:url(./content_bottom2.gif);background-repeat:no-repeat;"></td> </tr>; } ?> Thanks, and if you could please explain what was wrong, cause as i said, i'm really new to php and all stuff, so would appreciate it all, so i won't make the mistake again! (hopefully) Quote Link to comment https://forums.phpfreaks.com/topic/138067-php-session-help/ Share on other sites More sharing options...
dennismonsewicz Posted December 22, 2008 Share Posted December 22, 2008 do you have session_start(); at the beginning of the page? Quote Link to comment https://forums.phpfreaks.com/topic/138067-php-session-help/#findComment-721693 Share on other sites More sharing options...
ngreenwood6 Posted December 22, 2008 Share Posted December 22, 2008 You will need session_start(); at the top of your page. then you would have to make a unique value when the user logs in like this: $_SESSION['logged_in'] = TRUE; Then on each page you can check it using this: if($_SESSION['logged_in'] == FALSE) { header("location:index.php"); } Quote Link to comment https://forums.phpfreaks.com/topic/138067-php-session-help/#findComment-721698 Share on other sites More sharing options...
KirstyScott Posted December 22, 2008 Author Share Posted December 22, 2008 Opps, i forgot to say, i do have the session_start(); at the top of each page, and i tried what yah said ngreenwood6, i put that just below the session_start(); and i'm still able to view this even being logged out ??? Help :'( Quote Link to comment https://forums.phpfreaks.com/topic/138067-php-session-help/#findComment-721754 Share on other sites More sharing options...
DeanWhitehouse Posted December 22, 2008 Share Posted December 22, 2008 http://djw-webdesign.awardspace.com/code.php?snippet=9 Quote Link to comment https://forums.phpfreaks.com/topic/138067-php-session-help/#findComment-721755 Share on other sites More sharing options...
ngreenwood6 Posted December 22, 2008 Share Posted December 22, 2008 I think you misunderstood what I said make a unique value when the user logs in On the page where the user logs in (login.php or whatever). when you set the session variables for the username or whatever else you need to set a variable like this one: $_SESSION['logged_in'] = TRUE; Quote Link to comment https://forums.phpfreaks.com/topic/138067-php-session-help/#findComment-721757 Share on other sites More sharing options...
revraz Posted December 22, 2008 Share Posted December 22, 2008 Then post the actual code. Opps, i forgot to say, i do have the session_start(); at the top of each page, and i tried what yah said ngreenwood6, i put that just below the session_start(); and i'm still able to view this even being logged out ??? Help :'( Quote Link to comment https://forums.phpfreaks.com/topic/138067-php-session-help/#findComment-721759 Share on other sites More sharing options...
KirstyScott Posted December 22, 2008 Author Share Posted December 22, 2008 That is the actual code, the reason for it not having the session_start(); at the top is because i forgot to copy it in as it's at the top Quote Link to comment https://forums.phpfreaks.com/topic/138067-php-session-help/#findComment-721777 Share on other sites More sharing options...
mattjones Posted December 23, 2008 Share Posted December 23, 2008 you need put the !$_session['loggedin'] = 1 (or however you have set your session) at the top of the page like this. session_start(); if (!$_SESSION['loggedin'] == 1) {header(location: wherever);} else { //display page } Quote Link to comment https://forums.phpfreaks.com/topic/138067-php-session-help/#findComment-721856 Share on other sites More sharing options...
KirstyScott Posted December 23, 2008 Author Share Posted December 23, 2008 Thanks for all your replys and help. This is my new code below <?session_start();?> <head> <title>Website report</title> </head> <body style="margin:0;background-color:#000000;"> <? include('./config.php'); if (!$_SESSION['sesuser'] == 1) {header(index.php);} else { $userform=" <table bgcolor='black' cellpadding='0' cellspacing='0' border='0' align='center'> <tr> <td width='726' height='300' valign='top' background='./content_bkgrd.gif'> <img src='./content_top2.gif' width='726' height='71' /> <table width='560' border='0' align='center' cellpadding='0' cellspacing='0'> <tr> <td> <hr color='#9f7401'> <table border='0' width='100%'> <tr width='100%'> <td align='left' width='25%'> <td align='left' width='70%'> ..:: <a href='/index.php'>Home</a> | <a href='/index.php?act=user&actu=support'>Read rules</a> | <a href='/index.php?act=logout'>Logout</a> ::.. </td> </tr> </table><hr color='#9f7401'> <table width='556' border='0' cellspacing='0' cellpadding='0'> <tr> <td colspan='3'><img src='./news_top.gif' width='556' height='49'></td> </tr> <tr> <td width='13' valign='bottom' background='./news_slice_left.gif'> </td> <td width='530' align='left' valign='top' bgcolor='#e7dbc3'> <table width='530' border='0' cellspacing='0' cellpadding='6'> <tr> <td width='143' height='35' colspan='2' bgcolor='#25120B' class='textwhite'></font><font color='#bd8e00'>Contact us</font></td> <td width='296' height='35' bgcolor='#25120B' class='textwhite'></font><font color='#bd8e00'></font></td> </tr> <tr> <td width='546' colspan='3' rowspan='6' valign='top' bgcolor='#e7dbc3' class='bodytextnews'> <br /> <form action='/web_dialogs' method='POST'><table border='0' cellpadding='3'><tr><td valign='top'><font face='times' color='black' size='2'>Send to which department?</td><td><label><input name='web_dialog[client_department_id]' type='radio' id='web_dialog_client_department_id_119' value='119'><font face='times' color='black' size='2'>Website question</label><br><label><input name='web_dialog[client_department_id]' type='radio' id='web_dialog_client_department_id_120' value='120'>Account deletion</label><br><label><input name='web_dialog[client_department_id]' type='radio' id='web_dialog_client_department_id_121' value='121'><font face='times' color='black' size='2'>Website report</label><br><label><input name='web_dialog[client_department_id]' type='radio' id='web_dialog_client_department_id_122' value='122'><font face='times' color='black' size='2'>(Other)</label><br><p></td></tr><tr><td><font face='times' color='black' size='2'><i>First</i> name:</td><td><input name='web_dialog[fname]' size='30' type='text' id='web_dialog_fname'></td></tr><tr><td><font face='times' color='black' size='2'>Account secret code:</td><td><input name='web_dialog[lname]' size='30' type='text' id='web_dialog_lname'></td></tr><tr><td><font face='times' color='black' size='2'>Valid e-mail - <font face='times' color='black' size='1'><br></td><td><input name='web_dialog[email]' size='30' type='text' id='web_dialog_email'></td></tr><tr><td colspan='2'><hr></td></tr><tr><td><font face='times' color='black' size='2'>Subject:</td><td><input name='web_dialog[visitor_subject]' size='39' type='text' id='web_dialog_visitor_subject'></td></tr><tr><td valign='top'><font face='times' color='black' size='2'>Message:</td><td><textarea name='web_dialog[message]' id='web_dialog_message' rows='10' cols='30'></textarea></td></tr><tr><td colspan='2'><hr></td></tr><tr><td colspan='2'><font face='times' color='red' size='2'> </td></tr><tr><td><font face='times' color='black' size='2'>Verification code<font face='times' color='red' size='1'> - Case sensitive </td><td><img name='CaptchaImage' src='' id='CaptchaImage' height='40' alt='Verification' width='150'></td></tr><tr><td><font face='times' color='black' size='2'>Enter code</td><td><input name='code' size='8' type='text' id='code'> <font face='times' color='red' size='1'> case sensitive </td></tr><tr><td colspan='2'><center><br><center></center><p><br> <input name='commit' type='submit' value='Send message' onclick='this.setAttribute('originalValue', this.value);this.disabled=true;this.value='Processing...';;result = (this.form.onsubmit ? (this.form.onsubmit() ? this.form.submit() : false) : this.form.submit());if (result == false) { this.value = t his.getAttribute('originalValue'); this.disabled = false };return result'></td></tr></table><input name='store' type='hidden' id='store' value='62'><input name='rand' type='hidden' id='rand' value=''><input name='web_dialog[visitor_language_id]' type='hidden' id='web_dialog_visitor_language_id' value='1'></form><script src='/javascripts/loadcaptcha.js' type='text/javascript'></script><script type='text/javascript' language='JavaScript'>LoadCaptcha(875,'5f6070a9f53935b04b6e54033fa28e08');</script><br> </td> </tr> <tr></tr> <tr height='15'></tr> <tr height='15'></tr> <tr height='15'></tr> <tr height='184'></tr> <tr height='14'> <td class='bodytextnews' colspan='3' valign='top' bgcolor='#e7dbc3' width='446' height='14'> </td> </tr> </table> </td> <td width='13' valign='bottom' background='./news_slice_right.gif'> </td> </tr> </table> <img src='./tble_btm.gif' width='556' height='49'> </form> <table width='95%' border='0' cellspacing='0' cellpadding='0'> <tr> </table> </p> </td> </tr> </table></td> </tr> <tr> <td height='57' colspan='2' style='background-image:url(./content_bottom2.gif);background-repeat:no-repeat;'></td> </tr>" //display page } I'm pretty sure i've done it all right, but the above code is giving me "Parse error: syntax error, unexpected '}' in filename.php on line 136" I'm struggling with this :-\, and would appreciate help to fix the above code Quote Link to comment https://forums.phpfreaks.com/topic/138067-php-session-help/#findComment-722036 Share on other sites More sharing options...
mattjones Posted December 23, 2008 Share Posted December 23, 2008 you need a ; after the last " to end the echo. you may need to put the header before the title aswell. and you need location: in your header statement. header("Location: index.php") and mabey some brackets here. if (!($_SESSION['sesuser'] == 1)) Quote Link to comment https://forums.phpfreaks.com/topic/138067-php-session-help/#findComment-722171 Share on other sites More sharing options...
Yesideez Posted December 23, 2008 Share Posted December 23, 2008 Do you know which line is line 136? Just wondering which editor you're using as I use Edit+ and Notepad++ and both show me line numbers. Error messages from PHP aren't always caused at the line given. The majority are the previous line, most are somewhere earlier in the code and not many are on the actual line. Quote Link to comment https://forums.phpfreaks.com/topic/138067-php-session-help/#findComment-722174 Share on other sites More sharing options...
ngreenwood6 Posted December 23, 2008 Share Posted December 23, 2008 this statement is incorrect also: if (!$_SESSION['sesuser'] == 1) \\if nothing is set for sesuser = 1 ... doesnt make sense it should be if($_SESSION['sesuser'] != 1) \\if sesuser is not equal to 1 Quote Link to comment https://forums.phpfreaks.com/topic/138067-php-session-help/#findComment-722294 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.