Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 11
  1. #1
    Junior Member Famous's Avatar
    Join Date
    Jun 2007
    Posts
    27
    Member #
    15431
    First Post so Hi. Hope to get more involved with this forum as time goes on.

    Anyway, I'm having some issues with PHP carrying variables from one page to another. The site I am working on is in the process of migrating to another server.
    An example of a link that would be created via PHP would be:
    http://www.hants.gov.uk/hba/programm...y=18&countbx=1
    Therefore the variables would carry over. Clicking on that link will show you how its supposed to look. The page will retrieve the file based on those variables.
    However, on the new server the same link is:
    http://hba.hampshire.org.uk/programm...y=18&countbx=1
    But when you click on that one you can see that it is not retrieving the file. Instead of "Warning: main(listings/month--.php)" there should be numbers between the dashes that can be found in the URL (thismonth and thisyear). However it appears the file is not reading these variables. Can anybody suggest a reason why this could happen? The code on both sites is exactly the same.
    Thanks in advance.
    Fancy a read? Pixelfiction.co.uk

  2.  

  3. #2
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    The errors generated seem to have a problem accessing a file in a subdirectory called listings

    'listings/month--.php
    should probably be lisitings/month.php

    You had a - in there.

  4. #3
    Junior Member Famous's Avatar
    Join Date
    Jun 2007
    Posts
    27
    Member #
    15431
    due to the variables in the URL it should actually be looking for a file named month-2007-7.php
    But, as you can see it is looking for month--.php meaning it has not picked up the variables from the URL and I can't understand why.
    Fancy a read? Pixelfiction.co.uk

  5. #4
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    Ah right, well, it must have something to do with the code that points to the variable names.

    Try including a print_r($_GET); in your code, and check the keys match.

  6. #5
    Junior Member Famous's Avatar
    Join Date
    Jun 2007
    Posts
    27
    Member #
    15431
    That's odd. I added that bit of code and it printed:

    Array ( [thismonth] => 7 [thisweekday] => 3 [thisyear] => 2007 [thismonthday] => 18 [countbx] => 1 )

    which I take to mean it has registered the variables ok. But for some reason none of the scripts on the page will read the values.
    Quite strange, although after Googling print_r($_GET) I see some similar issues and I think I'll have to get in touch with my web host to reinstall/update PHP
    Fancy a read? Pixelfiction.co.uk

  7. #6
    ljm
    ljm is offline
    Senior Member ljm's Avatar
    Join Date
    Aug 2006
    Location
    Manchester, England
    Posts
    284
    Member #
    13684
    Liked
    1 times
    Could you put up some code to show how you get the particular file to include, please?

    I have some suspicions, but of course, I can't see if they're right without some PHP to look at.

  8. #7
    Junior Member Famous's Avatar
    Join Date
    Jun 2007
    Posts
    27
    Member #
    15431
    Certainly.
    In the navigation links on the left I have (abridged)
    PHP Code:
    <?php
    $date 
    getdate();
    $month $date[mon];
    $today $date[mday];
    $theyear $date[year];
    $theweekday $date[wday];
    print 
    "<li><a href='programmes.php?thismonth=$month&amp;thisweekday=$theweekday&amp;thisyear=$theyear&amp;thismonthday=$today&amp;countbx=1' class='sublink'>Programme Listings</a></li>";
    This works fine since when you hover over the link all the values are in the URL. When you click that link the page uses it quite a lot, one example is:
    PHP Code:
    <?php
    $testday 
    "$thismonthday-$thismonth-$thisyear";
    include(
    "listings/month-$thisyear-$thismonth.php");
    ?>
    But as we have seen it's coming up blank with listings/month--.php
    What is strange is this does work on the first version of the page, which has reinforced the idea that it's a server issue.
    Fancy a read? Pixelfiction.co.uk

  9. #8
    ljm
    ljm is offline
    Senior Member ljm's Avatar
    Join Date
    Aug 2006
    Location
    Manchester, England
    Posts
    284
    Member #
    13684
    Liked
    1 times
    My suspicion is that on your first server, 'register globals' is turned on.

    Looking at this code:
    PHP Code:
     <?php 
    $testday 
    "$thismonthday-$thismonth-$thisyear"
    include(
    "listings/month-$thisyear-$thismonth.php"); 
    ?>
    Are the variables in the include previously defined, or is that the first time they're used? What I'm saying is, do they link to the variables in the URL?

    For example:
    PHP Code:
    <?
    $thismonthday 
    $_GET['thismonthday'];
    $thismonth $_GET['thismonth'];
    $thisyear $_GET['thisyear'];
    ?>
    Y'see, if register globals is disabled (which it should be), your code won't work unless you use the $_GET variable (as shown in my own example). It means, if you have something in the URL you want to use in the script, you can't just take the name of it and use it as a variable:

    PHP Code:
    <?
    // Example URL
    // http://www.example.com/index.php?test=value&info=value

    // The WRONG way
    $test;

    // The RIGHT way
    $_GET['test'];
    ?>
    Try pasting my example into your code, before the include, and see if it works. That is, if you haven't got that code in your script already. If you do, I'm stumped.

  10. #9
    Junior Member Famous's Avatar
    Join Date
    Jun 2007
    Posts
    27
    Member #
    15431
    Yeah, now that works perfectly. Thanks.
    Unfortunately that means more code to add all over the site.
    Is it better to have register globals enabled or disabled. Enabled would make my life easier.
    Fancy a read? Pixelfiction.co.uk

  11. #10
    ljm
    ljm is offline
    Senior Member ljm's Avatar
    Join Date
    Aug 2006
    Location
    Manchester, England
    Posts
    284
    Member #
    13684
    Liked
    1 times
    It's better to have it disabled. It was a massive security issue before the PHP devs decided to default it to disabled.

    It may be a pain, but you will be better off if you change the code. No hosting company with sense will enable register globals for you.

    To make life easier, you can do all that stuff at the start of your script, so you've not got the variables hidden all over the place.

    Finally, you might want to look at validating those $_GET variables, because at the moment someone could inject any sort of code and have their wicked way with your server.


Page 1 of 2 1 2 LastLast

Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 10:06 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com