PDA

View Full Version : سوال: ارسال کاربر به یک Query String



MoMo121
شنبه 02 شهریور 1392, 20:06 عصر
چطور می توان کاربر را به این آدرس فرستاد


http://www.example.com/salam.php?QueryString

از header استفاده کردم نشد

MoMo121
شنبه 02 شهریور 1392, 21:18 عصر
لطفا یکی جواب بده
ممنونم

AliRezaPro
شنبه 02 شهریور 1392, 21:54 عصر
همین لینکی که مدنظر دارید را href میکنید و در آن page با Get مقدار رو بدست میارید

MoMo121
شنبه 02 شهریور 1392, 22:31 عصر
نه نمی خوام کاربر بره که

می خوام همون طوری که تو header یه آدرس می نویسی ریدایرکت می شه حالا این query string با توابع php ریدایرکت شه

AliRezaPro
شنبه 02 شهریور 1392, 22:47 عصر
من متوجه منظور شما نشدم
میخواید جای QueryString یک آدرس باشه و سپس به اون انتقال پیدا کنید ؟
مثلا ؟

http://www.example.com/salam.php?www.google.com
و google.com را بگیرید و به اون صفحه منتقل بشید ؟

MoMo121
شنبه 02 شهریور 1392, 23:00 عصر
if($i >= 12)
{
header("Location: sallam.php?yechizi);
}


می خوام مثلا وقتی $i بزرگتر از 12 بود بره به sallam.php?yechizi

با تشکر از پیگیری

AliRezaPro
شنبه 02 شهریور 1392, 23:26 عصر
همین کدی رو هم که گذاشتید کار میکنه . صفحه ی sallam.php را با مقدار yechizi باز میکند

header("Location:".$_SERVER["PHP_SELF"] ."?yechizi");

مثلا :

if(isset($_POST['btnclose'])){

session_destroy();

header("Location: login.php?close");
}

من شاید بازم متوجه منظور شما نشده باشم , کد کاملتون را برای بررسی بزارید

MoMo121
شنبه 02 شهریور 1392, 23:39 عصر
متاسفانه هر دوتاش این اررو را می دهد

Warning: Cannot modify header information

AliRezaPro
یک شنبه 03 شهریور 1392, 00:11 صبح
ob_start(); را بالای اسکریپتتون قرار بدید و ob_flush(); را انتهای اسکریپت
حتما بعد از header تابع exit() را صدا بزنید

MoMo121
یک شنبه 03 شهریور 1392, 02:23 صبح
ممنونم بالاخره درست شد

MoMo121
یک شنبه 03 شهریور 1392, 06:55 صبح
یه مشکل تازه من دقیقا قبل از


header("Location:".$_SERVER["PHP_SELF"] ."?yechizi");
ob_flush();
exit();

یه sleep(3) دارم که به خاطر بافر کار نمی کنه چی کار کنم ؟

AliRezaPro
یک شنبه 03 شهریور 1392, 07:43 صبح
دلیل :


faileN's answer is correct in theory. Without the ob_flush() the data would stay in PHP's buffer and not arrive at the browser until the buffer is implicitly flushed at the end of the request.

The reason why it still doesn't work is because the browsers also contain buffers. The data is now sent out correctly, but the browser waits after getting "one" before it actually kicks off rendering. Otherwise, with slow connections, page rendering would be really, really slow.

The workaround (to illustrate that it's working correctly) is, of course, to send a lot of data at once (maybe some huge html comment or something) or to use a tool like curl on the command line.

If you want to use this sending/sleeping cycle for some status update UI on the client, you'd have to find another way (like long-polling and AJAX)
و راه اون

$txt = setPageHeader(); // a PHP function that returns a new DOCTYPE
// plus <html><head>(...)</head>,
// plus an opening <body> tag

echo 'All things were completed. You should be redirected in about 3 seconds';

$txt .= '<script type="text/javascript">';
$txt = $txt.'function Rediriger() {document.location.replace(\'http://yoursite.com/yourpage.php?anticaching='.rand().'\');}';
$txt .= 'setTimeout (\'Rediriger()\', \'3000\')';
$txt .= '</script>';
$txt .= '<noscript><a href="http://yoursite.com/yourpage.php?anticaching='.rand().'">Javascript is disabled in your browser. Click here for being redirected.</a></noscript>';
$txt .= '</body></html>';
echo ($txt);