Jump to content

PHP coding


buge

Recommended Posts

Hi eveyone

 

i have a php code problem

 

$url = parse_url($_SERVER['QUERY_STRING']);
$query = array();
parse_str($url['path'], $query);
if ($query['dp']!=null){
$dp = $query['dp'];
}
else{
$dp = "CALIfor";
}
 
now,at the address line there "&" this sign,which i think causing me to get CALIfor.
what should i change so this sign wouldnt cause the code to break.
 
thank u alot
Edited by Zane
in the future use [code] tags
Link to comment
Share on other sites

Please wrap your code in the proper tags for this forum.

 

Please explain what you supposed problem is.  What you have here makes no sense.

 

A debug method would be to do a var_dump of you result array to see what you actually have.

Link to comment
Share on other sites

It looks like you're putting a query string into the query string? That's odd. Can you post an example of what that looks like?

 

If the answer to your problem is not to redo that (again, it's odd) then I'm guessing it will be htmlspecialchars().

Link to comment
Share on other sites

hi there

thnx for respond,

first-i dont know what do u mean by "wrap your code in the proper tags for this forum",and i dont know how to do dump in php.

second-the problem is:

i want for some var to taken from theURL- www.example.com/index.php?dp=alex&aff..etc

i want that the refering that comes after "=" will continue to other site

when its work (the php code),its take the var after the "dp="

but when its not-its refer it to diffult-which is CALIfor,

i want to know where is the problem.why its not taking the var from the URL.

 

maybe that will help:

<?php 
$url = parse_url($_SERVER['QUERY_STRING']);
$query = array();
parse_str($url['path'], $query);
if ($query['dp']!=null){
$dp = $query['dp'];
}
else{
$dp = "CALIfor";
}
?>

<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$(function(){
$('a').each(function() {
if(this.href.indexOf("sdzxczxcf")!= -1){
$(this).attr('href', this.href + "?subid=<?php echo $dp?>");
}
if(this.href.indexOf("dasdasdsa")!= -1){
$(this).attr('href', this.href + "<?php echo $dp?>");
}

});
});
</script> 
Edited by buge
Link to comment
Share on other sites

Add some debugging:

 

(note: the following code is wrapped in "php" and "/php" both surrounded by [ ])

 

parse_str($url['path'], $query);
var_dump($query);

 

This will show you exactly what arguments came in via the path of the url.  ALTHOUGH from your writing, I think you want to get the 'query' component, not the 'path' one.

Link to comment
Share on other sites

YOU DIDN'T WRITE THIS CODE?  So why should we help you?

 

We are here to help people learn, not patch their poorly written lifted code.

 

Besides - I gave you a line from your OWN code with a line to be added beneath it and you can't even figure that out?  Sounds like a severe case of laziness.  Can't help that.

 

Explain what I wrote?  Why don't you RTFM?

Link to comment
Share on other sites

$_SERVER['QUERY_STRING'] is already the part of the URL that's after the ?. I'm not sure what kind of result you'd get when you pass it to parse_url(). It's not a URL. 

 

If you have to do it this way, parsing the query string yourself... then you can pass $_SERVER['QUERY_STRING'] directly to parse_str() and get your $query array. Then check whether $query['db'] isset() and !empty() and use it's value, or else use 'CALIforn'. 

 

Taking something passed from the URL and placing it directly into your code without any validation is a bad idea, however. You're leaving a hole open where anyone can rewrite your entire page by passing values in the URL. 

 

-John

Link to comment
Share on other sites

I still wonder how on earth you've ended up with this idea.

 

Playing tricks with URLs and abusing them to the point that you can no longer use the standard parse functions is definitely a bad approach. Why can't you just pass the whole query string to the next page? What's the point of this weird "dp" pseudo-parameter?

Link to comment
Share on other sites

thank u all for your responses,

 

YOU DIDN'T WRITE THIS CODE?  So why should we help you?

 

We are here to help people learn, not patch their poorly written lifted code.

 

Besides - I gave you a line from your OWN code with a line to be added beneath it and you can't even figure that out?  Sounds like a severe case of laziness.  Can't help that.

 

Explain what I wrote?  Why don't you RTFM?

i didnt wrote that code-it was someone else that quit the JOB,u dont have to help if u dont wish to...

i knew its fro the code-i didnt knew what debug will help me with..(btw its given NULL)

i came here for quick help-its a little hard to learn PHP on one foot.

 

 

$_SERVER['QUERY_STRING'] is already the part of the URL that's after the ?. I'm not sure what kind of result you'd get when you pass it to parse_url(). It's not a URL. 

 

If you have to do it this way, parsing the query string yourself... then you can pass $_SERVER['QUERY_STRING'] directly to parse_str() and get your $query array. Then check whether $query['db'] isset() and !empty() and use it's value, or else use 'CALIforn'. 

 

Taking something passed from the URL and placing it directly into your code without any validation is a bad idea, however. You're leaving a hole open where anyone can rewrite your entire page by passing values in the URL. 

 

-John

im trying to pass thru the vars to next page,so i would know where it came from and who did it.

 

i dont know if its allowed to share the real link here :\

 

 

I still wonder how on earth you've ended up with this idea.

 

Playing tricks with URLs and abusing them to the point that you can no longer use the standard parse functions is definitely a bad approach. Why can't you just pass the whole query string to the next page? What's the point of this weird "dp" pseudo-parameter?

it wasnt me :(

if there is another was to do it-i would,but this is what he left for me.

 

 

the goal is:

landing page-that inside the URL r the vars of where it came from which ad etc..

but if the result is null(CALIfor),i cant know nothing about that.

 

for all of u,i thank u.

Link to comment
Share on other sites

is there a private inbox i can send u the link of the page that cause me the problem?

 

i already did the debug,which u mentioned-and it gave NULL.( i added the line to the code)

the EXACT CODE i have copied here above^.

 

i think im not explaining myself right.

it will be the best if u look at it-live.

Edited by buge
Link to comment
Share on other sites

Find the code that you think is the problem and debug it to the best of your ability.  Add some displays of important values to be sure they are what you expect them to be.  If that failes - show us THAT EXACT CODE with your debugging code included and show us what those values are also.  And please use the proper forum code tags as we have mentioned before.

Link to comment
Share on other sites

You guys keep talking about how to “debug” the code, but the only “bug” is a failure to understand URLs. No amount of code can fix that.

 

Query strings are expected to have a specific, very simple format:

param_1=val_1&param_2=val_2&param_3=val_3&...

Your URLs don't have this format, because you're trying to literally put a query string into another query string. This isn't possible, no matter what the “somebody else that quit the job” told you.

 

You have (at least) two options:

  • You URL-encode the original parameters and put them as data into one of your new parameters. For example, if the old query string was old_1=1&old_2=2, then the new is new_1=1&old_params=old_1%3D1%26old_2%3D2. Notice how the equation signs and ampersands are all encoded to prevent collisions with the new query string. The old query string must then be manually parsed.
  • You pass all original query parameters straight to the next page. This can be a problem if you want to add new parameters as well.

Pick one, then come back.

Link to comment
Share on other sites

You guys keep talking about how to “debug” the code, but the only “bug” is a failure to understand URLs. No amount of code can fix that.

 

Query strings are expected to have a specific, very simple format:

param_1=val_1&param_2=val_2&param_3=val_3&...

Your URLs don't have this format, because you're trying to literally put a query string into another query string. This isn't possible, no matter what the “somebody else that quit the job” told you.

 

You have (at least) two options:

  • You URL-encode the original parameters and put them as data into one of your new parameters. For example, if the old query string was old_1=1&old_2=2, then the new is new_1=1&old_params=old_1%3D1%26old_2%3D2. Notice how the equation signs and ampersands are all encoded to prevent collisions with the new query string. The old query string must then be manually parsed.
  • You pass all original query parameters straight to the next page. This can be a problem if you want to add new parameters as well.

Pick one, then come back.

 

i think the second one-cause the landing page-doesnt add new parameters,its redirect it to other page.

 

which one will be quicker to fix in your opinion?

Link to comment
Share on other sites

Is been a week now and nobody is getting anywhere.  Jacques is mostly correct in telling you your code is totally wrong, but you haven't listened and corrected it.  I've asked you why two scripts but no answer.

 

In English - you want to grab the url query string and pass it to another url and use a header to go there.  Why don't you just have your form do that?  Why don't you write some new code and experiment?  Why haven't you done anything to help yourself.

Link to comment
Share on other sites

Is been a week now and nobody is getting anywhere.  Jacques is mostly correct in telling you your code is totally wrong, but you haven't listened and corrected it.  I've asked you why two scripts but no answer.

 

In English - you want to grab the url query string and pass it to another url and use a header to go there.  Why don't you just have your form do that?  Why don't you write some new code and experiment?  Why haven't you done anything to help yourself.

u r right-Jacques  is correct,and TRYING TO HELP,why u come down on me like that?

u didnt asked why 2 scripts,and i am all ears to hear how to solve it ,and keep in mind,that itss hard for a newbie to follow someone else work & fix it(even not newbie).

i dont use form,cause the link i get from advertiser (is set in stone) >go on to landing page for a user (with same vars)> go to publisher.

i will write a whole book,if u will kindly direct me where to search (i understoond that parse_str is the problem).

 

ps.

this link is the problem (thats my ex programmer): just click until u get to continue then the link inclue CALIfor which means something wrong.

 

http://www.games4all.co/page1/page1-en91.php?dp=&aff_sub=utmsandbox&aff_sub2={teaser_id}&aff_sub3={geo}&aff_sub4={campaign_id}&aff_sub5=c2FuZGJveF8yMjYzNTY4XzE0OTYzMjMyOTNfc2FuZGJveA%2A%2A

 

(i know that its not alowed for "&" come after the "=" ,but thats the link the advs force to get.)

 

this link is working the same method,but its WORKING: (its not mine)

 

https://www.mgid.com/ghits/2214771/i/22225/0/tr/pp/48/3?h=DgsQK4oLCxNQdeF5YT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aHR0cHM6Ly9ibG9nLm1naWQuY29tLw%3D%3DfvSNA%3D%3DfwSMzA0fxSYTU4fySMmE0faSYTEwfbSfcSMQ%3D%3DfdSNjAwfeSMzYwfgSMTVjOWJjOGE2ZGE%3DfhS

 

 

http://mynewspepper.com/3-top-rated-games.php?voluumdata=BASE64dmlkLi4wMDAwMDAwOC1kMTRiLTRlZTUtODAwMC0wMDAwMDAwMDAwMDBfX3ZwaWQuLmNlNjExODAwLTRmN2YtMTFlNy04N2QxLWQ1ZjRmMThkZjFjYV9fY2FpZC4uOGY4ZWQ4N2QtZmJmOS00NTEyLWIzNmYtMTYzY2M3MjlmOGVjX19ydC4uUl9fbGlkLi5kZjhlYzE2MS1jMjkxLTQyNjktYjlmZC1iMmE4MGVkNTM0YjRfX29pZDEuLmExOTFhZjliLTdhNzctNDZiYS04NDJhLWMwMjZiMzhlOTJlMV9fdmFyMS4uNTUzOTg2NV9fdmFyMi4uMjIxNDc3MV9fdmFyMy4uUkdkelVVczBiMHhEZUU1UlpHVkdOVmxVU21OVFIwTk5RMWxwTkV3NWJWWjNUakp6YzBGUlUwOTBWbmRST0hKaVgzWkViMGhyZEd0SGMwcGFlRll5UlY4eE5EazNNamd4TURRMl9fcmQuLl9fYWlkLi5fX2FiLi5fX3NpZC4uX19jcmkuLl9fcHViLi5fX2RpZC4uX19kaXQuLl9fcGlkLi5fX2l0Li5fX3Z0Li4xNDk3MjgxMDQ2OTA4&widget_id=5539865&teaser_id=2214771&click_id=RGdzUUs0b0xDeE5RZGVGNVlUSmNTR0NNQ1lpNEw5bVZ3TjJzc0FRU090VndROHJiX3ZEb0hrdGtHc0paeFYyRV8xNDk3MjgxMDQ2&click_price=0.02

 

i beg the admin to let those links pass so u can see it ..

Edited by buge
Link to comment
Share on other sites

This is the latest code you have shown us:

 

<?php
$url = parse_url($_SERVER['QUERY_STRING']);
echo "url is: <pre>",print_r($url,true),"</pre>";
$query = array();
parse_str($url['path'], $query);
echo "query is: <pre>",print_r($query,true),"</pre>";
if ($query['dp']!=null){
$dp = $query['dp'];
}
else{
$dp = "CALIfor";
}
exit();

 

I have added some echos to show you what you are doing.

 

Run this by putting it in place of the SIMILAR piece of code in your script.  Can you do this?

Tell us what you get and if you see that it is not what you are expecting perhaps you can then FIGURE out what you really want to do?

Link to comment
Share on other sites

This is the latest code you have shown us:

<?php
$url = parse_url($_SERVER['QUERY_STRING']);
echo "url is: <pre>",print_r($url,true),"</pre>";
$query = array();
parse_str($url['path'], $query);
echo "query is: <pre>",print_r($query,true),"</pre>";
if ($query['dp']!=null){
$dp = $query['dp'];
}
else{
$dp = "CALIfor";
}
exit();

I have added some echos to show you what you are doing.

 

Run this by putting it in place of the SIMILAR piece of code in your script.  Can you do this?

Tell us what you get and if you see that it is not what you are expecting perhaps you can then FIGURE out what you really want to do?

url is:Array

(

[path] => dp=&aff_sub=utmsandbox&aff_sub2={teaser_id}&aff_sub3={geo}&aff_sub4={campaign_id}&aff_sub5=c2FuZGJveF8yMjYzNTY4XzE0OTYzMjMyOTNfc2FuZGJveA%2A%2A

)

query is:Array

(

[dp] =>

[aff_sub] => utmsandbox

[aff_sub2] => {teaser_id}

[aff_sub3] => {geo}

[aff_sub4] => {campaign_id}

[aff_sub5] => c2FuZGJveF8yMjYzNTY4XzE0OTYzMjMyOTNfc2FuZGJveA**

)

 

thank u very much for the help-as u can see,thats the result it gave me

Link to comment
Share on other sites

So what have you learned from this debugging exercise?

 

At least now we know why dp is 'CALIfor'

that all goes to its place :\?

u know,im still at the dark,if its not the "&" that made it go crazy,what did...

Link to comment
Share on other sites

I have no idea what you are asking.  What went crazy?  Just because you kept getting CALIfor as a value?  The reason you got that is because they didn't send you a value for 'db'.!!!

 

You now know what the query string was coming in.  All you need to add that to some 'outgoing' url is a "?" at the front to make it a proper query string for some other page to receive.  Is that what you want to do?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.