SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2000
    Location
    Rocky Mount, NC
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy php scripts stop working when i switch servers

    Recently I was working on a website. It uses a header file so that editing menu links and other information is easier.

    I created a script so that the title of the page changes with the pages (for search engine purposes). The script worked perfectly on my server. I switched to their server and it only gives me the default page title.

    I know there is probably a better way to do this but this worked for me...

    $t works like this.. they click on a link -- contact.php?t=13 ($t = 13)

    Code:
    <?php
    
    $title_default = "2009 Back To School Jumpoff | Rocky Mount, NC | August 7 &amp; 8, 2009";
    $title_registration_booths = "Booth Registration | 2009 Back To School Jumpoff";
    $title_registration_main_stage = "Main Stage Registration | 2009 Back To School Jumpoff";
    $title_registration_youth_lockin = "Youth Lockin Registration | 2009 Back To School Jumpoff";
    $title_registration_volunteers = "Volunteer Registration | 2009 Back To School Jumpoff";
    $title_registration_sponsorship = "Sponsorship Registration | 2009 Back To School Jumpoff";
    $title_registration_vendors = "Vendor Resistration | 2009 Back To School Jumpoff";
    $title_event_security = "Event Security | 2009 Back To School Jumpoff";
    $title_sponsors_partners = "Sponsors & Partners | 2009 Back To School Jumpoff";
    $title_featured_entertainment = "Featured Entertainment | 2009 Back To School Jumpoff";
    $title_featured_activities = "Featured Activities | 2009 Back To School Jumpoff";
    $title_planning_committee = "Planning Committee | 2009 Back To School Jumpoff";
    $title_planning_contact = "Contact Us | 2009 Back To School Jumpoff";
    $title_planning_photos = "Photo Gallery | 2009 Back To School Jumpoff";
    $title_registration_churches = "Church Registration | 2009 Back To School Jumpoff";
    
    ?>
    <?
    
    if ($t == 1){
        $title = $title_registration_churches;}
    elseif ($t == 2){
        $title = $title_registration_booths;}
    elseif ($t == 3){
        $title = $title_registration_main_stage;}
    elseif ($t == 4){
        $title = $title_registration_youth_lockin;}
    elseif ($t == 5){
        $title = $title_registration_volunteers;}
    elseif ($t == 6){
        $title = $title_registration_sponsorship;}
    elseif ($t == 7){
        $title = $title_registration_vendors;}
    elseif ($t == 8){
        $title = $title_event_security;}
    elseif ($t == 9){
        $title = $title_sponsors_partners;}
    elseif ($t == 10){
        $title = $title_featured_entertainment;}
    elseif ($t == 11){
        $title = $title_featured_activities;}
    elseif ($t == 12){
        $title = $title_planning_committee;}
    elseif ($t == 13){
        $title = $title_contact;}
    elseif ($t == 14){
        $title = $title_photos;}
        else {
            $title = $title_default;}
    
    ?>
    Any suggestions?

    Oh, and so you can see what I am talking about...

    Originally script that works: http://stuartbriscar.com/jumpoff/
    This one does no work: http://www.rmjumpoff.com/
    Stuart Briscar Consulting - Free Website Consulting

  2. #2
    play of mind Ernie1's Avatar
    Join Date
    Sep 2005
    Posts
    1,252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I guess the new server has register globals turned off
    You shot use the $_GET['t']; to get the query string
    my mobile portal
    ghiris.ro

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2000
    Location
    Rocky Mount, NC
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hallelujah! some times it is the simple things.. thank you very much
    Stuart Briscar Consulting - Free Website Consulting

  4. #4
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Edit:

    Agh, beaten to it! Forgot to press 'send'...


    Unless it is done before hand, you aren't parsing the GET value of 't' to $t.

    If what I'm assuming is correct, your current hosting allows Register_Globals. This is where form values, such as parameters passed through the URI, are parsed automatically as variables - e.g. somefile.php?q=search, $q is set to 'search'.

    This introduced massive security flaws so was removed years ago, has been deprecated and will soon be completely removed from PHP - the only reason such an atrocity is still around is for backwards compatibility.

    Anyway, to solve this you need to parse variables from forms manually, using PHP.

    For example, with your current script (and I've converted your if()s to switches for the sake of good practise):
    PHP Code:
    <?php
    $title_default 
    "2009 Back To School Jumpoff | Rocky Mount, NC | August 7 &amp; 8, 2009";
    $title_registration_booths "Booth Registration | 2009 Back To School Jumpoff";
    $title_registration_main_stage "Main Stage Registration | 2009 Back To School Jumpoff";
    $title_registration_youth_lockin "Youth Lockin Registration | 2009 Back To School Jumpoff";
    $title_registration_volunteers "Volunteer Registration | 2009 Back To School Jumpoff";
    $title_registration_sponsorship "Sponsorship Registration | 2009 Back To School Jumpoff";
    $title_registration_vendors "Vendor Resistration | 2009 Back To School Jumpoff";
    $title_event_security "Event Security | 2009 Back To School Jumpoff";
    $title_sponsors_partners "Sponsors & Partners | 2009 Back To School Jumpoff";
    $title_featured_entertainment "Featured Entertainment | 2009 Back To School Jumpoff";
    $title_featured_activities "Featured Activities | 2009 Back To School Jumpoff";
    $title_planning_committee "Planning Committee | 2009 Back To School Jumpoff";
    $title_planning_contact "Contact Us | 2009 Back To School Jumpoff";
    $title_planning_photos "Photo Gallery | 2009 Back To School Jumpoff";
    $title_registration_churches "Church Registration | 2009 Back To School Jumpoff";
    $t = (int)$_GET['t'];
    switch(
    $t){
        case 
    1:
            
    $title $title_registration_churches;
            break;
        case 
    2:
            
    $title $title_registration_booths;
            break;
        case 
    3:
            
    $title $title_registration_main_stage;
            break;
        case 
    4:
            
    $title $title_registration_youth_lockin
            break;
        case 
    5:
            
    $title $title_registration_volunteers
            break;
        case 
    6:
            
    $title $title_registration_sponsorship;
            break;
        case 
    7:
            
    $title $title_registration_vendors;
            break;
        case 
    8:
            
    $title $title_event_security;
            break;
        case 
    9:
            
    $title $title_sponsors_partners;
            break;
        case 
    10:
            
    $title $title_featured_entertainment;
            break;
        case 
    11:
            
    $title $title_featured_activities;
            break;
        case 
    12:
            
    $title $title_planning_committee;
            break;
        case 
    13:
            
    $title $title_contact;
            break;
        case 
    14:
            
    $title $title_photos;
            break;
        default:
            
    $title $title_default;
            break;
    }
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  5. #5
    SitePoint Enthusiast
    Join Date
    May 2000
    Location
    Rocky Mount, NC
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh cool. I actually had a verses that used Switch instead of If/Else..

    So what is being removed eventually from php?
    Stuart Briscar Consulting - Free Website Consulting

  6. #6
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Not much really, if you adhere to best practices it won't affect you.

    The two main security removals are register globals and magic-quotes.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  7. #7
    SitePoint Enthusiast
    Join Date
    May 2000
    Location
    Rocky Mount, NC
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay, so what is used instead of registering globals..

    Sorry, even though I've been doing php for 8 years.. it's been very off and on so I don't get to hear about any of the cool stuff
    Stuart Briscar Consulting - Free Website Consulting

  8. #8
    SitePoint Guru
    Join Date
    Jul 2005
    Location
    Orlando
    Posts
    634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If we're going to rewrite it, might as well use an array..

    PHP Code:
        $arr_titles = array(
                
    "Booth Registration | 2009 Back To School Jumpoff"
            
    ,    "Main Stage Registration | 2009 Back To School Jumpoff"
            
    ,    "Youth Lockin Registration | 2009 Back To School Jumpoff"
            
    ,    "Volunteer Registration | 2009 Back To School Jumpoff"
            
    ,    "Sponsorship Registration | 2009 Back To School Jumpoff"
            
    ,    "Vendor Resistration | 2009 Back To School Jumpoff"
            
    ,    "Event Security | 2009 Back To School Jumpoff"
            
    ,    "Sponsors & Partners | 2009 Back To School Jumpoff"
            
    ,    "Featured Entertainment | 2009 Back To School Jumpoff"
            
    ,    "Featured Activities | 2009 Back To School Jumpoff"
            
    ,    "Planning Committee | 2009 Back To School Jumpoff"
            
    ,    "Contact Us | 2009 Back To School Jumpoff"
            
    ,    "Photo Gallery | 2009 Back To School Jumpoff"
            
    ,    "Church Registration | 2009 Back To School Jumpoff"
        
    );
        
    $t = (int) $_GET['t'];
        
    $index $t 1;
        
    $title array_key_exists$index$arr_titles ) ? $arr_titles$index ] : "2009 Back To School Jumpoff | Rocky Mount, NC | August 7 &amp; 8, 2009"
    It's a whole lot more concise that way.

    Note: This won't match up exactly, because your strings aren't in the same order up top as you used in your if statements. If the array was put into the correct "t" order, though, it would.


Tags for this Thread

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
  •