SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    SitePoint Enthusiast boardy's Avatar
    Join Date
    Feb 2007
    Location
    Lincoln, UK
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    SCRIPT_NAME issues in a script

    Hi,

    I have just moved from a Linux server to a Windows 2003 Web Edition server and have setup IIS6, PHP5, and MySQL5 myself as it's a dedicated server.

    The issue is I have PHP scripts which would run fine on the Linux box with SCRIPT_NAME in them, but for some reason they will not work on the IIS6 server.

    There is nothing echo'd where the SCRIPT_NAME command is.

    The phpinfo() output is here -

    http://www.bench-uk.co.uk/phpinfo.php

    and the script is -

    PHP Code:
    <?php

    include("config.php");

        if(isset(
    $_GET['id']) == TRUE) {
            if(
    is_numeric($_GET['id']) == FALSE) {
                
    $error 1;
            }
            if(
    $error == 1) {
                
    header("location:".$config_basedir);
            }
            else {
                
    $validentry $_GET['id'];
            }
        }
        else {
            
    $validentry 0;
        }    

        if(
    $_POST['submit']) {
            
    $db mysql_connect($dbhost$dbuser$dbpassword);
            
    mysql_select_db($dbdatabase$db);
            
            
    $sql "INSERT INTO comments(blog_id, dateposted, name, comment) VALUES('".$validentry."',NOW(), '".$_POST['name']."', '".$_POST['comment']."')";
            
    mysql_query($sql);
            
    header("Location: http://" $HTTP_HOST $SCRIPT_NAME "?id=" $validentry);
        }
        else {
            
    // Code will go here
        
    }

    include(
    "header.php");

        if(
    $validentry == 0) {
            
    $sql "SELECT entries.*, categories.cat FROM entries, categories
                    WHERE entries.cat_id = categories.id
                    ORDER BY dateposted DESC
                    LIMIT 1"
    ;
        }
        else {
            
    $sql "SELECT entries.*, categories.cat FROM entries, categories
                    WHERE entries.cat_id = categories.id
                    AND entries.id = "
    .$validentry"
                    ORDER BY dateposted DESC
                    LIMIT 1"
    ;
        }
        
    $result mysql_query($sql);    
        
    $row mysql_fetch_assoc($result);
        
        echo 
    "<h2>" .$row['subject']. "</h2><br />";
        echo 
    "<i>In ".$row['cat']." - Posted on ".date("D jS F Y g.iA"strtotime($row['dateposted']))."</i>";
        echo 
    "<p>";
        echo 
    nl2br($row['body']);
        echo 
    "</p>";
        
        
    $commsql "SELECT * FROM comments WHERE blog_id = ".$validentry." ORDER BY dateposted DESC";
        
    $commresult mysql_query($commsql);
        
    $numrows_comm mysql_num_rows($commresult);
        
        if(
    $numrows_comm == 0) {
            echo 
    "<p>No Comments</P>";
        }
        else {
            
    $i 1;
            
            while(
    $commrow mysql_fetch_assoc($commresult)) {
                echo 
    "<a name='comment".$i."'></a>";
                echo 
    "<h3>Comment by " .$commrow['name']." on ".date("D jS F Y g.iA"strtotime($commrow['dateposted']))."</h3>";
                echo 
    $commrow['comment'];
                
    $i++;
            }
        }

    ?>

    <h3>Leave a comment</h3>

    <form action="<?php echo $SCRIPT_NAME."?id=".$validentry?>" method="post">

    <table>
        <tr>
            <td>Your Name</td>
            <td><input type="text" name="name"></td>
        </tr>
        <tr>
            <td>Comments</td>
            <td><textarea name="comment" rows="10" cols="30"></textarea></td>
        </tr>
        <tr>
            <td></td>
            <td><input type="submit" name="submit" value="Add Comment"></td>
        </tr>
    </table>
    </form>

    <?php

    include("footer.php");

    ?>
    If anyone can shed any light on this, please help.

    Thanks
    Adam
    Adam
    Devarios
    boardy@live.com

  2. #2
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    http://www.sitepoint.com/blogs/2005/...i-differences/

    try $_SERVER['SCRIPT_NAME']
    actually stop using register globals all together.


    your settings says:
    Code:
    Directive         Local Value     Master Value
    register_globals  Off             Off
    And I recommend to leave it off and code something properly.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  3. #3
    SitePoint Enthusiast boardy's Avatar
    Join Date
    Feb 2007
    Location
    Lincoln, UK
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Would having register_globals turned off also mean that $_GET will not work?

    For some reason the following will not allow me to pass validation nor will it allow me to post an update to a blog entry -

    PHP Code:
    <?php
    session_start
    ();

        require(
    "config.php");
        
        if(isset(
    $_SESSION['USERNAME']) == FALSE) {
            
    header("Location:".$config_basedir);
        }
        
        
    $db mysql_connect($dbhost$dbuser$dbpassword);
        
    mysql_select_db($dbdatabase);
        
        if(isset(
    $_GET['id']) == TRUE) {
            if(
    is_numeric($id) == FALSE) {
                
    $error 1;
            }
            
            if(
    $error == 1) {
                
    header("Location:".$config_basedir);
            }
            else {
                
    $validentry $_GET['id'];
            }
        }
        
        if(
    $_POST['submit']) {
            
    $sql "UPDATE entries SET cat_id = '".$_POST['cat']."', subject = '".$_POST['subject']."', body = '".$_POST['body']."' WHERE id = ".$validentry.";";
            
    mysql_query($sql);
            
            
    header("Location:".$caonfig_basedir."viewentry.php?id=".$validentry);
        }
        else {
            require(
    "header.php");
            
            
    $fillsql "SELECT * FROM entries WHERE id = ".$validentry.";";
            
    $fillres mysql_query($fillsql);
            
    $fillrow mysql_fetch_assoc($fillres);

    ?>

    <h1>Update entry</h1>

    <form action="<?php echo $_SERVER['SCRIPT_NAME']."?id=".$validentry?>" method="post">

    <table>
        <tr>
            <td>Category</td>
            <td>
                <select name="cat">
                    <?php
                        $catsql 
    "SELECT * FROM categories;";
                        
    $catres mysql_query($catsql);
                        while(
    $catrow mysql_fetch_assoc($catres)) {
                            echo 
    "<option value='".$catrow['id']."'";
                            
                            if(
    $catrow['id'] == $fillrow['cat_id']) {
                                echo 
    " selected";
                            }
                            
                            echo 
    ">" .$catrow['cat']."</option>";
                        }
                    
    ?>
                </select>
            </td>
        </tr>
        <tr>
            <td>Subject</td>
            <td><input type="text" name="subject" value="<?php echo $fillrow['subject']; ?>" /></td>
        </tr>
        <tr>
            <td>Body</td>
            <td><textarea name="body" rows="10" cols="50"><?php echo $fillrow['body']; ?></textarea></td>
        </tr>
        <tr>
            <td></td>
            <td><input type="submit" name="submit" value="Update entry!" /></td>
        </tr>
    </table>
    </form>

    <?php

        
    }
        
    require(
    "footer.php");

    ?>
    I have tried running this through "Charles" HTTP Debugging Proxy to see what is going on, but as far as I can see it's ok. I just cannot figure out why I can't access the page with the validentry checking in there, nor why I cannot post an update.

    The user I have for the database has the correct permissions. It just seems as if something is not getting where it should.

    Can anyone shed any light on this new problem?

    http://www.bench-uk.co.uk/phpinfo.php


    I have activated a few of the other extensions since posting last.

    Cheers
    Adam
    Adam
    Devarios
    boardy@live.com

  4. #4
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    No $_GET works, what does not work is $_GET['var'] -> $var or $_SERVER['SCRIPT_NAME'] -> $SCRIPT_NAME.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  5. #5
    SitePoint Enthusiast boardy's Avatar
    Join Date
    Feb 2007
    Location
    Lincoln, UK
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    logic could you explain that a little more clearly please? If $_GET['var'] should work, how come the script above isn't working?

    Cheers
    Adam
    Adam
    Devarios
    boardy@live.com

  6. #6
    SitePoint Enthusiast boardy's Avatar
    Join Date
    Feb 2007
    Location
    Lincoln, UK
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In fact, if anyone could explain what's not working and why in my script so I can not make this mistake again, that'd be great.

    Cheers
    Adam
    Adam
    Devarios
    boardy@live.com


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •