Graxeon Posted December 28, 2008 Share Posted December 28, 2008 I have this: <?php $URL = $_GET['url']; $allowed_url = array("google.com","yahoo.com"); if(in_array($URL,$allowed_url)) { header("Location: http://video.".$URL."/videorankings?type=blogged&cr=usa&hl=en"); }else{ header("Location: http://www.google.com/"); } ?> But I want to run it with this in a separate PHP file: <?php header("Location: http://video.".$URL."/videorankings?type=blogged&cr=usa&hl=en"); ?> So how can I call that second script through the first one like this: <?php $URL = $_GET['url']; $allowed_url = array("google.com","yahoo.com"); if(in_array($URL,$allowed_url)) { CALL 2nd PHP file from here }else{ header("Location: http://www.google.com/"); } ?> I don't want the script to redirect to the 2nd one...I just want the second one to run after it's gone through the array check system thing. Link to comment https://forums.phpfreaks.com/topic/138644-solved-run-an-external-script-after-array/ Share on other sites More sharing options...
DarkWater Posted December 28, 2008 Share Posted December 28, 2008 Why? Link to comment https://forums.phpfreaks.com/topic/138644-solved-run-an-external-script-after-array/#findComment-724900 Share on other sites More sharing options...
t_miller_3 Posted December 28, 2008 Share Posted December 28, 2008 Can you not use: <?php include(filename.php); ?> I'm only new to php so excuse me if I'm completely wrong Link to comment https://forums.phpfreaks.com/topic/138644-solved-run-an-external-script-after-array/#findComment-724901 Share on other sites More sharing options...
Graxeon Posted December 28, 2008 Author Share Posted December 28, 2008 Why? Some of my other scripts don't work within the array script so I need to run it externally. My team doesn't want me to share the script so that's why I have to ask in this manner . Can you not use: <?php include(filename.php); ?> I'm only new to php so excuse me if I'm completely wrong I tried this but it didn't work: <?php $URL = $_GET['url']; $allowed_url = array("google.com","yahoo.com"); if(in_array($URL,$allowed_url)) { include(file2.php); }else{ header("Location: http://www.google.com/"); } ?> Link to comment https://forums.phpfreaks.com/topic/138644-solved-run-an-external-script-after-array/#findComment-724961 Share on other sites More sharing options...
corbin Posted December 28, 2008 Share Posted December 28, 2008 <?php $URL = $_GET['url']; $allowed_url = array("google.com","yahoo.com"); if(in_array($URL,$allowed_url)) { header("Location: http://video.".$URL."/videorankings?type=blogged&cr=usa&hl=en"); }else{ header("Location: http://www.google.com/"); } ?> ???? Guessing I'm misunderstanding the problem. Link to comment https://forums.phpfreaks.com/topic/138644-solved-run-an-external-script-after-array/#findComment-724964 Share on other sites More sharing options...
opalelement Posted December 28, 2008 Share Posted December 28, 2008 include should work, did it give an error or anything? Link to comment https://forums.phpfreaks.com/topic/138644-solved-run-an-external-script-after-array/#findComment-724966 Share on other sites More sharing options...
Graxeon Posted December 28, 2008 Author Share Posted December 28, 2008 include should work, did it give an error or anything? Nope, just a blank page. Guessing I'm misunderstanding the problem. Oh...right I should explain what it's doing first. Ok this script is checking to see if the inputs after "url=" are in the predefined list of "allowed" inputs: <?php $URL = $_GET['url']; $allowed_url = array("google.com","yahoo.com"); if(in_array($URL,$allowed_url)) { header("Location: http://video.".$URL."/videorankings?type=blogged&cr=usa&hl=en"); }else{ header("Location: http://www.google.com/"); } ?> If the input is in the predefined list, then this part of the script is run: header("Location: http://video.".$URL."/videorankings?type=blogged&cr=usa&hl=en"); If the input is not in the list, then the user is redirected to "http://www.google.com" Now...what I want to do is instead of having "header("Location: http://video.".$URL."/videorankings?type=blogged&cr=usa&hl=en");" within the same script, I want it to be on an external file. So I should have 2 PHP files, the first one would be this: <?php $URL = $_GET['url']; $allowed_url = array("google.com","yahoo.com"); if(in_array($URL,$allowed_url)) { CALL 2nd PHP file from here }else{ header("Location: http://www.google.com/"); } ?> The 2nd script would be: <?php //This can be any script, btw. My team doesn't allow me to share the script that I do want to put here, sorry. header("Location: http://video.".$URL."/videorankings?type=blogged&cr=usa&hl=en"); ?> That 2nd script would take whatever "allowed" input the user used in the first script and just run it through the 2nd script. Does that make more sense? >.< Link to comment https://forums.phpfreaks.com/topic/138644-solved-run-an-external-script-after-array/#findComment-724968 Share on other sites More sharing options...
corbin Posted December 28, 2008 Share Posted December 28, 2008 That's pretty much how including works. http://php.net/include file1.php <?php $x = 5; include 'file2.php'; file2.php <?php echo $x; Would put out 5. Link to comment https://forums.phpfreaks.com/topic/138644-solved-run-an-external-script-after-array/#findComment-724971 Share on other sites More sharing options...
Graxeon Posted December 28, 2008 Author Share Posted December 28, 2008 I'm a newbie, can you show me how to do it with the scripts I provided, please? I tried to mess around with it but it didn't output anything xD Link to comment https://forums.phpfreaks.com/topic/138644-solved-run-an-external-script-after-array/#findComment-724978 Share on other sites More sharing options...
corbin Posted December 28, 2008 Share Posted December 28, 2008 Since your scripts are using header statements, they shouldn't print out anything but headers, which you won't see in a browser. <?php $URL = $_GET['url']; $allowed_url = array("google.com","yahoo.com"); if(in_array($URL,$allowed_url)) { require 'file2.php'; //require is the same as include, but the script throws a fatal error if the file isn't able to be included. }else{ header("Location: http://www.google.com/"); } ?> file2.php <?php //This can be any script, btw. My team doesn't allow me to share the script that I do want to put here, sorry. header("Location: http://video.".$URL."/videorankings?type=blogged&cr=usa&hl=en"); ?> Link to comment https://forums.phpfreaks.com/topic/138644-solved-run-an-external-script-after-array/#findComment-724981 Share on other sites More sharing options...
Graxeon Posted December 28, 2008 Author Share Posted December 28, 2008 It works, thank you very much. PHPfreaks.com has sexy gurus in it Link to comment https://forums.phpfreaks.com/topic/138644-solved-run-an-external-script-after-array/#findComment-724987 Share on other sites More sharing options...
corbin Posted December 28, 2008 Share Posted December 28, 2008 Creepy, but errr... You're welcome ;p. Link to comment https://forums.phpfreaks.com/topic/138644-solved-run-an-external-script-after-array/#findComment-724995 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.