Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


do you know script for redirecting?
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

do you know script for redirecting?

Hello
im looking for a script or a php code that redirect first click to URL1 and rest of clicks to URL2 ,
Do you know how to do that?
Thanks

Comments

  • @Darwin said:
    Yes

    What is that script

  • WSSWSS Member

    Pretty simple to use with setenv/mod_rewrite, PHP, Python, heck, even a basic perl script. Shell is also doable with setenv.

  • My first approach would be to verify a cookie for this. If is set, redirect to url2, otherwise set the cookie and redirect to url1.
    You can do this in five lines or so, now go and learn to do it.

  • I know nothing about PHP
    can you please write it

    @yomero said:
    My first approach would be to verify a cookie for this. If is set, redirect to url2, otherwise set the cookie and redirect to url1.
    You can do this in five lines or so, now go and learn to do it.

  • @flym said:
    Hello
    im looking for a script or a php code that redirect first click to URL1 and rest of clicks to URL2 ,
    Do you know how to do that?
    Thanks

    Something like clickjacking?

    Depends on what you are looking to achieve with that. Since you have used the word click, you may need JavaScript not PHP

  • I meant redirecting , not click

    @sharuu said:

    @flym said:
    Hello
    im looking for a script or a php code that redirect first click to URL1 and rest of clicks to URL2 ,
    Do you know how to do that?
    Thanks

    Something like clickjacking?

    Depends on what you are looking to achieve with that. Since you have used the word click, you may need JavaScript not PHP

  • flym said: I know nothing about PHP can you please write it

    No

    It should take you a couple of hours to learn this.

  • @flym,

    Oh for crying out loud you can literally just type this into Google to get started: lmgtfy.com/?q=PHP+redirect

  • As yomero said, you should learn it first rather than asking someone to code it for you for free.

    As of solution, use session/cookies and redirect to different page depending on the state.

  • Hate these affiliate sites

  • pbgbenpbgben Member, Host Rep
    edited January 2017

    header('location: https://google.com')

  • pbgbenpbgben Member, Host Rep

    Or in JS would be cleaner, just have an onclick event to change the href value.

    I can do it for you, but you will have to pay $120

    Thanked by 1WSS
  • WSSWSS Member

    @pbgben said:
    Or in JS would be cleaner, just have an onclick event to change the href value.

    Cleaner, and much easier to filter. :D

  • If it works with JS I will give it a go myself for learning purposes though given you already have a solution :)

    @pbgen I guess onclick was also what came to my mind first :P

  • wow thank you mate
    i have two questions , if Url1 change to http://1.com how change below code :
    isset($_COOKIE['affiliatefraud']) && $_COOKIE['affiliatefraud'] == 'notmalwareredirect

    and
    after how long cookie will be expired

  • YmpkerYmpker Member
    edited January 2017

    @flym said:
    wow thank you mate
    i have two questions , if Url1 change to http://1.com how change below code :
    isset($_COOKIE['affiliatefraud']) && $_COOKIE['affiliatefraud'] == 'notmalwareredirect

    and
    after how long cookie will be expired

    Look in your php.ini file. It will tell you exactly how long the default session will last.

  • WSSWSS Member
    edited January 2017

    @hzr said:
    because i'm feeling nice

    No call to session_start()? Used to frameworks, are we? :D

  • hzrhzr Member

    It doesn't use sessions

  • WSSWSS Member
    edited January 2017

    @hzr said:
    It doesn't use sessions

    I realize this, but blindly calling isset() and then referencing the key is going to cause a warning since you did && rather than only calling it after testing (PHP4/5 observed), so I assumed that you either run with warnings disabled, or were doing something else kind of funky.

    Also setting the redirect before the cookie doesn't always work with PHP4/5 in my experience, so I would have instead used a session. Perhaps I'm overthinking a bit of throwaway code. :)

  • hzrhzr Member
    if (isset($_COOKIE['test']) && $_COOKIE['test'] == 't1'){ echo 'x'; }

    doesn't throw warning or error by default on any of my installs

    if ($_COOKIE['test'] == 't1'){ echo 'x'; }

    does ('php notice')

    I'm not entirely sure what but I'm new to php and have only used 7.x

  • WSSWSS Member
    edited January 2017

    @hzr said:
    I'm not entirely sure what but I'm new to php and have only used 7.x

    That'll be why.

    A good form to use when starting with PHP is to set notices for E_ALL so you learn different caveates, and don't pick up bad habits. A buddy of mine from the PHP3 days used to create arrays like @array[foo], instead of $array['foo'], et al, because it didn't care- and is still struggling to unlearn bad habits a decade later.

    If you are serious about PHP, you will learn that things that DO work, don't always work. Even my use of sessions won't always work, if the client is set to drop identifiers and the host has no way of storing them in SHM or temp files.. but then again, if that happens, that is a very, very broken host.

    [code]
    if (@isset($_COOKIE['test'])) THEN {
    if ($_COOKIE['test'] == '...' ) [...]
    }[/code]

    The above is proper, because you are testing if it is set. If you don't, it then goes

    [code]
    if (@isset($_COOKIE['test']))
    AND
    if (NULL['test'] == '...' ) [...]
    }[/code]

    That's why it throws a notice.

    Thanked by 1BeardyUnixGuy
  • BeardyUnixGuyBeardyUnixGuy Member
    edited January 2017

    flym said: can you please write it

    Well, I saw that one coming just by looking at the topic.

    It's best to simply be upfront about your intentions from the beginning. It would probably save all of us some time and avoid some of the usual LET sarcasm.

    WSS said: buddy of mine from the PHP3 days .. still struggling to unlearn bad habits a decade later

    That's unfortunate! I've come from PHP3 days as well but managed to keep up with best practices as they developed. I will admit though that I still have some silly habits that are related to early PHP optimization techniques e.g. Using single quotes with strings since double quotes would invoke additional variable substitution routines

  • WSS said: That's why it throws a notice.

    No it does't, short-circuit evaluation

  • WSSWSS Member
    edited January 2017

    @vedran said:

    WSS said: That's why it throws a notice.

    No it does't, short-circuit evaluation

    That's how it's supposed to work, yes. The logic, however, is wrong.

    If ($foo["bar"]) AND (if $foo["bar"] == "baz")

    Not only asks if $foo["bar"] is set, but secondarily requires the test due to the && stanza, so it HAS to be evaluated, whether $foo["bar"] is set, or not.

    Please test the above in PHP 5.x (or whatever), and note that you'll still get the notice because it is still trying to evaluate the unset $_foo['var'] for the example.

    To do this without PHP possibly bitching, you need to do:

    if (isset($foo["bar"])) {
    if ($foo["bar"] == "..."
    }

  • WSSWSS Member
    edited January 2017

    I actually corrected my assertion above and gave @vedran credit for being technically correct- if it worked that way, but this is actually a known logical issue that plagued PHP from the 5.x days. You can't use && for shorthand when testing for, then testing the same thing and expect it to not be evaluated when it's part of the initial testing...

  • hzrhzr Member

    WSS said: I realize this, but blindly calling isset() and then referencing the key is going to cause a warning since you did && rather than only calling it after testing (PHP4/5 observed), so I assumed that you either run with warnings disabled, or were doing something else kind of funky.

    I don't get a warning or notice at all with even error_reporting(-1), not sure why.

  • SmithSmith Member

    As per my knowledge, I guess you'll find your ans over here https://www.cyberciti.biz/faq/php-redirect/.
    In the above link, you'll also gain deep knowledge for redirection

  • <?php
    
    session_start();
    
    $link1 = "URL1";
    $link2 = "URL2";
    $days_to_live = 30; /* days to remember cookies */
    
    if ($_COOKIE['click']) header("Location: ".$link2);
    else {
         setcookie ( "click", "1", time()+60*60*24*$days_to_live);
         header("Location: ".$link1);
    }
    
    ?>
    
Sign In or Register to comment.