Thread: Anything Wrong?

Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    23
    Rep Power
    0
    Anything wrong with the below code??

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>if (ereg("http://www.abc.net/.+",getenv("$HTTP_REFERER")))[/code]

    I want to check if the referer is http://www.abc.net/ and with anything at the back (e.g. http://www.abc.net/baba.htm) .

    Please help.
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    4
    Rep Power
    0
    I think the right way to write it would be:
    if (eregi("^http://www.abc.net/", $HTTP_REFERER))

    (Note: There's nothing wrong with writing getenv($HTTP_REFERER) - it's just faster to write $HTTP_REFERER).

    I chose eregi() instead of ereg() because some write the URL in capital letters, and so the $HTTP_REFERER will be HTTP://WWW.ABC.NET/.

    Take a look at http://phpbuilder.com/columns/dario19990616.php3
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    23
    Rep Power
    0
    Thanks, but someone else has already given me a better solution. Please tell me what is wrong with the following code??

    ereg("http://www.abc.net/(.+)",$str,$url);

    Please help...
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    4
    Rep Power
    0
    > Thanks, but someone else has already given
    > me a better solution.
    >
    > ereg("http://www.abc.net/(.+)",$str,$url);

    Why is that better than my solution?
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    24
    Rep Power
    0
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Thanks, but someone else has already given me a better solution. Please tell me what is wrong with the following code??[/quote]

    heh, doesn't seem like they gave you a solution if it's still wrong.

    ------------------
    - weeder
  10. #6
  11. Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    49
    Rep Power
    15
    hehehe....



    nick
  12. #7
  13. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    23
    Rep Power
    0
    Someone has given me a better solution for the previous question.

    To use:

    if (ereg("http://www.abc.net/.+",getenv("HTTP_REFERER")))
    Instead of:

    if (ereg("http://www.abc.net/.+",getenv("$HTTP_REFERER")))

    So it is a MUCH better than your solution!

    Now I need a solution for another problem, that is, what's wrong with the following code?

    ereg("http://www.abc.net/(.+)",$str,$url);

    Please help.
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2000
    Posts
    79
    Rep Power
    15
    how bout...
    $url = parse_url($url);
    if($url[host] == "www.abc.net")

    i think that should work...checking up on it now...


    yep it does

    Basil

    [This message has been edited by 'tantrum (edited July 21, 2000).]
  16. #9
  17. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    23
    Rep Power
    0
    I always get the value as "Array". Why is that?
  18. #10
  19. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    27
    Rep Power
    0
    That's the value returned when passing in $url. A 3rd parameter automatically gives you that.

    Go with 'tantrum. And as a side note: insulting those who give assistance is not the most intelligent thing (no matter how helpful they prove to be).

    //ryan
  20. #11
  21. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    27
    Rep Power
    0
    I just replicated the "Array" print out error...

    what I had was an array of strings, and I tried to print the contents with "print" just as you would echo any normal variable.

    Try using a string function to process the array element and return a variable of type string. If you're familiar w/ C++, think of it as a type-cast ... sorta.

    //ryan
  22. #12
  23. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    23
    Rep Power
    0
    Sorry, I got angry as the person gave me a solution which made matters worse and that guy still asked me why. I did not insult him or anyone, I only got angry and don't try to say I'm not intelligent, because I am.

    Okay, back to the subject.
    Thanks, but how do I do that?
  24. #13
  25. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    27
    Rep Power
    0
    could you post your source code? ...it'll be easier to find a solution once we can rule out the rest of the code.

    ...one possible soultion is similar to Jonas' post, but instead of this:

    if (eregi("^http://www.abc.net/", $HTTP_REFERER))

    try this:

    if (eregi(".+http://www.abc.net/.+", $HTTP_REFERER))

    Sorry, that's the only solution I can pose w/o seeing more code. As far as type-casting, all I had to do to fix the "Array" error was to write:

    print strchr($arr[$i],$arr[$i]);
    (my code was slightly different... the 2nd parameter was actually the 1st char of the 1st element, and maybe the variations effected the outcome, but the point is that I tried using a function that returned a string from whatever I passed in)


    //...oh the pitfalls of dynamic type casting
    //ryan
    (hope I helped... sorry for the crack earlier)
  26. #14
  27. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2000
    Posts
    79
    Rep Power
    15
    Did u say it says 'Array' when echoing mine?

    If so, its because ur trying to echo $url and not $url[host]

    I can't beleive how many replies have gone into this simple problem

    Basil
  28. #15
  29. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    23
    Rep Power
    0
    My problem is:

    ereg("http://www.abc.net/(.+)",$str,$url);

    Your solution displays: www.abc.net

    Instead of everything after http://www.abc.net/.

    For example if the value is: http://www.abc.net/abbabababa
    It should become:
    abbabababa
    Or:
    /abbabababa

    Get it? Please help.
Page 1 of 2 12 Last
  • Jump to page:

Similar Threads

  1. simple form, simple trigger, whats wrong ??
    By zishto in forum Oracle Development
    Replies: 3
    Last Post: January 12th, 2004, 01:25 PM
  2. what is wrong with this code ????
    By fule in forum Database Management
    Replies: 1
    Last Post: November 20th, 2003, 01:24 AM
  3. *sigh*
    By vb.net in forum Dev Shed Lounge
    Replies: 45
    Last Post: November 9th, 2003, 07:52 PM
  4. offsetHeight returning the wrong height
    By Tobbe in forum HTML Programming
    Replies: 10
    Last Post: October 19th, 2003, 08:23 AM

IMN logo majestic logo threadwatch logo seochat tools logo