Jump to content

website won't access mysql


jagguy

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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();....

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

 

Link to comment
Share on other sites

  $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']

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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'];

Link to comment
Share on other sites

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....

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.