Page 1 of 2 12 LastLast
Results 1 to 15 of 21

Thread: How to make an out.php script?

  1. #1
    Registered Mr. Pink's Avatar
    Join Date
    Sep 2008
    Location
    USA
    Posts
    147

    Question How to make an out.php script?

    Hello,

    I searched the forums but could not find the exact explanations for what I need. I did find this thread http://www.websitepublisher.net/foru...=&threadid=336 and some others, but since I am not a programmer I don't understand what needs to be done, unless every step of the process is described.

    Basically, I would like to create a database of outgoing links, and an out.php file, just the same way it is done on this site.

    My question is, how is that done?

    (I am very good at following instructions, but unfortunately I do need every step of the process explained, sorry...)

    Thank you in advance for your help...


    PS - This is a great site, by the way. I read about 50% of the articles in the past 2 day, since I joined. Really informative. Thank you, Chris.

  2. #2
    Administrator Chris's Avatar
    Join Date
    Feb 2003
    Location
    East Lansing, MI USA
    Posts
    7,055
    Do you understand enough to copy & change a php script?

    PHP Code:
    <?

    $db 
    mysql_connect("localhost""username""password");
    if (!
    $db) {  echo( "<P>Unable to connect to the " "database server at this time.</P>" );  exit();}

    mysql_select_db("database_name"$db);


    $result1 mysql_query("SELECT * FROM redirect_links where LinkID = '$LinkID'"$db);
    if (!
    $result1) {  echo("<P>Error performing query: " mysql_error() . "</P>");  
    exit();
    }
        
    $numResults mysql_num_rows($result1); 
        if(
    $numResults != 0){

            while(
    $list mysql_fetch_array($result1)){
            
    $url $list[url];
            }
        }
        
    mysql_free_result($result1);

        
    header("Location: $url");
        
    ?>
    Chris Beasley - My Guide to Building a Successful Website[size=1]
    Content Sites: ABCDFGHIJKLMNOP|Forums: ABCD EF|Ecommerce: Swords Knives

  3. #3
    Registered Mr. Pink's Avatar
    Join Date
    Sep 2008
    Location
    USA
    Posts
    147
    Thanks for looking into this, Chris.

    Here is what I did so far.

    In my Control Panel, I set up a new MySQL database, gave it a name, set up a user and added that user to the new database. I checked all permissions.

    In the script, I changed the "username" "password" and "database_name"
    I left "localhost" as is (or am I supposed to change that, too?).

    On my server, I created a new folder called "scripts" and then I put the out.php script in it.

    Is all the above correct?



    Now I don't know what to do next.

    Basically, where and how do add URL's into the database and how do I manage the database in general?

    Sorry if this is all simple stuff, but I have no experience with MySQL or PHP. I've always only worked with CGI scripts and followed whatever installation instructions came with them.


    Thank you in advance for your help.

  4. #4
    Administrator Chris's Avatar
    Join Date
    Feb 2003
    Location
    East Lansing, MI USA
    Posts
    7,055
    Yes, all of the above is correct.

    Next step, you need to get into phpMyAdmin - look for a link in your control panel. It is a front end for your database.

    once you get there browse for your database, then create a new table called

    redirect_links

    add 2 fields to that table

    LinkID
    url

    for LinkID make it an mediumint field with a length of 8, then under extra select "auto increment" and at the far right for the radio boxes check primary key

    for url make it a varchar field with a length of say 200.

    then you can insert into this database from phpmyadmin urls, and then browse the database to see the LinkIDs, and reference them with your redirect script.
    Chris Beasley - My Guide to Building a Successful Website[size=1]
    Content Sites: ABCDFGHIJKLMNOP|Forums: ABCD EF|Ecommerce: Swords Knives

  5. #5
    Registered Mr. Pink's Avatar
    Join Date
    Sep 2008
    Location
    USA
    Posts
    147
    Chris,

    First of all, thank you for taking the time to help me out.

    I set-up everything as instructed and was able to insert a couple of URLs into the database. However, I'm afraid something is still not right. I spend about an hour troubleshooting, but no luck.

    To run the script I just point my browser to www.my-site.com/scripts/out.php?LinkID=1 (I believe this is correct). The browser idles for several seconds and then just stops idling. Nothing happens, there is just a blank browser page with no source code in it. I even tried setting permissions to the script to 755 (it defaulted to 644) and still nothing.

    I tried several other things, changing things in the script, but then the browser just returned error pages.

    Any idea what I might have missed?

  6. #6
    Registered Mr. Pink's Avatar
    Join Date
    Sep 2008
    Location
    USA
    Posts
    147
    Well... I've been struggling for a few more hours with trying to set up this script. But at least I have some news that may help determine what is wrong, and hopefully how to fix it.

    I entered 3 URLs into the database. If I change the LinkID of the 1st URL to the value 0, then the script forwards to that URL. But it forwards to that URL regardless which LinkID I point my browser to. So, if I point it to a non existent LinkID (like 6) it will go to the 1st URL on the list, and if I point it to 2 or 3, it also goes to the 1st URL, while ignoring the actual LinkIDs 2 or 3. Then, when I change the LinkID of the 1st URL back to 1, the script doesn't work again.

    Does this information help resolve what is not set up correctly?

  7. #7
    Administrator Chris's Avatar
    Join Date
    Feb 2003
    Location
    East Lansing, MI USA
    Posts
    7,055
    try this.

    at the top of out.php add:

    echo "ID: ".$LinkID;
    echo "<br>Global ID: ".$_GET['LinkID'];

    I'm assuming you're accessing out.php like this

    /scripts/out.php?LinkID=2

    and remember... it is case sensitive.

    if you want it to be simpler

    put $LinkID = $id;

    at the top then you can access it like this

    /scripts/out.php?id=2

    But tell me what those echos output.
    Chris Beasley - My Guide to Building a Successful Website[size=1]
    Content Sites: ABCDFGHIJKLMNOP|Forums: ABCD EF|Ecommerce: Swords Knives

  8. #8
    Registered Mr. Pink's Avatar
    Join Date
    Sep 2008
    Location
    USA
    Posts
    147
    Chris,

    I did that test.

    Quote Originally Posted by Chris View Post
    I'm assuming you're accessing out.php like this

    /scripts/out.php?LinkID=2

    and remember... it is case sensitive.
    Correct, I am accessing like this (case sensitive) so I did not add that additional line on top. I only added the echos.

    Quote Originally Posted by Chris View Post
    ...But tell me what those echos output.
    With the added 2 echos, when calling up LinkID=2, the browser returns this:

    ID:
    Global ID: 2
    Warning: Cannot modify header information - headers already sent by (output started at /home/shark/public_html/scripts/out.php:3) in /home/shark/public_html/scripts/out.php on line 25
    Since the error message mentions line 25, I thought I'd include it here. Line 25 says this:

    header("Location: $url");

    Thanks...

  9. #9
    Registered
    Join Date
    Aug 2006
    Location
    Sacramento, CA
    Posts
    208
    You should change this line:

    PHP Code:
    $result1 mysql_query("SELECT * FROM redirect_links where LinkID = '$LinkID'"$db); 
    to this:

    PHP Code:
    $result1 mysql_query("SELECT * FROM redirect_links where LinkID = '" addslashes($_GET['LinkID']) . "'"$db); 
    and it should work fine. Of course remove those 2 echo's that you used for testing.
    ________
    VAPORIZERS
    Last edited by rpanella; 03-17-2011 at 11:09 AM.

  10. #10
    Administrator Chris's Avatar
    Join Date
    Feb 2003
    Location
    East Lansing, MI USA
    Posts
    7,055
    Yup, do what Russel posted and it'll work.

    The issue is your server has a php setting called "register_globals" turned off. They do this for security reasons on shared servers.

    So any variable passed will need to be accessed via an array such as $_GET or $_POST
    Chris Beasley - My Guide to Building a Successful Website[size=1]
    Content Sites: ABCDFGHIJKLMNOP|Forums: ABCD EF|Ecommerce: Swords Knives

  11. #11
    Registered Mr. Pink's Avatar
    Join Date
    Sep 2008
    Location
    USA
    Posts
    147

    Smile

    It worked!

    Thank you very much for helping me out. I'm sure I'll have some more questions, but for now the most important thing is that it works.

  12. #12
    Registered Mr. Pink's Avatar
    Join Date
    Sep 2008
    Location
    USA
    Posts
    147
    I did warn I'd have more questions, and here it is.

    I want to make a separate MySQL database only for my Amazon links. to make it easier for me to know which URL leads to which book, I would like to make the DB with 3 columns (LinkID, title, url). This way when I log onto my CP, and look at the list, I will have the boot titles right next to each LinkID.

    So, I know how to make this now, but I want to check with some technical details, first.

    1 - I will make a copy of the out.php script, and name it amazon.php. Do I have to add any lines in that new script, since the DB will have an extra column?

    2 - What settings do I have to use when I create my new "title" column/field? Do I make it a varchar field? any other settings for this field?

    Thank you...

  13. #13
    Administrator Chris's Avatar
    Join Date
    Feb 2003
    Location
    East Lansing, MI USA
    Posts
    7,055
    1. No - you're not using the title for anything so no.

    2. Yes, make it a varchar field, with a length long enough to handle your longest title, no other settings are necessary.
    Chris Beasley - My Guide to Building a Successful Website[size=1]
    Content Sites: ABCDFGHIJKLMNOP|Forums: ABCD EF|Ecommerce: Swords Knives

  14. #14
    Administrator Chris's Avatar
    Join Date
    Feb 2003
    Location
    East Lansing, MI USA
    Posts
    7,055
    by the way, you may want to go through this tutorial

    http://www.websitepublisher.net/arti...p-mysql-intro/
    Chris Beasley - My Guide to Building a Successful Website[size=1]
    Content Sites: ABCDFGHIJKLMNOP|Forums: ABCD EF|Ecommerce: Swords Knives

  15. #15
    Registered Mr. Pink's Avatar
    Join Date
    Sep 2008
    Location
    USA
    Posts
    147
    Thanks for your reply, and also for the link to that article. I read it and found it to be helpful and also found some other interesting articles linked form it.

    I now have some additional questions, but they will be better categorized in new threads.

Similar Threads

  1. biz-directory script
    By Percept in forum General Management Issues
    Replies: 0
    Last Post: 07-02-2004, 01:22 PM

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
  •