jagguy Posted July 9, 2007 Share Posted July 9, 2007 Hi, I have ported my website to this address and used the same login /password for mysql as previous websites on the same host. I am getting a session error which you can't see unless you highlight. It works on my pc but what do i do here? I access my sql with a script like this .. //connect to the db $link = mysql_connect("localhost", "jagguy_root", "")or die("Could not connect: " . mysql_error()); // select our database mysql_select_db("jagguy_formdata") or die(mysql_error()); .. http://jagguy.ej.am/school/test/home.php Quote Link to comment Share on other sites More sharing options...
BillyBoB Posted July 9, 2007 Share Posted July 9, 2007 Please read stickys before posting http://www.phpfreaks.com/forums/index.php/topic,37442.0.html Quote Link to comment Share on other sites More sharing options...
AndyB Posted July 9, 2007 Share Posted July 9, 2007 Well highlight it and tell us what it is! I'll save you the trouble: Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/jagguy/public_html/school/test/home.php:10) in /home/jagguy/public_html/school/test/home.php on line 17 It's nothing to do with the database. It's all to do with output sent to the browser before setting the cookie. Quote Link to comment Share on other sites More sharing options...
jagguy Posted July 9, 2007 Author Share Posted July 9, 2007 There is no cookie but just sessions. It works fine on my PC so how can i fix this ? eg <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html > <head> <title>Untitled Document</title> <link rel="stylesheet" type="text/css" href="mystyle2.css"/> </head> <body > <?php include("navigation2.html"); ?> <?php session_start();.... Quote Link to comment Share on other sites More sharing options...
BillyBoB Posted July 9, 2007 Share Posted July 9, 2007 i usually dont recommend this but try typing this before any other code: <?php ob_start(); ?> Quote Link to comment Share on other sites More sharing options...
AndyB Posted July 9, 2007 Share Posted July 9, 2007 A quick look at your code reveals you have tons of output to the browser before you get anywhere near a session. How can you fix it? Without seeing what your trying to do, that's impossible. Quote Link to comment Share on other sites More sharing options...
jagguy Posted July 9, 2007 Author Share Posted July 9, 2007 I am just trying to get every page password protected so i use sessions. If someone types in an url without logging in they get redirected. Now what i did do was simple set the session_start() at the start of every script then send html headers. I use <?php session_start(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html >.... What is ob_start? q)Also with my footer I get Notice: Use of undefined constant HTTP_HOST - assumed 'HTTP_HOST' in /home/jagguy/public_html/school/test/footer.php on line 5 $urlh = getenv(HTTP_HOST); $url = $urlh; What is wrong with this as I don't get an error here on my pc? Quote Link to comment Share on other sites More sharing options...
BillyBoB Posted July 9, 2007 Share Posted July 9, 2007 try using ob_start() it allows you to send headers throughout the page and for the HTTP_HOST it should be $_SERVER['HTTP_HOST'] Quote Link to comment Share on other sites More sharing options...
AndyB Posted July 9, 2007 Share Posted July 9, 2007 $urlh = getenv(HTTP_HOST); $url = $urlh; What is wrong with this as I don't get an error here on my pc? Different php version, different error reporting levels, different error display settings ... who know why. $urlh = $_SERVER['HTTP_HOST'] Quote Link to comment Share on other sites More sharing options...
jagguy Posted July 9, 2007 Author Share Posted July 9, 2007 try using ob_start() it allows you to send headers throughout the page and for the HTTP_HOST it should be $_SERVER['HTTP_HOST'] hi, If I place ob_start at top of each page then is that all I have to do as well as inlclude the session vars as per normal? I checked the function and it looks more involved than that. What is wrong with setting the session at line 1 then add html/php header stuff? Quote Link to comment Share on other sites More sharing options...
BillyBoB Posted July 9, 2007 Share Posted July 9, 2007 Please just try to do the ob_start(); then tell me if it works or not Quote Link to comment Share on other sites More sharing options...
jagguy Posted July 9, 2007 Author Share Posted July 9, 2007 well i don't get any error message, but i will need to change the 30 other scripts and add ob_start() to line 1 to all of them to be sure. So could you explain how this works, does it allow headers to be sent from anywhere in the page before any screen output? Quote Link to comment Share on other sites More sharing options...
BillyBoB Posted July 9, 2007 Share Posted July 9, 2007 yes pretty much Quote Link to comment Share on other sites More sharing options...
jagguy Posted July 9, 2007 Author Share Posted July 9, 2007 I am getting this error the line under I access the session variable. I don't get this error on my pc. Notice: Undefined index: all in /home/jagguy/public_html/school/test/teacherupload.php on line 78 <?php ob_start(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html > <head> <title>Untitled Document</title> <link rel="stylesheet" type="text/css" href="mystyle2.css"/> <script type="text/javascript"> function validate() { var fname=document.getElementById("file1").value; submitOK="true" if (fname.length ==0 || ( !fname.match(/\.txt/) && !fname.match(/\.TXT/) && !fname.match(/\.doc/) && !fname.match(/\.DOC/) && !fname.match(/\.xls/) && !fname.match(/\.XLS/) && !fname.match(/\.zip/) && !fname.match(/\.ZIP/) && !fname.match(/\.exe/) && !fname.match(/\.EXE/) && !fname.match(/\.ppt/) && !fname.match(/\.PPT/) && !fname.match(/\.jpg/) && !fname.match(/\.gif/) && !fname.match(/\.png/) )) { alert("The name must not be blank and must have lower case .txt, .doc or .xls .ppt .exe .zip .png .jpg .gif filename ending") submitOK="false" } if (submitOK=="false") { return false } } </script> </head> <body> <?php include("navigation2.html"); ?> <div id='tablewrap'> <span style='color:#d4cd5c'> <h3> Create a Download</h3> This form allows you to upload a file and make it available for students to download<br> <form enctype="multipart/form-data" action="teacherupload2.php" method="post" onsubmit="return validate()"> <input type="hidden" name="MAX_FILE_SIZE" value="3000000" > Choose a file to upload: <input name="uploadedfile" type="file" id="file1"><br > <input type="submit" value="Click to Upload File " > </form> <?php session_start(); // echo $_SESSION['uid'] ; if (isset($_SESSION['HTTP_USER_AGENT'])) { if ($_SESSION['HTTP_USER_AGENT'] != md5($_SERVER['HTTP_USER_AGENT'])) { /* Prompt for password */ session_destroy(); header( "Location: http://localhost/school/test/login.php" ); exit; } } else { $_SESSION['HTTP_USER_AGENT'] = md5($_SERVER['HTTP_USER_AGENT']); } if (!isset($_SESSION['uid'])) { header( "Location: http://localhost/school/test/login.php" ); exit; } //view uploaded files include("dbconnect.php"); $uid=$_SESSION['uid']; $viewall= $_POST['all']; Quote Link to comment Share on other sites More sharing options...
sushant_d84 Posted July 9, 2007 Share Posted July 9, 2007 POST THE CODE Quote Link to comment Share on other sites More sharing options...
matto Posted July 9, 2007 Share Posted July 9, 2007 The alternative to using ob_start() would be to put the session function as the first line of code on the pages that need access to the session data <?php session_start(); //the rest of the code below this line.... 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.